From d81d15b43a6b2a1898d8ea28db8d28f45a618087 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 28 Jul 2022 21:21:34 +0100 Subject: [PATCH] feat!: support no-copy serialization Accept Uint8ArrayLists as input for desrialization. BREAKING CHANGE: Uses Uint8ArrayList v2 --- packages/protons-runtime/package.json | 2 +- packages/protons-runtime/src/codecs/bytes.ts | 2 +- packages/protons-runtime/src/codecs/string.ts | 2 +- packages/protons-runtime/src/decode.ts | 6 +- packages/protons-runtime/src/encode.ts | 9 ++- packages/protons/package.json | 3 +- packages/protons/src/index.ts | 8 +- packages/protons/test/fixtures/basic.ts | 5 +- packages/protons/test/fixtures/circuit.ts | 9 ++- packages/protons/test/fixtures/daemon.ts | 73 ++++++++++--------- packages/protons/test/fixtures/dht.ts | 13 ++-- packages/protons/test/fixtures/noise.ts | 5 +- packages/protons/test/fixtures/peer.ts | 13 ++-- packages/protons/test/fixtures/test.ts | 9 ++- packages/protons/test/index.spec.ts | 12 +-- 15 files changed, 94 insertions(+), 77 deletions(-) diff --git a/packages/protons-runtime/package.json b/packages/protons-runtime/package.json index 2d6f291..2b9be40 100644 --- a/packages/protons-runtime/package.json +++ b/packages/protons-runtime/package.json @@ -143,7 +143,7 @@ "release": "aegir release" }, "dependencies": { - "uint8arraylist": "^1.4.0", + "uint8arraylist": "^2.0.0", "uint8arrays": "^3.0.0" }, "devDependencies": { diff --git a/packages/protons-runtime/src/codecs/bytes.ts b/packages/protons-runtime/src/codecs/bytes.ts index b8e826e..d86ce3e 100644 --- a/packages/protons-runtime/src/codecs/bytes.ts +++ b/packages/protons-runtime/src/codecs/bytes.ts @@ -21,7 +21,7 @@ const decode: DecodeFunction = function bytesDecode (buf, offset) { const byteLength = unsigned.decode(buf, offset) offset += unsigned.encodingLength(byteLength) - return buf.slice(offset, offset + byteLength) + return buf.subarray(offset, offset + byteLength) } export const bytes = createCodec('bytes', CODEC_TYPES.LENGTH_DELIMITED, encode, decode, encodingLength) diff --git a/packages/protons-runtime/src/codecs/string.ts b/packages/protons-runtime/src/codecs/string.ts index d544ade..04ebf11 100644 --- a/packages/protons-runtime/src/codecs/string.ts +++ b/packages/protons-runtime/src/codecs/string.ts @@ -23,7 +23,7 @@ const decode: DecodeFunction = function stringDecode (buf, offset) { const strLen = unsigned.decode(buf, offset) offset += unsigned.encodingLength(strLen) - return uint8ArrayToString(buf.slice(offset, offset + strLen)) + return uint8ArrayToString(buf.subarray(offset, offset + strLen)) } export const string = createCodec('string', CODEC_TYPES.LENGTH_DELIMITED, encode, decode, encodingLength) diff --git a/packages/protons-runtime/src/decode.ts b/packages/protons-runtime/src/decode.ts index 92ec257..d9229e5 100644 --- a/packages/protons-runtime/src/decode.ts +++ b/packages/protons-runtime/src/decode.ts @@ -2,10 +2,10 @@ import { Uint8ArrayList } from 'uint8arraylist' import { unsigned } from './utils/varint.js' import type { Codec } from './codec.js' -export function decodeMessage (buf: Uint8Array, codec: Codec) { +export function decodeMessage (buf: Uint8Array | Uint8ArrayList, codec: Codec): T { // wrap root message - const prefix = new Uint8Array(unsigned.encodingLength(buf.length)) - unsigned.encode(buf.length, prefix) + const prefix = new Uint8Array(unsigned.encodingLength(buf.byteLength)) + unsigned.encode(buf.byteLength, prefix) return codec.decode(new Uint8ArrayList(prefix, buf), 0) } diff --git a/packages/protons-runtime/src/encode.ts b/packages/protons-runtime/src/encode.ts index f82cfcc..a92ba64 100644 --- a/packages/protons-runtime/src/encode.ts +++ b/packages/protons-runtime/src/encode.ts @@ -1,10 +1,15 @@ +import { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from './codec.js' import { unsigned } from './utils/varint.js' -export function encodeMessage (message: T, codec: Codec) { +export function encodeMessage (message: T, codec: Codec): 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) } diff --git a/packages/protons/package.json b/packages/protons/package.json index e7fdee3..0bcb45b 100644 --- a/packages/protons/package.json +++ b/packages/protons/package.json @@ -154,6 +154,7 @@ "devDependencies": { "aegir": "^37.0.5", "pbjs": "^0.0.14", - "protons-runtime": "^1.0.0" + "protons-runtime": "^1.0.0", + "uint8arraylist": "^2.0.0" } } diff --git a/packages/protons/src/index.ts b/packages/protons/src/index.ts index 7aee805..6feceaf 100644 --- a/packages/protons/src/index.ts +++ b/packages/protons/src/index.ts @@ -215,11 +215,11 @@ export interface ${messageDef.name} { }) } - export const encode = (obj: ${messageDef.name}): Uint8Array => { + export const encode = (obj: ${messageDef.name}): Uint8ArrayList => { return encodeMessage(obj, ${messageDef.name}.codec()) } - export const decode = (buf: Uint8Array): ${messageDef.name} => { + export const decode = (buf: Uint8Array | Uint8ArrayList): ${messageDef.name} => { return decodeMessage(buf, ${messageDef.name}.codec()) }` } @@ -310,6 +310,10 @@ export async function generate (source: string, flags: any) { lines.push(`import type { ${Array.from(moduleDef.importedTypes).join(', ')} } from 'protons-runtime'`) } + if (moduleDef.imports.has('encodeMessage')) { + lines.push("import type { Uint8ArrayList } from 'uint8arraylist'") + } + lines = [ ...lines, '', diff --git a/packages/protons/test/fixtures/basic.ts b/packages/protons/test/fixtures/basic.ts index e340908..7491aed 100644 --- a/packages/protons/test/fixtures/basic.ts +++ b/packages/protons/test/fixtures/basic.ts @@ -3,6 +3,7 @@ import { encodeMessage, decodeMessage, message, string, int32 } from 'protons-runtime' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Basic { foo: string @@ -17,11 +18,11 @@ export namespace Basic { }) } - export const encode = (obj: Basic): Uint8Array => { + export const encode = (obj: Basic): Uint8ArrayList => { return encodeMessage(obj, Basic.codec()) } - export const decode = (buf: Uint8Array): Basic => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Basic => { return decodeMessage(buf, Basic.codec()) } } diff --git a/packages/protons/test/fixtures/circuit.ts b/packages/protons/test/fixtures/circuit.ts index 71ee1b9..ec47246 100644 --- a/packages/protons/test/fixtures/circuit.ts +++ b/packages/protons/test/fixtures/circuit.ts @@ -3,6 +3,7 @@ import { enumeration, encodeMessage, decodeMessage, message, bytes } from 'protons-runtime' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface CircuitRelay { type?: CircuitRelay.Type @@ -89,11 +90,11 @@ export namespace CircuitRelay { }) } - export const encode = (obj: Peer): Uint8Array => { + export const encode = (obj: Peer): Uint8ArrayList => { return encodeMessage(obj, Peer.codec()) } - export const decode = (buf: Uint8Array): Peer => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Peer => { return decodeMessage(buf, Peer.codec()) } } @@ -107,11 +108,11 @@ export namespace CircuitRelay { }) } - export const encode = (obj: CircuitRelay): Uint8Array => { + export const encode = (obj: CircuitRelay): Uint8ArrayList => { return encodeMessage(obj, CircuitRelay.codec()) } - export const decode = (buf: Uint8Array): CircuitRelay => { + export const decode = (buf: Uint8Array | Uint8ArrayList): CircuitRelay => { return decodeMessage(buf, CircuitRelay.codec()) } } diff --git a/packages/protons/test/fixtures/daemon.ts b/packages/protons/test/fixtures/daemon.ts index 7b4e7a1..3c0a958 100644 --- a/packages/protons/test/fixtures/daemon.ts +++ b/packages/protons/test/fixtures/daemon.ts @@ -3,6 +3,7 @@ import { enumeration, encodeMessage, decodeMessage, message, bytes, int64, string, int32 } from 'protons-runtime' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Request { type: Request.Type @@ -63,11 +64,11 @@ export namespace Request { }) } - export const encode = (obj: Request): Uint8Array => { + export const encode = (obj: Request): Uint8ArrayList => { return encodeMessage(obj, Request.codec()) } - export const decode = (buf: Uint8Array): Request => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Request => { return decodeMessage(buf, Request.codec()) } } @@ -113,11 +114,11 @@ export namespace Response { }) } - export const encode = (obj: Response): Uint8Array => { + export const encode = (obj: Response): Uint8ArrayList => { return encodeMessage(obj, Response.codec()) } - export const decode = (buf: Uint8Array): Response => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Response => { return decodeMessage(buf, Response.codec()) } } @@ -135,11 +136,11 @@ export namespace IdentifyResponse { }) } - export const encode = (obj: IdentifyResponse): Uint8Array => { + export const encode = (obj: IdentifyResponse): Uint8ArrayList => { return encodeMessage(obj, IdentifyResponse.codec()) } - export const decode = (buf: Uint8Array): IdentifyResponse => { + export const decode = (buf: Uint8Array | Uint8ArrayList): IdentifyResponse => { return decodeMessage(buf, IdentifyResponse.codec()) } } @@ -159,11 +160,11 @@ export namespace ConnectRequest { }) } - export const encode = (obj: ConnectRequest): Uint8Array => { + export const encode = (obj: ConnectRequest): Uint8ArrayList => { return encodeMessage(obj, ConnectRequest.codec()) } - export const decode = (buf: Uint8Array): ConnectRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): ConnectRequest => { return decodeMessage(buf, ConnectRequest.codec()) } } @@ -183,11 +184,11 @@ export namespace StreamOpenRequest { }) } - export const encode = (obj: StreamOpenRequest): Uint8Array => { + export const encode = (obj: StreamOpenRequest): Uint8ArrayList => { return encodeMessage(obj, StreamOpenRequest.codec()) } - export const decode = (buf: Uint8Array): StreamOpenRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): StreamOpenRequest => { return decodeMessage(buf, StreamOpenRequest.codec()) } } @@ -205,11 +206,11 @@ export namespace StreamHandlerRequest { }) } - export const encode = (obj: StreamHandlerRequest): Uint8Array => { + export const encode = (obj: StreamHandlerRequest): Uint8ArrayList => { return encodeMessage(obj, StreamHandlerRequest.codec()) } - export const decode = (buf: Uint8Array): StreamHandlerRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): StreamHandlerRequest => { return decodeMessage(buf, StreamHandlerRequest.codec()) } } @@ -225,11 +226,11 @@ export namespace ErrorResponse { }) } - export const encode = (obj: ErrorResponse): Uint8Array => { + export const encode = (obj: ErrorResponse): Uint8ArrayList => { return encodeMessage(obj, ErrorResponse.codec()) } - export const decode = (buf: Uint8Array): ErrorResponse => { + export const decode = (buf: Uint8Array | Uint8ArrayList): ErrorResponse => { return decodeMessage(buf, ErrorResponse.codec()) } } @@ -249,11 +250,11 @@ export namespace StreamInfo { }) } - export const encode = (obj: StreamInfo): Uint8Array => { + export const encode = (obj: StreamInfo): Uint8ArrayList => { return encodeMessage(obj, StreamInfo.codec()) } - export const decode = (buf: Uint8Array): StreamInfo => { + export const decode = (buf: Uint8Array | Uint8ArrayList): StreamInfo => { return decodeMessage(buf, StreamInfo.codec()) } } @@ -311,11 +312,11 @@ export namespace DHTRequest { }) } - export const encode = (obj: DHTRequest): Uint8Array => { + export const encode = (obj: DHTRequest): Uint8ArrayList => { return encodeMessage(obj, DHTRequest.codec()) } - export const decode = (buf: Uint8Array): DHTRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): DHTRequest => { return decodeMessage(buf, DHTRequest.codec()) } } @@ -353,11 +354,11 @@ export namespace DHTResponse { }) } - export const encode = (obj: DHTResponse): Uint8Array => { + export const encode = (obj: DHTResponse): Uint8ArrayList => { return encodeMessage(obj, DHTResponse.codec()) } - export const decode = (buf: Uint8Array): DHTResponse => { + export const decode = (buf: Uint8Array | Uint8ArrayList): DHTResponse => { return decodeMessage(buf, DHTResponse.codec()) } } @@ -375,11 +376,11 @@ export namespace PeerInfo { }) } - export const encode = (obj: PeerInfo): Uint8Array => { + export const encode = (obj: PeerInfo): Uint8ArrayList => { return encodeMessage(obj, PeerInfo.codec()) } - export const decode = (buf: Uint8Array): PeerInfo => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PeerInfo => { return decodeMessage(buf, PeerInfo.codec()) } } @@ -419,11 +420,11 @@ export namespace ConnManagerRequest { }) } - export const encode = (obj: ConnManagerRequest): Uint8Array => { + export const encode = (obj: ConnManagerRequest): Uint8ArrayList => { return encodeMessage(obj, ConnManagerRequest.codec()) } - export const decode = (buf: Uint8Array): ConnManagerRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): ConnManagerRequest => { return decodeMessage(buf, ConnManagerRequest.codec()) } } @@ -439,11 +440,11 @@ export namespace DisconnectRequest { }) } - export const encode = (obj: DisconnectRequest): Uint8Array => { + export const encode = (obj: DisconnectRequest): Uint8ArrayList => { return encodeMessage(obj, DisconnectRequest.codec()) } - export const decode = (buf: Uint8Array): DisconnectRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): DisconnectRequest => { return decodeMessage(buf, DisconnectRequest.codec()) } } @@ -483,11 +484,11 @@ export namespace PSRequest { }) } - export const encode = (obj: PSRequest): Uint8Array => { + export const encode = (obj: PSRequest): Uint8ArrayList => { return encodeMessage(obj, PSRequest.codec()) } - export const decode = (buf: Uint8Array): PSRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PSRequest => { return decodeMessage(buf, PSRequest.codec()) } } @@ -513,11 +514,11 @@ export namespace PSMessage { }) } - export const encode = (obj: PSMessage): Uint8Array => { + export const encode = (obj: PSMessage): Uint8ArrayList => { return encodeMessage(obj, PSMessage.codec()) } - export const decode = (buf: Uint8Array): PSMessage => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PSMessage => { return decodeMessage(buf, PSMessage.codec()) } } @@ -535,11 +536,11 @@ export namespace PSResponse { }) } - export const encode = (obj: PSResponse): Uint8Array => { + export const encode = (obj: PSResponse): Uint8ArrayList => { return encodeMessage(obj, PSResponse.codec()) } - export const decode = (buf: Uint8Array): PSResponse => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PSResponse => { return decodeMessage(buf, PSResponse.codec()) } } @@ -575,11 +576,11 @@ export namespace PeerstoreRequest { }) } - export const encode = (obj: PeerstoreRequest): Uint8Array => { + export const encode = (obj: PeerstoreRequest): Uint8ArrayList => { return encodeMessage(obj, PeerstoreRequest.codec()) } - export const decode = (buf: Uint8Array): PeerstoreRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PeerstoreRequest => { return decodeMessage(buf, PeerstoreRequest.codec()) } } @@ -597,11 +598,11 @@ export namespace PeerstoreResponse { }) } - export const encode = (obj: PeerstoreResponse): Uint8Array => { + export const encode = (obj: PeerstoreResponse): Uint8ArrayList => { return encodeMessage(obj, PeerstoreResponse.codec()) } - export const decode = (buf: Uint8Array): PeerstoreResponse => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PeerstoreResponse => { return decodeMessage(buf, PeerstoreResponse.codec()) } } diff --git a/packages/protons/test/fixtures/dht.ts b/packages/protons/test/fixtures/dht.ts index f46af45..125655e 100644 --- a/packages/protons/test/fixtures/dht.ts +++ b/packages/protons/test/fixtures/dht.ts @@ -3,6 +3,7 @@ import { encodeMessage, decodeMessage, message, bytes, string, enumeration, int32 } from 'protons-runtime' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Record { key?: Uint8Array @@ -23,11 +24,11 @@ export namespace Record { }) } - export const encode = (obj: Record): Uint8Array => { + export const encode = (obj: Record): Uint8ArrayList => { return encodeMessage(obj, Record.codec()) } - export const decode = (buf: Uint8Array): Record => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Record => { return decodeMessage(buf, Record.codec()) } } @@ -101,11 +102,11 @@ export namespace Message { }) } - export const encode = (obj: Peer): Uint8Array => { + export const encode = (obj: Peer): Uint8ArrayList => { return encodeMessage(obj, Peer.codec()) } - export const decode = (buf: Uint8Array): Peer => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Peer => { return decodeMessage(buf, Peer.codec()) } } @@ -121,11 +122,11 @@ export namespace Message { }) } - export const encode = (obj: Message): Uint8Array => { + export const encode = (obj: Message): Uint8ArrayList => { return encodeMessage(obj, Message.codec()) } - export const decode = (buf: Uint8Array): Message => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Message => { return decodeMessage(buf, Message.codec()) } } diff --git a/packages/protons/test/fixtures/noise.ts b/packages/protons/test/fixtures/noise.ts index 855a319..1c75bc4 100644 --- a/packages/protons/test/fixtures/noise.ts +++ b/packages/protons/test/fixtures/noise.ts @@ -3,6 +3,7 @@ import { encodeMessage, decodeMessage, message, bytes } from 'protons-runtime' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export namespace pb { export interface NoiseHandshakePayload { @@ -20,11 +21,11 @@ export namespace pb { }) } - export const encode = (obj: NoiseHandshakePayload): Uint8Array => { + export const encode = (obj: NoiseHandshakePayload): Uint8ArrayList => { return encodeMessage(obj, NoiseHandshakePayload.codec()) } - export const decode = (buf: Uint8Array): NoiseHandshakePayload => { + export const decode = (buf: Uint8Array | Uint8ArrayList): NoiseHandshakePayload => { return decodeMessage(buf, NoiseHandshakePayload.codec()) } } diff --git a/packages/protons/test/fixtures/peer.ts b/packages/protons/test/fixtures/peer.ts index 3d7c83c..f089a4f 100644 --- a/packages/protons/test/fixtures/peer.ts +++ b/packages/protons/test/fixtures/peer.ts @@ -3,6 +3,7 @@ import { encodeMessage, decodeMessage, message, string, bytes, bool } from 'protons-runtime' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Peer { addresses: Address[] @@ -23,11 +24,11 @@ export namespace Peer { }) } - export const encode = (obj: Peer): Uint8Array => { + export const encode = (obj: Peer): Uint8ArrayList => { return encodeMessage(obj, Peer.codec()) } - export const decode = (buf: Uint8Array): Peer => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Peer => { return decodeMessage(buf, Peer.codec()) } } @@ -45,11 +46,11 @@ export namespace Address { }) } - export const encode = (obj: Address): Uint8Array => { + export const encode = (obj: Address): Uint8ArrayList => { return encodeMessage(obj, Address.codec()) } - export const decode = (buf: Uint8Array): Address => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Address => { return decodeMessage(buf, Address.codec()) } } @@ -67,11 +68,11 @@ export namespace Metadata { }) } - export const encode = (obj: Metadata): Uint8Array => { + export const encode = (obj: Metadata): Uint8ArrayList => { return encodeMessage(obj, Metadata.codec()) } - export const decode = (buf: Uint8Array): Metadata => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Metadata => { return decodeMessage(buf, Metadata.codec()) } } diff --git a/packages/protons/test/fixtures/test.ts b/packages/protons/test/fixtures/test.ts index 893be8b..11e6b16 100644 --- a/packages/protons/test/fixtures/test.ts +++ b/packages/protons/test/fixtures/test.ts @@ -3,6 +3,7 @@ import { enumeration, encodeMessage, decodeMessage, message, string, bool, int32, int64, uint32, uint64, sint32, sint64, double, float, bytes, fixed32, fixed64, sfixed32, sfixed64 } from 'protons-runtime' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export enum AnEnum { HERP = 'HERP', @@ -30,11 +31,11 @@ export namespace SubMessage { }) } - export const encode = (obj: SubMessage): Uint8Array => { + export const encode = (obj: SubMessage): Uint8ArrayList => { return encodeMessage(obj, SubMessage.codec()) } - export const decode = (buf: Uint8Array): SubMessage => { + export const decode = (buf: Uint8Array | Uint8ArrayList): SubMessage => { return decodeMessage(buf, SubMessage.codec()) } } @@ -84,11 +85,11 @@ export namespace AllTheTypes { }) } - export const encode = (obj: AllTheTypes): Uint8Array => { + export const encode = (obj: AllTheTypes): Uint8ArrayList => { return encodeMessage(obj, AllTheTypes.codec()) } - export const decode = (buf: Uint8Array): AllTheTypes => { + export const decode = (buf: Uint8Array | Uint8ArrayList): AllTheTypes => { return decodeMessage(buf, AllTheTypes.codec()) } } diff --git a/packages/protons/test/index.spec.ts b/packages/protons/test/index.spec.ts index 6927aca..1ca67d8 100644 --- a/packages/protons/test/index.spec.ts +++ b/packages/protons/test/index.spec.ts @@ -39,7 +39,7 @@ describe('encode', () => { const schema = pbjs.parseSchema(fs.readFileSync('./test/fixtures/basic.proto', 'utf-8')).compile() const pbjsBuf = schema.encodeBasic(basic) - const encoded = Basic.encode(basic) + const encoded = Basic.encode(basic).subarray() expect(encoded).to.equalBytes(pbjsBuf) const decoded = Basic.decode(encoded) @@ -76,7 +76,7 @@ describe('encode', () => { const schema = pbjs.parseSchema(fs.readFileSync('./test/fixtures/test.proto', 'utf-8')).compile() const pbjsBuf = schema.encodeAllTheTypes(longifyBigInts(allTheTypes)) - const encoded = AllTheTypes.encode(allTheTypes) + const encoded = AllTheTypes.encode(allTheTypes).subarray() expect(encoded).to.equalBytes(pbjsBuf) expect(AllTheTypes.decode(encoded)).to.deep.equal(allTheTypes) @@ -104,7 +104,7 @@ describe('encode', () => { const schema = pbjs.parseSchema(fs.readFileSync('./test/fixtures/test.proto', 'utf-8')).compile() const pbjsBuf = schema.encodeAllTheTypes(longifyBigInts(allTheTypes)) - const encoded = AllTheTypes.encode(allTheTypes) + const encoded = AllTheTypes.encode(allTheTypes).subarray() expect(encoded).to.equalBytes(pbjsBuf) expect(AllTheTypes.decode(encoded)).to.deep.equal(allTheTypes) @@ -132,7 +132,7 @@ describe('encode', () => { const schema = pbjs.parseSchema(fs.readFileSync('./test/fixtures/test.proto', 'utf-8')).compile() const pbjsBuf = schema.encodeAllTheTypes(longifyBigInts(allTheTypes)) - const encoded = AllTheTypes.encode(allTheTypes) + const encoded = AllTheTypes.encode(allTheTypes).subarray() expect(encoded).to.equalBytes(pbjsBuf) expect(AllTheTypes.decode(encoded)).to.deep.equal(allTheTypes) @@ -155,7 +155,7 @@ describe('encode', () => { const schema = pbjs.parseSchema(fs.readFileSync('./test/fixtures/peer.proto', 'utf-8')).compile() const pbjsBuf = schema.encodePeer(peer) - const encoded = Peer.encode(peer) + const encoded = Peer.encode(peer).subarray() expect(encoded).to.equalBytes(pbjsBuf) expect(Peer.decode(encoded)).to.deep.equal(peer) @@ -174,7 +174,7 @@ describe('encode', () => { const pbufJsBuf = PbCircuitRelay.encode(PbCircuitRelay.fromObject(message)).finish() - const encoded = CircuitRelay.encode(message) + const encoded = CircuitRelay.encode(message).subarray() expect(encoded).to.equalBytes(pbufJsBuf)