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

feat: buffer codecs #14

Merged
merged 7 commits into from
Nov 30, 2023
Merged

feat: buffer codecs #14

merged 7 commits into from
Nov 30, 2023

Conversation

jackyzha0
Copy link
Member

@jackyzha0 jackyzha0 commented Nov 30, 2023

Why

Previously, our codecs only encoded/decoded to/from strings. Both websocket and stdio support using raw binary so let's use that instead of string encoding everything

This opens the door to more efficient binary encodings (and also allows us to use Type.Uint8Array() in our services!

@jackyzha0 jackyzha0 requested review from a team, siliconjungle and lhchavez and removed request for a team November 30, 2023 20:28
Comment on lines +7 to +23
function uint8ArrayToBase64(uint8Array: Uint8Array) {
let binary = '';
uint8Array.forEach((byte) => {
binary += String.fromCharCode(byte);
});
return btoa(binary);
}

// Convert base64 to Uint8Array
function base64ToUint8Array(base64: string) {
const binaryString = atob(base64);
const uint8Array = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
uint8Array[i] = binaryString.charCodeAt(i);
}
return uint8Array;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

lol this feels extremely inefficient. but it seems like it's what all the internet answer say to do so 🤷.

Copy link
Member Author

Choose a reason for hiding this comment

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

good thing we're moving away from json :)

* basic binary codec impl

* make e2es run for all codecs
@jackyzha0 jackyzha0 merged commit f633c5b into main Nov 30, 2023
@jackyzha0 jackyzha0 deleted the jackyzha0/codec-buffers branch November 30, 2023 23:57
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.

2 participants