Skip to content

Commit

Permalink
fix string encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFoxPro committed Oct 4, 2024
1 parent 6979c76 commit 1e2458a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions serde-generate/runtime/typescript/serde.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type Optional<T> = T | null
export type Seq<T> = T[]
export type Tuple<T extends any[]> = {
[K in keyof T as `$${Exclude<K, keyof any[]> extends string ? Exclude<K, keyof any[]> : never}` ]: T[K]
[K in keyof T as `$${Exclude<K, keyof any[]> extends string ? Exclude<K, keyof any[]> : never}`]: T[K]
}
export type ListTuple<T extends any[]> = Tuple<T>[]
export type Map<K, V> = globalThis.Map<K, V>
Expand Down Expand Up @@ -116,12 +116,12 @@ export abstract class BinaryWriter implements Writer {
abstract sort_map_entries(offsets: number[]): void

public write_string(value: string) {
const length = value.length
// https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto#buffer_sizing
// char and U64 for length
this.alloc(8 + length)
this.alloc(8 + value.length * 3)

// encode into buffer with space for string length (u64)
BinaryWriter.TEXT_ENCODER.encodeInto(value, new Uint8Array(this.view.buffer, this.offset + 8))
let { written: length } = BinaryWriter.TEXT_ENCODER.encodeInto(value, new Uint8Array(this.view.buffer, this.offset + 8))

const bLength = BigInt(length)
this.view.setUint32(this.offset, Number(bLength & BIG_32Fs), true)
Expand Down

0 comments on commit 1e2458a

Please sign in to comment.