1
1
/* eslint-disable import/export */
2
2
/* eslint-disable @typescript-eslint/no-namespace */
3
3
4
- import { encodeMessage , decodeMessage , message , bytes } from 'protons-runtime'
5
- import type { Codec } from 'protons-runtime'
4
+ import { encodeMessage , decodeMessage , message } from 'protons-runtime'
6
5
import type { Uint8ArrayList } from 'uint8arraylist'
6
+ import type { Codec } from 'protons-runtime'
7
7
8
8
export namespace pb {
9
9
export interface NoiseHandshakePayload {
@@ -13,15 +13,87 @@ export namespace pb {
13
13
}
14
14
15
15
export namespace NoiseHandshakePayload {
16
+ let _codec : Codec < NoiseHandshakePayload >
17
+
16
18
export const codec = ( ) : Codec < NoiseHandshakePayload > => {
17
- return message < NoiseHandshakePayload > ( {
18
- 1 : { name : 'identityKey' , codec : bytes } ,
19
- 2 : { name : 'identitySig' , codec : bytes } ,
20
- 3 : { name : 'data' , codec : bytes }
21
- } )
19
+ if ( _codec == null ) {
20
+ _codec = message < NoiseHandshakePayload > ( ( obj , writer , opts = { } ) => {
21
+ if ( opts . lengthDelimited !== false ) {
22
+ writer . fork ( )
23
+ }
24
+
25
+ if ( obj . identityKey != null ) {
26
+ writer . uint32 ( 10 )
27
+ writer . bytes ( obj . identityKey )
28
+ } else {
29
+ throw new Error ( 'Protocol error: required field "identityKey" was not found in object' )
30
+ }
31
+
32
+ if ( obj . identitySig != null ) {
33
+ writer . uint32 ( 18 )
34
+ writer . bytes ( obj . identitySig )
35
+ } else {
36
+ throw new Error ( 'Protocol error: required field "identitySig" was not found in object' )
37
+ }
38
+
39
+ if ( obj . data != null ) {
40
+ writer . uint32 ( 26 )
41
+ writer . bytes ( obj . data )
42
+ } else {
43
+ throw new Error ( 'Protocol error: required field "data" was not found in object' )
44
+ }
45
+
46
+ if ( opts . lengthDelimited !== false ) {
47
+ writer . ldelim ( )
48
+ }
49
+ } , ( reader , length ) => {
50
+ const obj : any = {
51
+ identityKey : new Uint8Array ( 0 ) ,
52
+ identitySig : new Uint8Array ( 0 ) ,
53
+ data : new Uint8Array ( 0 )
54
+ }
55
+
56
+ const end = length == null ? reader . len : reader . pos + length
57
+
58
+ while ( reader . pos < end ) {
59
+ const tag = reader . uint32 ( )
60
+
61
+ switch ( tag >>> 3 ) {
62
+ case 1 :
63
+ obj . identityKey = reader . bytes ( )
64
+ break
65
+ case 2 :
66
+ obj . identitySig = reader . bytes ( )
67
+ break
68
+ case 3 :
69
+ obj . data = reader . bytes ( )
70
+ break
71
+ default :
72
+ reader . skipType ( tag & 7 )
73
+ break
74
+ }
75
+ }
76
+
77
+ if ( obj . identityKey == null ) {
78
+ throw new Error ( 'Protocol error: value for required field "identityKey" was not found in protobuf' )
79
+ }
80
+
81
+ if ( obj . identitySig == null ) {
82
+ throw new Error ( 'Protocol error: value for required field "identitySig" was not found in protobuf' )
83
+ }
84
+
85
+ if ( obj . data == null ) {
86
+ throw new Error ( 'Protocol error: value for required field "data" was not found in protobuf' )
87
+ }
88
+
89
+ return obj
90
+ } )
91
+ }
92
+
93
+ return _codec
22
94
}
23
95
24
- export const encode = ( obj : NoiseHandshakePayload ) : Uint8ArrayList => {
96
+ export const encode = ( obj : NoiseHandshakePayload ) : Uint8Array => {
25
97
return encodeMessage ( obj , NoiseHandshakePayload . codec ( ) )
26
98
}
27
99
0 commit comments