From 9eed3842bace3b3ff15ef5fbbc33ca4288dc79e0 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 11 Aug 2022 11:48:06 +0100 Subject: [PATCH] deps: update protons to 5.1.0 (#24) --- package.json | 4 +- src/pb/peer.ts | 229 ++++++++++++++++++++++++++++++++++++++++++++----- src/pb/tags.ts | 124 +++++++++++++++++++++++--- 3 files changed, 323 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 5cff121..3f239d3 100644 --- a/package.json +++ b/package.json @@ -162,7 +162,7 @@ "it-pipe": "^2.0.3", "mortice": "^3.0.0", "multiformats": "^9.6.3", - "protons-runtime": "^2.0.2", + "protons-runtime": "^3.1.0", "uint8arraylist": "^2.1.1", "uint8arrays": "^3.1.0" }, @@ -175,7 +175,7 @@ "delay": "^5.0.0", "p-defer": "^4.0.0", "p-wait-for": "^5.0.0", - "protons": "^4.0.1", + "protons": "^5.1.0", "sinon": "^14.0.0" } } diff --git a/src/pb/peer.ts b/src/pb/peer.ts index f089a4f..f9357a3 100644 --- a/src/pb/peer.ts +++ b/src/pb/peer.ts @@ -1,9 +1,9 @@ /* eslint-disable import/export */ /* eslint-disable @typescript-eslint/no-namespace */ -import { encodeMessage, decodeMessage, message, string, bytes, bool } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { encodeMessage, decodeMessage, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' +import type { Codec } from 'protons-runtime' export interface Peer { addresses: Address[] @@ -14,17 +14,97 @@ export interface Peer { } export namespace Peer { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'addresses', codec: Address.codec(), repeats: true }, - 2: { name: 'protocols', codec: string, repeats: true }, - 3: { name: 'metadata', codec: Metadata.codec(), repeats: true }, - 4: { name: 'pubKey', codec: bytes, optional: true }, - 5: { name: 'peerRecordEnvelope', codec: bytes, optional: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.addresses != null) { + for (const value of obj.addresses) { + writer.uint32(10) + Address.codec().encode(value, writer) + } + } else { + throw new Error('Protocol error: required field "addresses" was not found in object') + } + + if (obj.protocols != null) { + for (const value of obj.protocols) { + writer.uint32(18) + writer.string(value) + } + } else { + throw new Error('Protocol error: required field "protocols" was not found in object') + } + + if (obj.metadata != null) { + for (const value of obj.metadata) { + writer.uint32(26) + Metadata.codec().encode(value, writer) + } + } else { + throw new Error('Protocol error: required field "metadata" was not found in object') + } + + if (obj.pubKey != null) { + writer.uint32(34) + writer.bytes(obj.pubKey) + } + + if (obj.peerRecordEnvelope != null) { + writer.uint32(42) + writer.bytes(obj.peerRecordEnvelope) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = { + addresses: [], + protocols: [], + metadata: [] + } + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.addresses.push(Address.codec().decode(reader, reader.uint32())) + break + case 2: + obj.protocols.push(reader.string()) + break + case 3: + obj.metadata.push(Metadata.codec().decode(reader, reader.uint32())) + break + case 4: + obj.pubKey = reader.bytes() + break + case 5: + obj.peerRecordEnvelope = reader.bytes() + break + default: + reader.skipType(tag & 7) + break + } + } + + return obj + }) + } + + return _codec } - export const encode = (obj: Peer): Uint8ArrayList => { + export const encode = (obj: Peer): Uint8Array => { return encodeMessage(obj, Peer.codec()) } @@ -39,14 +119,65 @@ export interface Address { } export namespace Address { + let _codec: Codec
+ export const codec = (): Codec
=> { - return message
({ - 1: { name: 'multiaddr', codec: bytes }, - 2: { name: 'isCertified', codec: bool, optional: true } - }) + if (_codec == null) { + _codec = message
((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.multiaddr != null) { + writer.uint32(10) + writer.bytes(obj.multiaddr) + } else { + throw new Error('Protocol error: required field "multiaddr" was not found in object') + } + + if (obj.isCertified != null) { + writer.uint32(16) + writer.bool(obj.isCertified) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = { + multiaddr: new Uint8Array(0) + } + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.multiaddr = reader.bytes() + break + case 2: + obj.isCertified = reader.bool() + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.multiaddr == null) { + throw new Error('Protocol error: value for required field "multiaddr" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: Address): Uint8ArrayList => { + export const encode = (obj: Address): Uint8Array => { return encodeMessage(obj, Address.codec()) } @@ -61,14 +192,72 @@ export interface Metadata { } export namespace Metadata { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'key', codec: string }, - 2: { name: 'value', codec: bytes } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.key != null) { + writer.uint32(10) + writer.string(obj.key) + } else { + throw new Error('Protocol error: required field "key" was not found in object') + } + + if (obj.value != null) { + writer.uint32(18) + writer.bytes(obj.value) + } else { + throw new Error('Protocol error: required field "value" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = { + key: '', + value: new Uint8Array(0) + } + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.key = reader.string() + break + case 2: + obj.value = reader.bytes() + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.key == null) { + throw new Error('Protocol error: value for required field "key" was not found in protobuf') + } + + if (obj.value == null) { + throw new Error('Protocol error: value for required field "value" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: Metadata): Uint8ArrayList => { + export const encode = (obj: Metadata): Uint8Array => { return encodeMessage(obj, Metadata.codec()) } diff --git a/src/pb/tags.ts b/src/pb/tags.ts index b749f6f..1e57e06 100644 --- a/src/pb/tags.ts +++ b/src/pb/tags.ts @@ -1,22 +1,64 @@ /* eslint-disable import/export */ /* eslint-disable @typescript-eslint/no-namespace */ -import { encodeMessage, decodeMessage, message, string, uint32, uint64 } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { encodeMessage, decodeMessage, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' +import type { Codec } from 'protons-runtime' export interface Tags { tags: Tag[] } export namespace Tags { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'tags', codec: Tag.codec(), repeats: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.tags != null) { + for (const value of obj.tags) { + writer.uint32(10) + Tag.codec().encode(value, writer) + } + } else { + throw new Error('Protocol error: required field "tags" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = { + tags: [] + } + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.tags.push(Tag.codec().decode(reader, reader.uint32())) + break + default: + reader.skipType(tag & 7) + break + } + } + + return obj + }) + } + + return _codec } - export const encode = (obj: Tags): Uint8ArrayList => { + export const encode = (obj: Tags): Uint8Array => { return encodeMessage(obj, Tags.codec()) } @@ -32,15 +74,73 @@ export interface Tag { } export namespace Tag { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'name', codec: string }, - 2: { name: 'value', codec: uint32, optional: true }, - 3: { name: 'expiry', codec: uint64, optional: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.name != null) { + writer.uint32(10) + writer.string(obj.name) + } else { + throw new Error('Protocol error: required field "name" was not found in object') + } + + if (obj.value != null) { + writer.uint32(16) + writer.uint32(obj.value) + } + + if (obj.expiry != null) { + writer.uint32(24) + writer.uint64(obj.expiry) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = { + name: '' + } + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.name = reader.string() + break + case 2: + obj.value = reader.uint32() + break + case 3: + obj.expiry = reader.uint64() + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.name == null) { + throw new Error('Protocol error: value for required field "name" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: Tag): Uint8ArrayList => { + export const encode = (obj: Tag): Uint8Array => { return encodeMessage(obj, Tag.codec()) }