Limitation of nanopb

283 views
Skip to first unread message

yul...@gmail.com

unread,
Apr 26, 2017, 2:24:00 AM4/26/17
to nanopb
Dear sir,

When I am the newer to use nanopb and study the document of nanopb on website, there are some questions that I want to ask. Thank you.

Q1. Could you explain the following statement and give a example to tell me? What is unknown fields?
"Unknown fields are not preserved when decoding and re-encoding a message."

Q2. I also don't understand the folowing statement and could you also describe and give me the real example to explain?
"Cyclic references between messages are supported only in callback and malloc mode."

Thank you.

Shelley

Petteri Aimonen

unread,
Apr 26, 2017, 2:29:32 AM4/26/17
to nan...@googlegroups.com
Hi,

> Q1. Could you explain the following statement and give a example to
> tell me? What is unknown fields? "Unknown fields are not preserved
> when decoding and re-encoding a message."

Consider two applications using different versions of message
definition:

Application1:
message MyMessage {
optional int32 field1 = 1;
}

Application2:
message MyMessage {
optional int32 field1 = 1;
optional int32 field2 = 2;
}

If Application2 sends a message with field2 to Application1, the first
application does not know anything about this field and cannot decode
it. This is what I call an unknown field.

The original Google Protobuf library stores unknown fields as binary
data, and if you re-encode the message it will keep them in the message.
However for simplicity and to conserve memory, nanopb will discard such
unknown fields.

For most applications this is not a problem, as most applications don't
care about preserving unknown fields.

> Q2. I also don't understand the folowing statement and could you also describe and give me the real example to explain?
> "Cyclic references between messages are supported only in callback and malloc mode."

message MyRecursiveMessage {
optional MyRecursiveMessage field1 = 1;
}

This cannot be represented as a plain C struct, because it would require
infinite memory. But it can be used in the two other modes, even though
it is more complex for the user.

However it is pretty rare that this sort of cyclic messages are used.

--
Petteri

yul...@gmail.com

unread,
Apr 26, 2017, 2:49:55 AM4/26/17
to nanopb, j...@kapsi.fi
Dear sir,

Thank you for your fast and full reply.
There is one more question to ask you.
Could you also describe and give me the real example to explain reflection example?
Shelley


"Reflection (runtime introspection) is not supported. E.g. you can't request a field by giving its name in a string."

Petteri Aimonen

unread,
Apr 26, 2017, 5:06:57 AM4/26/17
to nanopb groups
Hi,

> Could you also describe and give me the real example to explain reflection example?

In Google's own protobuf there is an API to do things like get the names
of all fields in a message, or to select a field based on its name
coming from a string, or to load new message types in runtime. I'm not
familiar with its usage but here is some example:
http://stackoverflow.com/questions/23963978/c-protobuf-how-to-iterate-through-fields-of-message

In nanopb there is no such facility, all message types and field names
must be known in compile time.

--
Petteri

yul...@gmail.com

unread,
Apr 26, 2017, 9:13:47 PM4/26/17
to nanopb, j...@kapsi.fi
Dear Petteri

I am really appreciate your answer.
Thank you!!

Shelley

Reply all
Reply to author
Forward
0 new messages