We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I am trying to encode a utf16 string in protodef but when I do
"string": [ "pstring", { "countType": "u16" } ]
it will encode a utf8 string and when I add
"string": [ "pstring", { "countType": "u16", "encoding": "utf16" } ]
it will just give a validation error
Here is the validation error in case you need it:
{ "keyword": "enum", "dataPath": "", "schemaPath": "#/oneOf/0/enum", "params": { "allowedValues": [ "native" ] }, "message": "should be equal to one of the allowed values", "schema": [ "native" ], "parentSchema": { "enum": [ "native" ] }, "data": [ "pstring", { "countType": "u16", "encoding": "utf16" } ] }
The text was updated successfully, but these errors were encountered:
I fixed my issue by creating my custom implementation:
function read (buffer: Buffer, offset: number): { value: string, size: number } { buffer = buffer.subarray(offset) const uint16Array = bufferToUint16Array(buffer) const length = uint16Array[0] const messageUint16Array = uint16Array.subarray(1, length + 1) const messageBuffer = uint16ArrayToBuffer(messageUint16Array) messageBuffer.swap16() const message = messageBuffer.toString('utf16le') return { value: message, size: size(message) } } function write (value: string, buffer: Buffer, offset: number): number { const messageBuffer = Buffer.from(value, 'utf16le') messageBuffer.swap16() const messageUint16Array = bufferToUint16Array(messageBuffer) const length = value.length const uint16Array = new Uint16Array([length, ...messageUint16Array]) const encodedBuffer = uint16ArrayToBuffer(uint16Array) encodedBuffer.copy(buffer, offset) return offset + encodedBuffer.length } function size (value: string): number { return (value.length + 1) * 2 }
It fixes my problem but it would still be nice to have the option to do it natively.
Sorry, something went wrong.
No branches or pull requests
I am trying to encode a utf16 string in protodef but when I do
it will encode a utf8 string and when I add
it will just give a validation error
Here is the validation error in case you need it:
The text was updated successfully, but these errors were encountered: