-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: support no-copy serialization (#54)
Accept Uint8ArrayLists as input for desrialization. BREAKING CHANGE: Uses Uint8ArrayList v2
- Loading branch information
1 parent
9b973ee
commit caa0d71
Showing
15 changed files
with
94 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import { Uint8ArrayList } from 'uint8arraylist' | ||
import type { Codec } from './codec.js' | ||
import { unsigned } from './utils/varint.js' | ||
|
||
export function encodeMessage <T> (message: T, codec: Codec<T>) { | ||
export function encodeMessage <T> (message: T, codec: Codec<T>): Uint8ArrayList { | ||
// unwrap root message | ||
const encoded = codec.encode(message) | ||
const skip = unsigned.encodingLength(unsigned.decode(encoded)) | ||
|
||
return encoded.slice(skip) | ||
if (encoded instanceof Uint8Array) { | ||
return new Uint8ArrayList(encoded.subarray(skip)) | ||
} | ||
|
||
return encoded.sublist(skip) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.