Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Length prefixed protobuf messages#54

Merged
ckousik merged 5 commits into
developfrom
ckousik/add-prefix-len
Nov 2, 2022
Merged

Length prefixed protobuf messages#54
ckousik merged 5 commits into
developfrom
ckousik/add-prefix-len

Conversation

@ckousik

@ckousik ckousik commented Oct 31, 2022

Copy link
Copy Markdown
Collaborator

Add length prefix to protobuf messages.

Comment thread src/transport.ts
Comment thread src/stream.ts Outdated
Comment thread src/stream.ts Outdated
Comment thread src/stream.ts Outdated
Comment thread test/transport.browser.spec.ts
Comment thread src/stream.ts Outdated
Comment thread src/stream.ts
Comment thread src/stream.ts
const msgbuf = pb.Message.toBinary({message: buf.subarray()});
const sendbuf = lp.encode.single(msgbuf)
log.trace(`[stream:${this.id}][${this.stat.direction}] sending message: length: ${res.length} ${res}, encoded through pb as ${msgbuf}`);
this.channel.send(sendbuf.subarray())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a question, but why do you have to call subarray all the time? Is it to switch type somehow?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Uint8ArrayList can have a single message spread across multiple different Uint8Array instances. Calling subarray makes them readable as a single Uint8Array which is much easier to work with.

Comment thread src/stream.ts
Comment thread src/stream.ts Outdated
Comment thread src/stream.ts
Comment thread src/stream.ts Outdated
Comment thread src/stream.ts
Comment thread src/transport.ts
Comment thread src/stream.ts Outdated
@mxinden

mxinden commented Nov 1, 2022

Copy link
Copy Markdown
Member

@ckousik does this resolve the compatibility issues you were seeing with libp2p/rust-libp2p#2622?

@ckousik

ckousik commented Nov 2, 2022

Copy link
Copy Markdown
Collaborator Author

@ckousik does this resolve the compatibility issues you were seeing with libp2p/rust-libp2p#2622?

yes

@ckousik
ckousik merged commit 2b7b2c1 into develop Nov 2, 2022
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants