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

protocol: frame messages with length-prefix instead of newlines #51

Merged
merged 4 commits into from
Feb 6, 2024

Conversation

jackyzha0
Copy link
Member

Why

We want to have newlines in our messages :) The old approach failed when we used the binary codec with a string or Uint8Array that contained a newline in it. This is because we framed our messages with newlines so we would get cases where a single message would be split in two.

What changed

Use uint32-prefix framing instead.

const spy = vi.fn();
parser.on('data', spy);

const emojiMessage = '🇧🇪🇨🇦👨‍👩‍👧‍👦';
Copy link
Contributor

Choose a reason for hiding this comment

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

giuseppe would be proud.

Copy link
Member Author

Choose a reason for hiding this comment

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

the notorious 🇩🇪 returns

Copy link

Choose a reason for hiding this comment

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

❤️

});
}

export const MessageFramer = {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it worth having a no-op framer for when we write these things to a websocket transport (or something that already has framing built-in? like a SEQPACKET UDS)

Copy link
Contributor

Choose a reason for hiding this comment

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

ah nevermind, i saw that those cases don't even use one. carry on.

Co-authored-by: lhchavez <lhchavez@lhchavez.com>
@jackyzha0 jackyzha0 merged commit 08445c3 into main Feb 6, 2024
3 checks passed
@jackyzha0 jackyzha0 deleted the jackyzha0/length-delimiting branch February 6, 2024 22:54
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.

3 participants