From b78b77120af016e709d9582b86a3d5375a8cd55e Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 7 Apr 2022 18:20:48 +0100 Subject: [PATCH] fix: update generated file --- packages/libp2p-daemon-protocol/src/index.ts | 494 ++++++++++--------- 1 file changed, 272 insertions(+), 222 deletions(-) diff --git a/packages/libp2p-daemon-protocol/src/index.ts b/packages/libp2p-daemon-protocol/src/index.ts index 44aecf12..9872fe4f 100644 --- a/packages/libp2p-daemon-protocol/src/index.ts +++ b/packages/libp2p-daemon-protocol/src/index.ts @@ -3,23 +3,125 @@ import { enumeration, encodeMessage, decodeMessage, message, bytes, int64, string, int32 } from 'protons-runtime' +export interface Request { + type: Request.Type + connect?: ConnectRequest + streamOpen?: StreamOpenRequest + streamHandler?: StreamHandlerRequest + dht?: DHTRequest + connManager?: ConnManagerRequest + disconnect?: DisconnectRequest + pubsub?: PSRequest + peerStore?: PeerstoreRequest +} + +export namespace Request { + export enum Type { + IDENTIFY = 'IDENTIFY', + CONNECT = 'CONNECT', + STREAM_OPEN = 'STREAM_OPEN', + STREAM_HANDLER = 'STREAM_HANDLER', + DHT = 'DHT', + LIST_PEERS = 'LIST_PEERS', + CONNMANAGER = 'CONNMANAGER', + DISCONNECT = 'DISCONNECT', + PUBSUB = 'PUBSUB', + PEERSTORE = 'PEERSTORE' + } + + export namespace Type { + export const codec = () => { + return enumeration(Type) + } + } + + export const codec = () => { + return message({ + 1: { name: 'type', codec: Request.Type.codec() }, + 2: { name: 'connect', codec: ConnectRequest.codec(), optional: true }, + 3: { name: 'streamOpen', codec: StreamOpenRequest.codec(), optional: true }, + 4: { name: 'streamHandler', codec: StreamHandlerRequest.codec(), optional: true }, + 5: { name: 'dht', codec: DHTRequest.codec(), optional: true }, + 6: { name: 'connManager', codec: ConnManagerRequest.codec(), optional: true }, + 7: { name: 'disconnect', codec: DisconnectRequest.codec(), optional: true }, + 8: { name: 'pubsub', codec: PSRequest.codec(), optional: true }, + 9: { name: 'peerStore', codec: PeerstoreRequest.codec(), optional: true } + }) + } + + export const encode = (obj: Request): Uint8Array => { + return encodeMessage(obj, Request.codec()) + } + + export const decode = (buf: Uint8Array): Request => { + return decodeMessage(buf, Request.codec()) + } +} + +export interface Response { + type: Response.Type + error?: ErrorResponse + streamInfo?: StreamInfo + identify?: IdentifyResponse + dht?: DHTResponse + peers: PeerInfo[] + pubsub?: PSResponse + peerStore?: PeerstoreResponse +} + +export namespace Response { + export enum Type { + OK = 'OK', + ERROR = 'ERROR' + } + + export namespace Type { + export const codec = () => { + return enumeration(Type) + } + } + + export const codec = () => { + return message({ + 1: { name: 'type', codec: Response.Type.codec() }, + 2: { name: 'error', codec: ErrorResponse.codec(), optional: true }, + 3: { name: 'streamInfo', codec: StreamInfo.codec(), optional: true }, + 4: { name: 'identify', codec: IdentifyResponse.codec(), optional: true }, + 5: { name: 'dht', codec: DHTResponse.codec(), optional: true }, + 6: { name: 'peers', codec: PeerInfo.codec(), repeats: true }, + 7: { name: 'pubsub', codec: PSResponse.codec(), optional: true }, + 8: { name: 'peerStore', codec: PeerstoreResponse.codec(), optional: true } + }) + } + + export const encode = (obj: Response): Uint8Array => { + return encodeMessage(obj, Response.codec()) + } + + export const decode = (buf: Uint8Array): Response => { + return decodeMessage(buf, Response.codec()) + } +} + export interface IdentifyResponse { id: Uint8Array addrs: Uint8Array[] } export namespace IdentifyResponse { - export const codec = message({ - 1: { name: 'id', codec: bytes }, - 2: { name: 'addrs', codec: bytes, repeats: true } - }) + export const codec = () => { + return message({ + 1: { name: 'id', codec: bytes }, + 2: { name: 'addrs', codec: bytes, repeats: true } + }) + } export const encode = (obj: IdentifyResponse): Uint8Array => { - return encodeMessage(obj, IdentifyResponse.codec) + return encodeMessage(obj, IdentifyResponse.codec()) } export const decode = (buf: Uint8Array): IdentifyResponse => { - return decodeMessage(buf, IdentifyResponse.codec) + return decodeMessage(buf, IdentifyResponse.codec()) } } @@ -30,18 +132,20 @@ export interface ConnectRequest { } export namespace ConnectRequest { - export const codec = message({ - 1: { name: 'peer', codec: bytes }, - 2: { name: 'addrs', codec: bytes, repeats: true }, - 3: { name: 'timeout', codec: int64, optional: true } - }) + export const codec = () => { + return message({ + 1: { name: 'peer', codec: bytes }, + 2: { name: 'addrs', codec: bytes, repeats: true }, + 3: { name: 'timeout', codec: int64, optional: true } + }) + } export const encode = (obj: ConnectRequest): Uint8Array => { - return encodeMessage(obj, ConnectRequest.codec) + return encodeMessage(obj, ConnectRequest.codec()) } export const decode = (buf: Uint8Array): ConnectRequest => { - return decodeMessage(buf, ConnectRequest.codec) + return decodeMessage(buf, ConnectRequest.codec()) } } @@ -52,18 +156,20 @@ export interface StreamOpenRequest { } export namespace StreamOpenRequest { - export const codec = message({ - 1: { name: 'peer', codec: bytes }, - 2: { name: 'proto', codec: string, repeats: true }, - 3: { name: 'timeout', codec: int64, optional: true } - }) + export const codec = () => { + return message({ + 1: { name: 'peer', codec: bytes }, + 2: { name: 'proto', codec: string, repeats: true }, + 3: { name: 'timeout', codec: int64, optional: true } + }) + } export const encode = (obj: StreamOpenRequest): Uint8Array => { - return encodeMessage(obj, StreamOpenRequest.codec) + return encodeMessage(obj, StreamOpenRequest.codec()) } export const decode = (buf: Uint8Array): StreamOpenRequest => { - return decodeMessage(buf, StreamOpenRequest.codec) + return decodeMessage(buf, StreamOpenRequest.codec()) } } @@ -73,17 +179,19 @@ export interface StreamHandlerRequest { } export namespace StreamHandlerRequest { - export const codec = message({ - 1: { name: 'addr', codec: bytes }, - 2: { name: 'proto', codec: string, repeats: true } - }) + export const codec = () => { + return message({ + 1: { name: 'addr', codec: bytes }, + 2: { name: 'proto', codec: string, repeats: true } + }) + } export const encode = (obj: StreamHandlerRequest): Uint8Array => { - return encodeMessage(obj, StreamHandlerRequest.codec) + return encodeMessage(obj, StreamHandlerRequest.codec()) } export const decode = (buf: Uint8Array): StreamHandlerRequest => { - return decodeMessage(buf, StreamHandlerRequest.codec) + return decodeMessage(buf, StreamHandlerRequest.codec()) } } @@ -92,16 +200,18 @@ export interface ErrorResponse { } export namespace ErrorResponse { - export const codec = message({ - 1: { name: 'msg', codec: string } - }) + export const codec = () => { + return message({ + 1: { name: 'msg', codec: string } + }) + } export const encode = (obj: ErrorResponse): Uint8Array => { - return encodeMessage(obj, ErrorResponse.codec) + return encodeMessage(obj, ErrorResponse.codec()) } export const decode = (buf: Uint8Array): ErrorResponse => { - return decodeMessage(buf, ErrorResponse.codec) + return decodeMessage(buf, ErrorResponse.codec()) } } @@ -112,18 +222,20 @@ export interface StreamInfo { } export namespace StreamInfo { - export const codec = message({ - 1: { name: 'peer', codec: bytes }, - 2: { name: 'addr', codec: bytes }, - 3: { name: 'proto', codec: string } - }) + export const codec = () => { + return message({ + 1: { name: 'peer', codec: bytes }, + 2: { name: 'addr', codec: bytes }, + 3: { name: 'proto', codec: string } + }) + } export const encode = (obj: StreamInfo): Uint8Array => { - return encodeMessage(obj, StreamInfo.codec) + return encodeMessage(obj, StreamInfo.codec()) } export const decode = (buf: Uint8Array): StreamInfo => { - return decodeMessage(buf, StreamInfo.codec) + return decodeMessage(buf, StreamInfo.codec()) } } @@ -151,45 +263,29 @@ export namespace DHTRequest { } export namespace Type { - export const codec = enumeration(Type) + export const codec = () => { + return enumeration(Type) + } } - export const codec = message({ - 1: { name: 'type', codec: DHTRequest.Type.codec }, - 2: { name: 'peer', codec: bytes, optional: true }, - 3: { name: 'cid', codec: bytes, optional: true }, - 4: { name: 'key', codec: bytes, optional: true }, - 5: { name: 'value', codec: bytes, optional: true }, - 6: { name: 'count', codec: int32, optional: true }, - 7: { name: 'timeout', codec: int64, optional: true } - }) + export const codec = () => { + return message({ + 1: { name: 'type', codec: DHTRequest.Type.codec() }, + 2: { name: 'peer', codec: bytes, optional: true }, + 3: { name: 'cid', codec: bytes, optional: true }, + 4: { name: 'key', codec: bytes, optional: true }, + 5: { name: 'value', codec: bytes, optional: true }, + 6: { name: 'count', codec: int32, optional: true }, + 7: { name: 'timeout', codec: int64, optional: true } + }) + } export const encode = (obj: DHTRequest): Uint8Array => { - return encodeMessage(obj, DHTRequest.codec) + return encodeMessage(obj, DHTRequest.codec()) } export const decode = (buf: Uint8Array): DHTRequest => { - return decodeMessage(buf, DHTRequest.codec) - } -} - -export interface PeerInfo { - id: Uint8Array - addrs: Uint8Array[] -} - -export namespace PeerInfo { - export const codec = message({ - 1: { name: 'id', codec: bytes }, - 2: { name: 'addrs', codec: bytes, repeats: true } - }) - - export const encode = (obj: PeerInfo): Uint8Array => { - return encodeMessage(obj, PeerInfo.codec) - } - - export const decode = (buf: Uint8Array): PeerInfo => { - return decodeMessage(buf, PeerInfo.codec) + return decodeMessage(buf, DHTRequest.codec()) } } @@ -207,21 +303,47 @@ export namespace DHTResponse { } export namespace Type { - export const codec = enumeration(Type) + export const codec = () => { + return enumeration(Type) + } } - export const codec = message({ - 1: { name: 'type', codec: DHTResponse.Type.codec }, - 2: { name: 'peer', codec: PeerInfo.codec, optional: true }, - 3: { name: 'value', codec: bytes, optional: true } - }) + export const codec = () => { + return message({ + 1: { name: 'type', codec: DHTResponse.Type.codec() }, + 2: { name: 'peer', codec: PeerInfo.codec(), optional: true }, + 3: { name: 'value', codec: bytes, optional: true } + }) + } export const encode = (obj: DHTResponse): Uint8Array => { - return encodeMessage(obj, DHTResponse.codec) + return encodeMessage(obj, DHTResponse.codec()) } export const decode = (buf: Uint8Array): DHTResponse => { - return decodeMessage(buf, DHTResponse.codec) + return decodeMessage(buf, DHTResponse.codec()) + } +} + +export interface PeerInfo { + id: Uint8Array + addrs: Uint8Array[] +} + +export namespace PeerInfo { + export const codec = () => { + return message({ + 1: { name: 'id', codec: bytes }, + 2: { name: 'addrs', codec: bytes, repeats: true } + }) + } + + export const encode = (obj: PeerInfo): Uint8Array => { + return encodeMessage(obj, PeerInfo.codec()) + } + + export const decode = (buf: Uint8Array): PeerInfo => { + return decodeMessage(buf, PeerInfo.codec()) } } @@ -240,22 +362,26 @@ export namespace ConnManagerRequest { } export namespace Type { - export const codec = enumeration(Type) + export const codec = () => { + return enumeration(Type) + } } - export const codec = message({ - 1: { name: 'type', codec: ConnManagerRequest.Type.codec }, - 2: { name: 'peer', codec: bytes, optional: true }, - 3: { name: 'tag', codec: string, optional: true }, - 4: { name: 'weight', codec: int64, optional: true } - }) + export const codec = () => { + return message({ + 1: { name: 'type', codec: ConnManagerRequest.Type.codec() }, + 2: { name: 'peer', codec: bytes, optional: true }, + 3: { name: 'tag', codec: string, optional: true }, + 4: { name: 'weight', codec: int64, optional: true } + }) + } export const encode = (obj: ConnManagerRequest): Uint8Array => { - return encodeMessage(obj, ConnManagerRequest.codec) + return encodeMessage(obj, ConnManagerRequest.codec()) } export const decode = (buf: Uint8Array): ConnManagerRequest => { - return decodeMessage(buf, ConnManagerRequest.codec) + return decodeMessage(buf, ConnManagerRequest.codec()) } } @@ -264,16 +390,18 @@ export interface DisconnectRequest { } export namespace DisconnectRequest { - export const codec = message({ - 1: { name: 'peer', codec: bytes } - }) + export const codec = () => { + return message({ + 1: { name: 'peer', codec: bytes } + }) + } export const encode = (obj: DisconnectRequest): Uint8Array => { - return encodeMessage(obj, DisconnectRequest.codec) + return encodeMessage(obj, DisconnectRequest.codec()) } export const decode = (buf: Uint8Array): DisconnectRequest => { - return decodeMessage(buf, DisconnectRequest.codec) + return decodeMessage(buf, DisconnectRequest.codec()) } } @@ -292,21 +420,25 @@ export namespace PSRequest { } export namespace Type { - export const codec = enumeration(Type) + export const codec = () => { + return enumeration(Type) + } } - export const codec = message({ - 1: { name: 'type', codec: PSRequest.Type.codec }, - 2: { name: 'topic', codec: string, optional: true }, - 3: { name: 'data', codec: bytes, optional: true } - }) + export const codec = () => { + return message({ + 1: { name: 'type', codec: PSRequest.Type.codec() }, + 2: { name: 'topic', codec: string, optional: true }, + 3: { name: 'data', codec: bytes, optional: true } + }) + } export const encode = (obj: PSRequest): Uint8Array => { - return encodeMessage(obj, PSRequest.codec) + return encodeMessage(obj, PSRequest.codec()) } export const decode = (buf: Uint8Array): PSRequest => { - return decodeMessage(buf, PSRequest.codec) + return decodeMessage(buf, PSRequest.codec()) } } @@ -320,21 +452,23 @@ export interface PSMessage { } export namespace PSMessage { - export const codec = message({ - 1: { name: 'from', codec: bytes, optional: true }, - 2: { name: 'data', codec: bytes, optional: true }, - 3: { name: 'seqno', codec: bytes, optional: true }, - 4: { name: 'topicIDs', codec: string, repeats: true }, - 5: { name: 'signature', codec: bytes, optional: true }, - 6: { name: 'key', codec: bytes, optional: true } - }) + export const codec = () => { + return message({ + 1: { name: 'from', codec: bytes, optional: true }, + 2: { name: 'data', codec: bytes, optional: true }, + 3: { name: 'seqno', codec: bytes, optional: true }, + 4: { name: 'topicIDs', codec: string, repeats: true }, + 5: { name: 'signature', codec: bytes, optional: true }, + 6: { name: 'key', codec: bytes, optional: true } + }) + } export const encode = (obj: PSMessage): Uint8Array => { - return encodeMessage(obj, PSMessage.codec) + return encodeMessage(obj, PSMessage.codec()) } export const decode = (buf: Uint8Array): PSMessage => { - return decodeMessage(buf, PSMessage.codec) + return decodeMessage(buf, PSMessage.codec()) } } @@ -344,17 +478,19 @@ export interface PSResponse { } export namespace PSResponse { - export const codec = message({ - 1: { name: 'topics', codec: string, repeats: true }, - 2: { name: 'peerIDs', codec: bytes, repeats: true } - }) + export const codec = () => { + return message({ + 1: { name: 'topics', codec: string, repeats: true }, + 2: { name: 'peerIDs', codec: bytes, repeats: true } + }) + } export const encode = (obj: PSResponse): Uint8Array => { - return encodeMessage(obj, PSResponse.codec) + return encodeMessage(obj, PSResponse.codec()) } export const decode = (buf: Uint8Array): PSResponse => { - return decodeMessage(buf, PSResponse.codec) + return decodeMessage(buf, PSResponse.codec()) } } @@ -371,21 +507,25 @@ export namespace PeerstoreRequest { } export namespace Type { - export const codec = enumeration(Type) + export const codec = () => { + return enumeration(Type) + } } - export const codec = message({ - 1: { name: 'type', codec: PeerstoreRequest.Type.codec }, - 2: { name: 'id', codec: bytes, optional: true }, - 3: { name: 'protos', codec: string, repeats: true } - }) + export const codec = () => { + return message({ + 1: { name: 'type', codec: PeerstoreRequest.Type.codec() }, + 2: { name: 'id', codec: bytes, optional: true }, + 3: { name: 'protos', codec: string, repeats: true } + }) + } export const encode = (obj: PeerstoreRequest): Uint8Array => { - return encodeMessage(obj, PeerstoreRequest.codec) + return encodeMessage(obj, PeerstoreRequest.codec()) } export const decode = (buf: Uint8Array): PeerstoreRequest => { - return decodeMessage(buf, PeerstoreRequest.codec) + return decodeMessage(buf, PeerstoreRequest.codec()) } } @@ -395,108 +535,18 @@ export interface PeerstoreResponse { } export namespace PeerstoreResponse { - export const codec = message({ - 1: { name: 'peer', codec: PeerInfo.codec, optional: true }, - 2: { name: 'protos', codec: string, repeats: true } - }) + export const codec = () => { + return message({ + 1: { name: 'peer', codec: PeerInfo.codec(), optional: true }, + 2: { name: 'protos', codec: string, repeats: true } + }) + } export const encode = (obj: PeerstoreResponse): Uint8Array => { - return encodeMessage(obj, PeerstoreResponse.codec) + return encodeMessage(obj, PeerstoreResponse.codec()) } export const decode = (buf: Uint8Array): PeerstoreResponse => { - return decodeMessage(buf, PeerstoreResponse.codec) - } -} - -export interface Request { - type: Request.Type - connect?: ConnectRequest - streamOpen?: StreamOpenRequest - streamHandler?: StreamHandlerRequest - dht?: DHTRequest - connManager?: ConnManagerRequest - disconnect?: DisconnectRequest - pubsub?: PSRequest - peerStore?: PeerstoreRequest -} - -export namespace Request { - export enum Type { - IDENTIFY = 'IDENTIFY', - CONNECT = 'CONNECT', - STREAM_OPEN = 'STREAM_OPEN', - STREAM_HANDLER = 'STREAM_HANDLER', - DHT = 'DHT', - LIST_PEERS = 'LIST_PEERS', - CONNMANAGER = 'CONNMANAGER', - DISCONNECT = 'DISCONNECT', - PUBSUB = 'PUBSUB', - PEERSTORE = 'PEERSTORE' - } - - export namespace Type { - export const codec = enumeration(Type) - } - - export const codec = message({ - 1: { name: 'type', codec: Request.Type.codec }, - 2: { name: 'connect', codec: ConnectRequest.codec, optional: true }, - 3: { name: 'streamOpen', codec: StreamOpenRequest.codec, optional: true }, - 4: { name: 'streamHandler', codec: StreamHandlerRequest.codec, optional: true }, - 5: { name: 'dht', codec: DHTRequest.codec, optional: true }, - 6: { name: 'connManager', codec: ConnManagerRequest.codec, optional: true }, - 7: { name: 'disconnect', codec: DisconnectRequest.codec, optional: true }, - 8: { name: 'pubsub', codec: PSRequest.codec, optional: true }, - 9: { name: 'peerStore', codec: PeerstoreRequest.codec, optional: true } - }) - - export const encode = (obj: Request): Uint8Array => { - return encodeMessage(obj, Request.codec) - } - - export const decode = (buf: Uint8Array): Request => { - return decodeMessage(buf, Request.codec) - } -} - -export interface Response { - type: Response.Type - error?: ErrorResponse - streamInfo?: StreamInfo - identify?: IdentifyResponse - dht?: DHTResponse - peers: PeerInfo[] - pubsub?: PSResponse - peerStore?: PeerstoreResponse -} - -export namespace Response { - export enum Type { - OK = 'OK', - ERROR = 'ERROR' - } - - export namespace Type { - export const codec = enumeration(Type) - } - - export const codec = message({ - 1: { name: 'type', codec: Response.Type.codec }, - 2: { name: 'error', codec: ErrorResponse.codec, optional: true }, - 3: { name: 'streamInfo', codec: StreamInfo.codec, optional: true }, - 4: { name: 'identify', codec: IdentifyResponse.codec, optional: true }, - 5: { name: 'dht', codec: DHTResponse.codec, optional: true }, - 6: { name: 'peers', codec: PeerInfo.codec, repeats: true }, - 7: { name: 'pubsub', codec: PSResponse.codec, optional: true }, - 8: { name: 'peerStore', codec: PeerstoreResponse.codec, optional: true } - }) - - export const encode = (obj: Response): Uint8Array => { - return encodeMessage(obj, Response.codec) - } - - export const decode = (buf: Uint8Array): Response => { - return decodeMessage(buf, Response.codec) + return decodeMessage(buf, PeerstoreResponse.codec()) } }