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

Add ability to encode raw binary strings #6

Merged
merged 4 commits into from
Jul 31, 2024
Merged

Conversation

jasonpaulos
Copy link

@jasonpaulos jasonpaulos commented Jul 16, 2024

#3 and #5 added support for decoding raw binary strings, i.e. leaving the value a a byte array instead of decoding into a string object.

This PR does the same for encoding -- you can now encode a byte array as a string. To do so, create an instance of the new RawBinaryString class that wraps your byte array. This type will encode the byte array contents as a string type.

These operations are useful when you must comply with a legacy protocol that uses the string family for values that can contain invalid UTF-8 sequences.

Additionally, during decoding, you can specify the useRawBinaryStringClass option for raw binary strings to be decoded as the new RawBinaryString class. With this, it's now possible to do a complete round-trip decoding and encoding of an object using raw binary strings.

@jasonpaulos jasonpaulos marked this pull request as ready for review July 16, 2024 19:47
test/raw-strings.test.ts Outdated Show resolved Hide resolved
@jasonpaulos jasonpaulos merged commit 6600a96 into main Jul 31, 2024
7 checks passed
@jasonpaulos jasonpaulos deleted the raw-string-encoding branch July 31, 2024 19:29
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