-
Notifications
You must be signed in to change notification settings - Fork 15
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
Encode each attestation by version when sending over the wire #351
Conversation
if len(attestationsBytes) < 4 { | ||
p.Events.Error.Trigger(ierrors.Errorf("failed to deserialize attestations, invalid attestation count"), id) | ||
|
||
return | ||
} | ||
|
||
attestationCount := binary.LittleEndian.Uint32(attestationsBytes[0:4]) |
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.
Checking for the constant, using binary.LittleEndian
package and having a manual readOffset
seems to be a bit cumbersome. I think this would be much nicer with the stream
package, here specifically ReadCollection
encodedAttestations := marshalutil.New() | ||
encodedAttestations.WriteUint32(uint32(len(attestations))) | ||
for _, att := range attestations { | ||
iotagoAPI := lo.PanicOnErr(p.apiProvider.APIForVersion(att.ProtocolVersion)) | ||
encodedAttestations.WriteBytes(lo.PanicOnErr(iotagoAPI.Encode(att))) |
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.
Instead of marshalutil we could use stream.WriteCollection
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.
a bytes buffer does not implement WriteSeeker, so could not use it here
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.
Ok then let's implement something like this https://stackoverflow.com/a/73679110 in the context of #284 so that we're able to use a bytes buffer with the stream package and replace this later
No description provided.