Comments (6)
I think my previous message was misunderstood. I meant that the option will be gained by FieldReadersTable
which is a generic mechanism defined in the common nim-serialization
library that will be shared by both Json and ProtoBuf. But thanks for sharing these considerations.
from nim-libp2p.
This will be solved by status-im/nim-serialization#20, because the reading code will be modelled after our json deserializer, which can handle fields appearing in arbitrary order:
To clarify the loop above, nim-serialization builds a RTTI table of "field reader" functions. When you encounter a key-value pair, you use the key to find a function that will deserialize the value into the correct field of the object.
from nim-libp2p.
Sure, though I can, at a glance, tell what minprotobuf is doing wrong and how to fix it.
nim-serialization? not so - it looks very clever - but let's not model it too closely after json:
in json duplicate keys are a bit of an open question whereas in pb, the wire encoding for lists and scalars is the same, the difference being that the last seen value is used for scalars - the way it's usually implemented is that it just keeps overwriting the scalar. you could say that it's a feature of pb that you can seamlessly upgrade a scalar to a list and the wire encoding stays the same - some protocols use this for forwards/backwards compatibility schemes.
in protobuf, there are two levels of "structured" decoding - the wire level and the protobuf level - the wire level is useful to decode separately because there are use cases for stopping there and not doing the "protobuf" level - the former is about identifying parsing the stream into keys and values of "approximate" type while the latter is about further refining the value into a more specific type. depending on the application, one or the other level may be appropriate.
protobuf is pretty explicit about the fact that unknown keys should be at least ignored or sometimes kept as unknown generic blobs, in case the message is meant to be reencoded - thus it would go against the spirit of protobuf for the parser to require that all fields are present, which I think that json code does? I mean it does something like raiseUnexpectedField
- but only if totalSerializedFields > 0
which looks a bit odd.
from nim-libp2p.
When I say "modelled after", don't take that too literally. It will be custom code responsible for exposing the peculiarities of ProtoBuf (just like in the json readers you can directly interact with the Json lexer).
protobuf is pretty explicit about the fact that unknown keys should be at least ignored or sometimes kept as unknown generic blobs, in case the message is meant to be reencoded - thus it would go against the spirit of protobuf for the parser to require that all fields are present
The point about unrecognized fields is an interesting one, will consider it during the design. Regarding requiring all fields, this will become a feature of the FieldReadersTable
. It will have an option to populate a bitmask indicating which fields were encountered, so the readers can decide which policy is more appropriate.
from nim-libp2p.
the policy of protobuf is that required fields are a mistake in applications that use protobuf - indeed, in protobuf 3, all fields are optional and the required
specifier is gone. We could do worse than take a hint from google that has plenty of experience in how protobuf is best used.
https://developers.google.com/protocol-buffers/docs/proto#specifying-field-rules
Notice the big warning about required - it's hard to upgrade a distributed system already, and required fields make it worse.
Protobuf is generally use for network protocols (like libp2p) which benefit tremendously from having clients write fallback behaviour deliberately and up front, before the first modifications to the protobuf are necessary - the people using protobuf should always be aware that this will happen eventually. We should certainly not be changing this policy, except maybe as an option that comes with an equally explicit warning, or we will be doing the users of the library a disservice - required
is not an expected use case of protobuf.
from nim-libp2p.
this was fixed
from nim-libp2p.
Related Issues (20)
- CI workflow is failing frequently
- Investigate why issue #868 is causing mesh health problems
- Single-board computer (SBC) support HOT 4
- ARM64/aarch64 support HOT 34
- Reevalute channel / stream / connection abstractions HOT 1
- Cannot run tests on Apple M1 MacOS HOT 2
- Bumper jobs failing HOT 11
- Graceful shutdown process reported as error in logs. HOT 4
- Where should people ask technical questions about nim-libp2p? HOT 1
- Where to have technical discussion about nim-libp2p? HOT 5
- fix(transport-interop): move code in libp2p/test-plans to this repo HOT 3
- minprotobuf does not handle `proto3` `repeated uint32` fields. HOT 6
- Single topic in RPC message
- WebTransport support
- Clear single-vote attestations when aggregate is full HOT 1
- GossipSub messages relayed back to source on 3 node network HOT 5
- peer doesn't respect backingOff
- switch.peerInfo reports with INADDR_ANY or INADDR6_ANY multiaddresses.
- rename nim-libp2p main branch from unstable to master HOT 1
- Prepare release 1.2.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nim-libp2p.