|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
JSONM: a JSON document with attached binary chunks in one contiguous buffer. More...
#include <NetworkProtocols.h>
Public Member Functions | |
| JSONM () | |
| JSONM (const char *data, uint64 size) | |
| Parse a complete JSONM container from raw bytes. | |
| JSONM (const char *json) | |
| Create a container from JSON text only (no attachments yet). | |
| ~JSONM () | |
| uint64 | getSize () |
| uint32 | getCount () |
| bool | isValid () |
| std::string | getJSON () |
| const char * | getData (const char *name, uint64 &size) |
| Get an attachment's bytes by name. | |
| const char * | getData (uint32 chunk, uint64 &size) |
| Get an attachment's bytes by chunk index. | |
| std::string | getDataType (const char *name) |
| std::string | getDataType (uint32 chunk) |
| std::string | getDataName (uint32 chunk) |
| bool | setJSON (const char *json) |
| Replace the JSON text portion (multipart metadata is regenerated). | |
| uint32 | addData (const char *name, const char *data, uint64 size, const char *type) |
| Append a binary attachment. | |
| std::string | getInfoString () |
| DataMessage * | convertToMessage () |
| Convert this container into a binary DataMessage. | |
Public Attributes | |
| char * | jmData |
| Owned serialised container buffer (JSON + attachments). | |
| uint64 | jmSize |
| Total size of ::jmData in bytes. | |
| uint64 | mOffset |
| Byte offset where the binary multipart section begins. | |
| std::map< uint32, JSONMEntry > | entries |
| Attachment metadata by chunk index. | |
JSONM: a JSON document with attached binary chunks in one contiguous buffer.
Wire format used to move JSON plus binary payloads (images, audio, etc.) as a single blob: the JSON text comes first and describes the attachments (name, size, MIME type); the raw binary chunks follow at recorded offsets. Construct from received bytes to parse, or build up with setJSON() + addData() to send. Internally serialised into ::jmData.
Definition at line 354 of file NetworkProtocols.h.
| cmlabs::JSONM::JSONM | ( | ) |
Definition at line 2460 of file NetworkProtocols.cpp.
| cmlabs::JSONM::JSONM | ( | const char * | data, |
| uint64 | size ) |
| cmlabs::JSONM::JSONM | ( | const char * | json | ) |
Create a container from JSON text only (no attachments yet).
| json | NUL-terminated JSON text (copied). |
Definition at line 2477 of file NetworkProtocols.cpp.
| cmlabs::JSONM::~JSONM | ( | ) |
Definition at line 2486 of file NetworkProtocols.cpp.
| uint32 cmlabs::JSONM::addData | ( | const char * | name, |
| const char * | data, | ||
| uint64 | size, | ||
| const char * | type ) |
Append a binary attachment.
| name | Attachment name. |
| data | Bytes (copied). |
| size | Byte count. |
| type | MIME type. |
Definition at line 2675 of file NetworkProtocols.cpp.
References cmlabs::JSONMEntry::chunk, entries, getCount(), getData(), jmData, jmSize, cmlabs::JSONMEntry::name, cmlabs::JSONMEntry::offset, setJSON(), cmlabs::JSONMEntry::size, and cmlabs::JSONMEntry::type.
Referenced by cmlabs::RequestGateway::replyToClient(), and cmlabs::TestWebSocketRequestClient::run().
| DataMessage * cmlabs::JSONM::convertToMessage | ( | ) |
Convert this container into a binary DataMessage.
Definition at line 2830 of file NetworkProtocols.cpp.
References entries, getJSON(), cmlabs::GetTimeNow(), jmData, mOffset, cmlabs::DataMessage::setCreatedTime(), cmlabs::DataMessage::setData(), cmlabs::DataMessage::setRecvTime(), and cmlabs::DataMessage::setString().
Referenced by cmlabs::RequestGateway::receiveWebsocketData().
| uint32 cmlabs::JSONM::getCount | ( | ) |
Definition at line 2501 of file NetworkProtocols.cpp.
References entries.
Referenced by addData(), and getInfoString().
| const char * cmlabs::JSONM::getData | ( | const char * | name, |
| uint64 & | size ) |
Get an attachment's bytes by name.
| name | Attachment name. |
| size | Out: attachment size. |
Definition at line 2538 of file NetworkProtocols.cpp.
References entries, jmData, jmSize, LOG_NETWORK, LogPrint, mOffset, and stricmp.
Referenced by addData().
| const char * cmlabs::JSONM::getData | ( | uint32 | chunk, |
| uint64 & | size ) |
Get an attachment's bytes by chunk index.
| chunk | Chunk index. |
| size | Out: attachment size. |
Definition at line 2616 of file NetworkProtocols.cpp.
References entries, jmData, jmSize, LOG_NETWORK, LogPrint, and mOffset.
| std::string cmlabs::JSONM::getDataName | ( | uint32 | chunk | ) |
| chunk | Chunk index. |
Definition at line 2597 of file NetworkProtocols.cpp.
| std::string cmlabs::JSONM::getDataType | ( | const char * | name | ) |
| std::string cmlabs::JSONM::getDataType | ( | uint32 | chunk | ) |
| chunk | Chunk index. |
Definition at line 2582 of file NetworkProtocols.cpp.
| std::string cmlabs::JSONM::getInfoString | ( | ) |
Definition at line 2704 of file NetworkProtocols.cpp.
References cmlabs::utils::BytifySize(), entries, getCount(), jmData, jmSize, mOffset, and cmlabs::utils::StringFormat().
| std::string cmlabs::JSONM::getJSON | ( | ) |
Definition at line 2528 of file NetworkProtocols.cpp.
References jmData, jmSize, and cmlabs::utils::laststrstr().
Referenced by convertToMessage(), and cmlabs::RequestGateway::receiveWebsocketData().
| uint64 cmlabs::JSONM::getSize | ( | ) |
Definition at line 2495 of file NetworkProtocols.cpp.
References jmSize.
Referenced by cmlabs::TestWebSocketRequestClient::run().
| bool cmlabs::JSONM::isValid | ( | ) |
Definition at line 2508 of file NetworkProtocols.cpp.
References entries, jmData, jmSize, cmlabs::utils::laststrstr(), LOG_NETWORK, and LogPrint.
Referenced by cmlabs::RequestGateway::receiveWebsocketData(), and cmlabs::TestWebSocketRequestClient::run().
| bool cmlabs::JSONM::setJSON | ( | const char * | json | ) |
Replace the JSON text portion (multipart metadata is regenerated).
| json | NUL-terminated JSON text. |
Definition at line 2665 of file NetworkProtocols.cpp.
Referenced by addData(), JSONM(), cmlabs::RequestGateway::replyToClient(), and cmlabs::TestWebSocketRequestClient::run().
| std::map<uint32, JSONMEntry> cmlabs::JSONM::entries |
Attachment metadata by chunk index.
Definition at line 406 of file NetworkProtocols.h.
Referenced by addData(), convertToMessage(), getCount(), getData(), getData(), getDataName(), getDataType(), getDataType(), getInfoString(), isValid(), and cmlabs::RequestGateway::receiveWebsocketData().
| char* cmlabs::JSONM::jmData |
Owned serialised container buffer (JSON + attachments).
Definition at line 403 of file NetworkProtocols.h.
Referenced by addData(), convertToMessage(), getData(), getData(), getDataName(), getDataType(), getDataType(), getInfoString(), getJSON(), isValid(), JSONM(), JSONM(), JSONM(), cmlabs::RequestGateway::replyToClient(), cmlabs::TestWebSocketRequestClient::run(), and ~JSONM().
| uint64 cmlabs::JSONM::jmSize |
Total size of ::jmData in bytes.
Definition at line 404 of file NetworkProtocols.h.
Referenced by addData(), getData(), getData(), getDataName(), getDataType(), getDataType(), getInfoString(), getJSON(), getSize(), isValid(), JSONM(), JSONM(), JSONM(), cmlabs::RequestGateway::receiveWebsocketData(), cmlabs::RequestGateway::replyToClient(), and ~JSONM().
| uint64 cmlabs::JSONM::mOffset |
Byte offset where the binary multipart section begins.
Definition at line 405 of file NetworkProtocols.h.
Referenced by convertToMessage(), getData(), getData(), getInfoString(), JSONM(), JSONM(), and ~JSONM().