iamandi / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

Add #define for maximum serialized size #89

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The generator could generate a #define for each message, which would give the 
maximum serialized size for the message type. This could be used to statically 
allocate message buffers when direct streaming is not possible.

Original issue reported on code.google.com by Petteri.Aimonen on 25 Sep 2013 at 6:02

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 388d4de833cf.

Original comment by Petteri.Aimonen on 26 Sep 2013 at 7:25

GoogleCodeExporter commented 9 years ago
Petteri, I have a question.  I have a case where a maximum size is not 
generated by the tool, but the size is deterministic.  The message in question 
is 

message xmit {
   required MessageHeader header = 1;
   required bytes data = 2 [(nanopb).max_size = 128];
}

Which references

message MessageInfo {
   required fixed32 msg_id = 1;
   optional fixed32 interface_id = 2;
}

message MessageResponseInfo {
   required fixed64 interface_id = 1;
   required fixed32 seq = 2;
   required fixed32 msg_id = 3;
}

message MessageHeader {
   required MessageInfo info = 1;
   optional MessageResponseInfo response_info = 2;
   optional MessageResponse response = 3;
}

message MessageResponse {
   required MessageStatus status = 1;
   required fixed32 seq = 2;
}

If I omit MessageHeader from xmit, a maximum size is generated for xmit.

Is this expected?

Original comment by allen.m...@gmail.com on 23 Oct 2013 at 1:41

GoogleCodeExporter commented 9 years ago
What is the definition of MessageStatus?

Original comment by Petteri.Aimonen on 23 Oct 2013 at 5:59

GoogleCodeExporter commented 9 years ago
/* Enum definitions */
typedef enum _MessageStatus {
    MessageStatus_FAIL = 0,
    MessageStatus_OK = 1
} MessageStatus;

Original comment by allen.m...@gmail.com on 23 Oct 2013 at 4:19

GoogleCodeExporter commented 9 years ago
Hmm, I cannot seem to be able to reproduce this problem. If I compile the 
attached messages.proto, I get the following defines:

#define xmit_size                                179
#define MessageInfo_size                         10
#define MessageResponseInfo_size                 19
#define MessageHeader_size                       46
#define MessageResponse_size                     11

which seems to have all the messages?

Original comment by Petteri.Aimonen on 23 Oct 2013 at 5:13

Attachments:

GoogleCodeExporter commented 9 years ago
One additional piece of information, xmit and the Message definitions live in 
different .proto files.  The Message definitions are included in the file that 
defines xmit.

Original comment by allen.m...@gmail.com on 23 Oct 2013 at 5:15

GoogleCodeExporter commented 9 years ago
Ah.

Unfortunately I don't know a good way to handle that, because the generator has 
to know the size of the submessage so that it can calculate the size of the 
total message. And currently each file is processed separately.

I guess the generator could emit C code like this:
#define xmit_size (133 + MessageHeader_size)

Original comment by Petteri.Aimonen on 23 Oct 2013 at 5:20

GoogleCodeExporter commented 9 years ago
I think that would be reasonable.  Thanks for the fast response.

Original comment by allen.m...@gmail.com on 23 Oct 2013 at 5:29

GoogleCodeExporter commented 9 years ago
Should work now in revision 49bd3f35a0b6db0fa47d2e6e8fe9ddfb1bbcd58b

Original comment by Petteri.Aimonen on 23 Oct 2013 at 6:02

GoogleCodeExporter commented 9 years ago
Fix released in nanopb-0.2.4.

Original comment by Petteri.Aimonen on 7 Nov 2013 at 2:56