I am trying to define an eight byte MAC address data element using protocol buffers in C. I have tried:
message mac {
required bytes address = 1 [(nanopb).max_size = 8];
}
but this creates a structure with a size field and an eight byte address field. I would like just and eight byte address field.
I rejected using a fixed64 element as a MAC address is a sequence of bytes. Sorry if this is a simple question as I am fairly new to protocol buffers.
The size field is generated because there is no way to force a minimum length on a 'bytes' field. So if whoever created the message didn't give 8 bytes in the field, the rest would be garbage data.
Does the size field cause some trouble? It does certainly consume 2-4 bytes of RAM, but that's all.
(I'm the author of nanopb; though probably this is the same in all the protobuf implementations.)
Update: Since nanopb 0.3.8 (released in 2017) there is now support for fixed length bytes fields using the option (nanopb).fixed_length = true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With