Binary Endpoints for IoT Ecosystem #67
Replies: 3 comments 5 replies
-
A binary format is crucial to resource constrained devices. JSON is compact, but it's not compact enough for resource constrained devices, on which any character-based format would be bloated. By supporting a binary format for APIs on the node software, we allow (even Class 01) devices to perform actions on the Tangle without hassle. But by simply saying "a binary format" the structure of data is not defined. Fortunately there has been standard ways to binary encode structured data without losing the structure (which makes it convenient to just convert from and to JSON). Because HTTP is also a character-based protocol, we can also take the transfer protocol into consideration (but not necessarily). I can think of a few possible solutions:
We've had MQTT endpoints running, but with a separate Event API. It's possible to further map and provide REST APIs in MQTT topics to enable more IoT devices to communicate with node software without the bloat of HTTP. CBOR(official website, Wikipedia, spec (RFC8949)) stands for "Concise Binary Object Representation". Its data model is based on JSON, so transformative between JSON and CBOR should be straightforward. It can be sent over any transfer protocol - it's just a way to encode data. FlatBuffers (official website, Wikipedia, schema compiler) can be seen as an improvement from Protocol Buffers. It uses schema to define the shape of data, so the serialized binary data has no structure marked in it; in other words, no parsing or unpacking is needed to access the structured data. It's thus more concise than any other serialization format, but it also makes the serialized data non-self-contained. CoAP (official website, Wikipedia, spec (RFC7252)) is a protocol designed to run on resource constrained devices and UDP. It borrows concepts from HTTP, making common features between the two easy to translate between each other. It's usually seen as a competitor of MQTT, who run (mainly) on TCP and emphasize long connection instead. One of the ideal combinations could be CBOR/CoAP. Both are well-defined, widely-used, widely-supported protocol formats designed specially for resource constrained IoT devices. It's also fine to just use HTTP to provide the REST APIs. In this way we do content negotiation, i.e. checking the Footnotes
|
Beta Was this translation helpful? Give feedback.
-
@arnauorriols thanks for your input. this discussion is meant to come out with reasonable support for IoT adoption. imo, FlatBuffers is not a fit for embedded development, it's designed for gaming and streaming for reducing serialization latency. it bloats the binary data, for example, FlatBuffers needs around 400 bytes of memory to send out 200 bytes of data, the memory consumption is similar to JSON which is a big drawback.
agree, binary communication has low adoption but the protocol shouldn't be changed frequently for a production-ready project. |
Beta Was this translation helpful? Give feedback.
-
Updated Client response objects in the description, thanks for @alexsporn pointing out, the MIMI type can be a customized one and need to be defined instead of discussed with the protocol team, the conclusion is anyone can build an external plugin to connect IoT devices via their own binary format. We don't know the reqs and what they use. We don't want to optimize for constrained devices in Stardust, at least not before the Shimmer launch. let's move forward and revisit this topic later. |
Beta Was this translation helpful? Give feedback.
-
Introduction
API endpoints are defined in following TIPs:
Most of the data are communicated via JSON objects which is a human-readable text format. For constrained devices, those text data are not packed and data conversions involve more frequently memory operations, especially allocation and free, which leads to memory fragmentation issues and causes potential system instabilities.
To reduce data conversion and serialization during communications, the node can provide endpoints that communicate with binary payload through HTTP. It has been partially implemented in
/api/v2/messages
.The client is able to send a message to the node in JSON string, like
or binary data, for example
The payload size in the example for binary is only 810 bytes, JSON is 2863 bytes, the binary is 3 times smaller.
Additionally, the following endpoints can be a customized MIME type, instead of
application/octet-stream
, in both requests and responses.Example responses
Excep for data types in Serialization Primitives, two extended data types are introduced for the Binary Client Response layout:
uintX
denotes the length of the list.uintY
denotes the lenght of ByteArrayuintX
denotes the length of the list.The value of
X
andY
should be one of 8, 16, 32.Error response:
Binary:
Restful API responses
/api/v2/info
JSON
Binary
/api/v2/tips
JSON
Binary
/api/v2/messages/{messageId}
JSON
Binary
/api/v2/outputs/{outputId}
JSON
Binary
/api/v2/messages/{messageId}/metadata
JSON
Binary
Indexer responses
All Indexer response are using the same response structure, for example
Binary
Pros
Cons
Conclusion
As constrained clients, such as a system under 100MHz CPU and 256KB memory, the communication should be packed and come with a small memory footprint, this proposal provides a friendly communication channel and opens a door for IoT adoption in the early stage.
Beta Was this translation helpful? Give feedback.
All reactions