-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add marshal_strict
feature
#44
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! Sorry for the delay on reviewing this. Code looks good but I'm confused about the varint with a new encoding. Can you clarify?
features/marshal/marshalto.go
Outdated
func (p *marshal) GenerateHelpers() { | ||
p.P(`func encodeVarint(dAtA []byte, offset int, v uint64) int {`) | ||
p.P(`func `, p.encodeVarintMeth(), `(dAtA []byte, offset int, v uint64) int {`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you need a specific name for encodeVarint
. The implementation is identical to the previous, so why name it differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As i commented on 56 line in order to generate helpers for marshal and marshal_strict features independently
.
E.g. if we want to use both marshal
and marshal_strict
features then encodeVarint
implementation would be generated twice that will lead to compilation error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay getting back to this, you caught me in holiday. We need to do better than that for this feature: let's check during codegen whether both marshal
and marshal_strict
are being requested and handle that case by generating the encodeVarint
helpers only once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for long delay! Returned to this PR. Watch please, added duplicate checker for helper functions to avoid duplicates among helper functions names which are generated by different features in the same file.
ca1bd29
to
22e8c81
Compare
22e8c81
to
5652387
Compare
Hello! @vmg , we would be really grateful if you looked the last changes! Thank you! |
How about replacing the default |
I'm afraid it can break something in projects which are using current order. |
Looking at this PR today! |
Hello! We in gowaves use this plug-in to marshal messages for producing signatures futher and compare them to signed messages which would be marshalled by other languages implementations. The problem is that many other implementations of protobuf (for e.g. Java) marshal fields in the strict order by their numbers declared in .proto file. Consequently, the most rational way to use such marshal scheme in all languages we use in our project.
marshal
feature doesn't satisfy this requirement and mustn't do as it should behave indentically toproto.Marshal()
which doesn't satisfy respectively. To be more precise the difference is thatoneOf
s fields are marshalled before others(#22) and in the example belowethereum_transaction
would be marshalled beforeproofs
:But we would like
ethereum_transaction
to be marshalled afterproofs
.We came with implementation of the new feature
marshal_strict
that solves this problem and can be useful in similar cases.