1
1
/* eslint-disable import/export */
2
2
/* eslint-disable @typescript-eslint/no-namespace */
3
3
4
- import { enumeration , encodeMessage , decodeMessage , message , bytes , uint64 } from 'protons-runtime'
4
+ import { enumeration , encodeMessage , decodeMessage , message } from 'protons-runtime'
5
+ import type { Uint8ArrayList } from 'uint8arraylist'
5
6
import type { Codec } from 'protons-runtime'
6
7
7
8
export interface IpnsEntry {
@@ -27,29 +28,121 @@ export namespace IpnsEntry {
27
28
28
29
export namespace ValidityType {
29
30
export const codec = ( ) => {
30
- return enumeration < typeof ValidityType > ( __ValidityTypeValues )
31
+ return enumeration < ValidityType > ( __ValidityTypeValues )
31
32
}
32
33
}
33
34
35
+ let _codec : Codec < IpnsEntry >
36
+
34
37
export const codec = ( ) : Codec < IpnsEntry > => {
35
- return message < IpnsEntry > ( {
36
- 1 : { name : 'value' , codec : bytes , optional : true } ,
37
- 2 : { name : 'signature' , codec : bytes , optional : true } ,
38
- 3 : { name : 'validityType' , codec : IpnsEntry . ValidityType . codec ( ) , optional : true } ,
39
- 4 : { name : 'validity' , codec : bytes , optional : true } ,
40
- 5 : { name : 'sequence' , codec : uint64 , optional : true } ,
41
- 6 : { name : 'ttl' , codec : uint64 , optional : true } ,
42
- 7 : { name : 'pubKey' , codec : bytes , optional : true } ,
43
- 8 : { name : 'signatureV2' , codec : bytes , optional : true } ,
44
- 9 : { name : 'data' , codec : bytes , optional : true }
45
- } )
38
+ if ( _codec == null ) {
39
+ _codec = message < IpnsEntry > ( ( obj , writer , opts = { } ) => {
40
+ if ( opts . lengthDelimited !== false ) {
41
+ writer . fork ( )
42
+ }
43
+
44
+ if ( obj . value != null ) {
45
+ writer . uint32 ( 10 )
46
+ writer . bytes ( obj . value )
47
+ }
48
+
49
+ if ( obj . signature != null ) {
50
+ writer . uint32 ( 18 )
51
+ writer . bytes ( obj . signature )
52
+ }
53
+
54
+ if ( obj . validityType != null ) {
55
+ writer . uint32 ( 24 )
56
+ IpnsEntry . ValidityType . codec ( ) . encode ( obj . validityType , writer )
57
+ }
58
+
59
+ if ( obj . validity != null ) {
60
+ writer . uint32 ( 34 )
61
+ writer . bytes ( obj . validity )
62
+ }
63
+
64
+ if ( obj . sequence != null ) {
65
+ writer . uint32 ( 40 )
66
+ writer . uint64 ( obj . sequence )
67
+ }
68
+
69
+ if ( obj . ttl != null ) {
70
+ writer . uint32 ( 48 )
71
+ writer . uint64 ( obj . ttl )
72
+ }
73
+
74
+ if ( obj . pubKey != null ) {
75
+ writer . uint32 ( 58 )
76
+ writer . bytes ( obj . pubKey )
77
+ }
78
+
79
+ if ( obj . signatureV2 != null ) {
80
+ writer . uint32 ( 66 )
81
+ writer . bytes ( obj . signatureV2 )
82
+ }
83
+
84
+ if ( obj . data != null ) {
85
+ writer . uint32 ( 74 )
86
+ writer . bytes ( obj . data )
87
+ }
88
+
89
+ if ( opts . lengthDelimited !== false ) {
90
+ writer . ldelim ( )
91
+ }
92
+ } , ( reader , length ) => {
93
+ const obj : any = { }
94
+
95
+ const end = length == null ? reader . len : reader . pos + length
96
+
97
+ while ( reader . pos < end ) {
98
+ const tag = reader . uint32 ( )
99
+
100
+ switch ( tag >>> 3 ) {
101
+ case 1 :
102
+ obj . value = reader . bytes ( )
103
+ break
104
+ case 2 :
105
+ obj . signature = reader . bytes ( )
106
+ break
107
+ case 3 :
108
+ obj . validityType = IpnsEntry . ValidityType . codec ( ) . decode ( reader )
109
+ break
110
+ case 4 :
111
+ obj . validity = reader . bytes ( )
112
+ break
113
+ case 5 :
114
+ obj . sequence = reader . uint64 ( )
115
+ break
116
+ case 6 :
117
+ obj . ttl = reader . uint64 ( )
118
+ break
119
+ case 7 :
120
+ obj . pubKey = reader . bytes ( )
121
+ break
122
+ case 8 :
123
+ obj . signatureV2 = reader . bytes ( )
124
+ break
125
+ case 9 :
126
+ obj . data = reader . bytes ( )
127
+ break
128
+ default :
129
+ reader . skipType ( tag & 7 )
130
+ break
131
+ }
132
+ }
133
+
134
+ return obj
135
+ } )
136
+ }
137
+
138
+ return _codec
46
139
}
47
140
48
141
export const encode = ( obj : IpnsEntry ) : Uint8Array => {
49
142
return encodeMessage ( obj , IpnsEntry . codec ( ) )
50
143
}
51
144
52
- export const decode = ( buf : Uint8Array ) : IpnsEntry => {
145
+ export const decode = ( buf : Uint8Array | Uint8ArrayList ) : IpnsEntry => {
53
146
return decodeMessage ( buf , IpnsEntry . codec ( ) )
54
147
}
55
148
}
0 commit comments