2
2
/* eslint-disable complexity */
3
3
/* eslint-disable @typescript-eslint/no-namespace */
4
4
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
5
+ /* eslint-disable @typescript-eslint/no-empty-interface */
5
6
6
7
import { encodeMessage , decodeMessage , message } from 'protons-runtime'
7
- import type { Uint8ArrayList } from 'uint8arraylist'
8
8
import type { Codec } from 'protons-runtime'
9
+ import type { Uint8ArrayList } from 'uint8arraylist'
9
10
10
11
export interface PeerRecord {
11
12
peerId : Uint8Array
@@ -28,7 +29,7 @@ export namespace PeerRecord {
28
29
w . fork ( )
29
30
}
30
31
31
- if ( opts . writeDefaults === true || ( obj . multiaddr != null && obj . multiaddr . byteLength > 0 ) ) {
32
+ if ( ( obj . multiaddr != null && obj . multiaddr . byteLength > 0 ) ) {
32
33
w . uint32 ( 10 )
33
34
w . bytes ( obj . multiaddr )
34
35
}
@@ -63,7 +64,7 @@ export namespace PeerRecord {
63
64
return _codec
64
65
}
65
66
66
- export const encode = ( obj : AddressInfo ) : Uint8Array => {
67
+ export const encode = ( obj : Partial < AddressInfo > ) : Uint8Array => {
67
68
return encodeMessage ( obj , AddressInfo . codec ( ) )
68
69
}
69
70
@@ -81,22 +82,20 @@ export namespace PeerRecord {
81
82
w . fork ( )
82
83
}
83
84
84
- if ( opts . writeDefaults === true || ( obj . peerId != null && obj . peerId . byteLength > 0 ) ) {
85
+ if ( ( obj . peerId != null && obj . peerId . byteLength > 0 ) ) {
85
86
w . uint32 ( 10 )
86
87
w . bytes ( obj . peerId )
87
88
}
88
89
89
- if ( opts . writeDefaults === true || obj . seq !== 0n ) {
90
+ if ( ( obj . seq != null && obj . seq !== 0n ) ) {
90
91
w . uint32 ( 16 )
91
92
w . uint64 ( obj . seq )
92
93
}
93
94
94
95
if ( obj . addresses != null ) {
95
96
for ( const value of obj . addresses ) {
96
97
w . uint32 ( 26 )
97
- PeerRecord . AddressInfo . codec ( ) . encode ( value , w , {
98
- writeDefaults : true
99
- } )
98
+ PeerRecord . AddressInfo . codec ( ) . encode ( value , w )
100
99
}
101
100
}
102
101
@@ -138,7 +137,7 @@ export namespace PeerRecord {
138
137
return _codec
139
138
}
140
139
141
- export const encode = ( obj : PeerRecord ) : Uint8Array => {
140
+ export const encode = ( obj : Partial < PeerRecord > ) : Uint8Array => {
142
141
return encodeMessage ( obj , PeerRecord . codec ( ) )
143
142
}
144
143
0 commit comments