-
Notifications
You must be signed in to change notification settings - Fork 1
Message Pack
For serialization, EmbMessenger uses a modified version of MessagePack. The following table is the list of currently implemented types.
Type | Byte | Example Value | Example Bytes |
---|---|---|---|
Positive FixInt |
0x00 - 0x7F
|
42 |
2A |
Null | 0xC0 |
n/a | C0 |
End Of Message | 0xC1 |
n/a | C1 |
Bool false
|
0xC2 |
false |
C2 |
Bool true
|
0xC3 |
true |
C3 |
Float 32
|
0xCA |
3.14159 |
CA 40 49 0F D0 |
Error | 0xCB |
Param Read Error 0x10
|
CB 10 |
Unsigned Int 8
|
0xCC |
241 |
CC F1 |
Unsigned Int 16
|
0xCD |
61731 |
CD F1 23 |
Unsigned Int 32
|
0xCE |
4045620583 |
CE F1 23 45 67 |
Unsigned Int 64
|
0xCF |
17375808098319191535 |
CF F1 23 45 67 89 AB CD EF |
Signed Int 8
|
0xD0 |
-33 |
D0 DF |
Signed Int 16
|
0xD1 |
-3805 |
D1 F1 23 |
Signed Int 32
|
0xD2 |
-249346713 |
D2 F1 23 45 67 |
Signed Int 64
|
0xD3 |
-1070935975390360081 |
D3 F1 23 45 67 89 AB CD EF |
Negative FixInt |
0xE0 - 0xFF
|
-16 |
F0 |
EmbMessenger has placed a few restrictions on MessagePack. It will not cross signed and unsigned ints; meaning you can't write an unsigned int and read it as a signed int, and vice versa. This is to prevent possible misinterpretations of data, e.g. writing 0xBE
as a uint8_t
intending for it equal 190
, but reading it as a int8_t
, which would equal -66
. EmbMessenger also does not support double
s, this is because not all microprocessors support 64-bit double
s.
EmbMessenger's implementation of MessagePack also supports minimization and expansion of ints. Writing a uint64_t
that fits into a uint8_t
will be sent as a uint8_t
, and you can read a uint8_t
into a uint64_t
.
uint64_t uint64_val = 0x89;
messenger.write(uint64_val); // Writes 0xCC 0x89
int64_t int64_val = -16;
messenger.write(int64_val); // Writes 0xF0
uint64_t uint64_val;
messenger.read(uint64_val); // Reads 0xCC 0x89
// uint64_val contains 0x89
int64_t int64_val;
messenger.read(int64_val); // Reads 0xF0
// int64_val contains -16