From dd88be111ccb5cbc1ed12e6b6f496c002134f9fe Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 8 Aug 2024 11:54:25 +0100 Subject: [PATCH] fix: regenerate protobuf messages Updates to the latest protons message format. --- .../test/fixtures/test-message.ts | 15 ++++++++------- packages/it-rpc/src/rpc.ts | 14 +++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/it-protobuf-stream/test/fixtures/test-message.ts b/packages/it-protobuf-stream/test/fixtures/test-message.ts index e79cb11b..d9f74112 100644 --- a/packages/it-protobuf-stream/test/fixtures/test-message.ts +++ b/packages/it-protobuf-stream/test/fixtures/test-message.ts @@ -4,8 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface TestMessage { @@ -30,7 +29,7 @@ export namespace TestMessage { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { foo: '' } @@ -41,12 +40,14 @@ export namespace TestMessage { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.foo = reader.string() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -61,7 +62,7 @@ export namespace TestMessage { return encodeMessage(obj, TestMessage.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): TestMessage => { - return decodeMessage(buf, TestMessage.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): TestMessage => { + return decodeMessage(buf, TestMessage.codec(), opts) } } diff --git a/packages/it-rpc/src/rpc.ts b/packages/it-rpc/src/rpc.ts index dadcb23e..83b2793b 100644 --- a/packages/it-rpc/src/rpc.ts +++ b/packages/it-rpc/src/rpc.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime' import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' @@ -237,7 +237,7 @@ export namespace InvokeMethodMessage { } case 3: { if (opts.limits?.args != null && obj.args.length === opts.limits.args) { - throw new CodeError('decode error - map field "args" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "args" had too many elements') } obj.args.push(Value.codec().decode(reader, reader.uint32(), { @@ -536,7 +536,7 @@ export namespace InvokeCallbackMessage { } case 2: { if (opts.limits?.parents != null && obj.parents.length === opts.limits.parents) { - throw new CodeError('decode error - map field "parents" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "parents" had too many elements') } obj.parents.push(reader.string()) @@ -548,7 +548,7 @@ export namespace InvokeCallbackMessage { } case 4: { if (opts.limits?.args != null && obj.args.length === opts.limits.args) { - throw new CodeError('decode error - map field "args" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "args" had too many elements') } obj.args.push(Value.codec().decode(reader, reader.uint32(), { @@ -627,7 +627,7 @@ export namespace AbortCallbackMessage { } case 2: { if (opts.limits?.parents != null && obj.parents.length === opts.limits.parents) { - throw new CodeError('decode error - map field "parents" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "parents" had too many elements') } obj.parents.push(reader.string()) @@ -710,7 +710,7 @@ export namespace CallbackResolvedMessage { } case 2: { if (opts.limits?.parents != null && obj.parents.length === opts.limits.parents) { - throw new CodeError('decode error - map field "parents" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "parents" had too many elements') } obj.parents.push(reader.string()) @@ -799,7 +799,7 @@ export namespace CallbackRejectedMessage { } case 2: { if (opts.limits?.parents != null && obj.parents.length === opts.limits.parents) { - throw new CodeError('decode error - map field "parents" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "parents" had too many elements') } obj.parents.push(reader.string())