Skip to content
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

Merged
merged 2 commits into from
Sep 19, 2023

Conversation

alexsporn
Copy link
Member

No description provided.

@alexsporn alexsporn linked an issue Sep 18, 2023 that may be closed by this pull request
@alexsporn alexsporn changed the title Encode each attestations by version when sending over the wire Encode each attestation by version when sending over the wire Sep 18, 2023
Comment on lines +205 to +211
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])
Copy link
Contributor

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

Comment on lines +78 to +82
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)))
Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Contributor

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

@alexsporn alexsporn merged commit 8241799 into develop Sep 19, 2023
4 checks passed
@alexsporn alexsporn deleted the chore/encode-attestations-by-version branch September 19, 2023 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Encode/Decode attestation one by one
2 participants