user27798: I am currently developing an IoT device with arduino and i want to minimise the data payload. First i used json which is not very efficent in fixed messages (the format will always be the same). Then i found something like messagepack which also sounds nice but i think you could do even better with just binary. I hope to find something like that:
I have a message for example:
#BOOL#INT#INT#FLOAT#BOOL#STRING#

The position of this variables never change so i could represent the message in binary and i could save a lot of bytes. Is there any library which can de/encode such formats and generate messages from given values?
If not i think it would be very useful in further IoT devices!

user15705: A good choice to send sensor data is CayenneLPP. LPP stands for "Low Power Payload". It is a sensor type aware encoding that uses as few bytes as possible.
A key feature is that recipient must not be aware of content as it is encoded into message, so you can build a generic gateway using that.
You can read more about CayenneLPP here: https://developers.mydevices.com/cayenne/docs/lora/#lora-cayenne-low-power-payload
It is recommended for using it on TTN to minimize payload weigth.
There is an Arduino library for enconding and decoding. For decoding it outputs JSON object so it is ready to be used in platforms like NodeRed or any python or web based application.
Check it here: https://github.com/ElectronicCats/CayenneLPP

user368: No such library is needed, since basic C++ can handle this on its own. Create a packed struct with the fields, fill the fields with assignment or memory copying, and cast to a char* in order to send. Reverse the order of operations in order to receive. Beware the string though, since they need to/should specify a length somewhere.

user3042: Passing messages across computers and/or microcontrollers with different architectures can be a real pain (endianness...). So do not fall into NIH / reinventing the wheel traps but keep standing on the shoulders of giants! Several message serialization protocols exist.

BSON
MessagePack
Protocol Buffers
CBOR (Concise Binary Object Representation)
...

Several implementations of such protocols exist (even for Arduino).
I suggest to have a look in a search engine for such protocols and add Arduino.
I've found:

BSON


ardubson

MessagePack


msgpack-mcu
arduino_msgpack
MsgPacketizer
msgpack-arduino
ArduinoJSON serializeMsgPack / deserializeMsgPack

Protocol Buffers


nanopb

CBOR


Arduino-Cbor

...

PS: You might read https://scottlocklin.wordpress.com/2017/04/02/please-stop-writing-new-serialization-protocols/
and have a look at https://xkcd.com/927/
Just choose a giant compatible with your requirements ;-)
https://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats may help

27798: <p>I am currently developing an IoT device with arduino and i want to minimise the data payload. First i used json which is not very efficent in fixed messages (the format will always be the same). Then i found something like messagepack which also sounds nice but i think you could do even better with just binary. I hope to find something like that:</p>

<p>I have a message for example:</p>

<pre><code>#BOOL#INT#INT#FLOAT#BOOL#STRING#
</code></pre>

<p>The position of this variables never change so i could represent the message in binary and i could save a lot of bytes. Is there any library which can de/encode such formats and generate messages from given values?</p>

<p>If not i think it would be very useful in further IoT devices!</p>
 15705: <p>A good choice to send sensor data is <strong>CayenneLPP</strong>. LPP stands for <strong>"Low Power Payload"</strong>. It is a sensor type aware encoding that uses as few bytes as possible.</p>

<p>A key feature is that recipient must not be aware of content as it is encoded into message, so you can build a generic gateway using that.</p>

<p>You can read more about CayenneLPP here: <a href="https://developers.mydevices.com/cayenne/docs/lora/#lora-cayenne-low-power-payload" rel="nofollow noreferrer">https://developers.mydevices.com/cayenne/docs/lora/#lora-cayenne-low-power-payload</a></p>

<p>It is recommended for using it on TTN to minimize payload weigth.</p>

<p>There is an Arduino library for enconding and decoding. For decoding it outputs JSON object so it is ready to be used in platforms like NodeRed or any python or web based application.</p>

<p>Check it here: <a href="https://github.com/ElectronicCats/CayenneLPP" rel="nofollow noreferrer">https://github.com/ElectronicCats/CayenneLPP</a></p>
 368: <p>No such library is needed, since basic C++ can handle this on its own. Create a packed struct with the fields, fill the fields with assignment or memory copying, and cast to a <code>char*</code> in order to send. Reverse the order of operations in order to receive. Beware the string though, since they need to/should specify a length somewhere.</p>
 3042: <p>Passing messages across computers and/or microcontrollers with different architectures can be a real pain (<a href="https://en.wikipedia.org/wiki/Endianness" rel="nofollow noreferrer">endianness</a>...). So do not fall into <a href="https://en.wikipedia.org/wiki/Not_invented_here" rel="nofollow noreferrer">NIH</a> / <a href="https://en.wikipedia.org/wiki/Reinventing_the_wheel" rel="nofollow noreferrer">reinventing the wheel</a> traps but keep standing on the shoulders of giants! Several message <a href="https://en.wikipedia.org/wiki/Serialization" rel="nofollow noreferrer">serialization</a> protocols exist.</p>

<ul>
<li><a href="https://en.wikipedia.org/wiki/BSON" rel="nofollow noreferrer">BSON</a></li>
<li><a href="https://en.wikipedia.org/wiki/MessagePack" rel="nofollow noreferrer">MessagePack</a></li>
<li><a href="https://en.wikipedia.org/wiki/Protocol_Buffers" rel="nofollow noreferrer">Protocol Buffers</a></li>
<li><a href="https://en.wikipedia.org/wiki/CBOR" rel="nofollow noreferrer">CBOR (Concise Binary Object Representation)</a></li>
<li>...</li>
</ul>

<p>Several implementations of such protocols exist (even for Arduino).</p>

<p>I suggest to have a look in a search engine for such protocols and add <code>Arduino</code>.</p>

<p>I've found:</p>

<ul>
<li>BSON

<ul>
<li><a href="https://github.com/argandas/ardubson" rel="nofollow noreferrer">ardubson</a></li>
</ul></li>
<li>MessagePack

<ul>
<li><a href="https://github.com/hasegaw/msgpack-mcu" rel="nofollow noreferrer">msgpack-mcu</a></li>
<li><a href="https://github.com/HEADS-project/arduino_msgpack" rel="nofollow noreferrer">arduino_msgpack</a></li>
<li><a href="https://github.com/hideakitai/MsgPacketizer" rel="nofollow noreferrer">MsgPacketizer</a></li>
<li><a href="https://github.com/elliotwoods/msgpack-arduino" rel="nofollow noreferrer">msgpack-arduino</a></li>
<li>ArduinoJSON <a href="https://arduinojson.org/v6/api/msgpack/serializemsgpack/" rel="nofollow noreferrer">serializeMsgPack</a> / <a href="https://arduinojson.org/v6/api/msgpack/deserializemsgpack/" rel="nofollow noreferrer">deserializeMsgPack</a></li>
</ul></li>
<li>Protocol Buffers

<ul>
<li><a href="https://github.com/nanopb/nanopb" rel="nofollow noreferrer">nanopb</a></li>
</ul></li>
<li>CBOR

<ul>
<li><a href="https://github.com/jjtara/Library-Arduino-Cbor/" rel="nofollow noreferrer">Arduino-Cbor</a></li>
</ul></li>
<li>...</li>
</ul>

<p>PS: You might read <a href="https://scottlocklin.wordpress.com/2017/04/02/please-stop-writing-new-serialization-protocols/" rel="nofollow noreferrer">https://scottlocklin.wordpress.com/2017/04/02/please-stop-writing-new-serialization-protocols/</a>
and have a look at <a href="https://xkcd.com/927/" rel="nofollow noreferrer">https://xkcd.com/927/</a>
Just choose a giant compatible with your requirements ;-)</p>

<p><a href="https://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats</a> may help</p>
