@layerzerolabs/lz-serdes 2.3.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,276 @@
1
+ type Seq<T> = T[];
2
+ type Uint8 = number;
3
+ type Uint16 = number;
4
+ type Uint32 = number;
5
+ type Uint64 = bigint;
6
+ type Uint128 = bigint;
7
+ type Uint256 = bigint;
8
+ type AnyNumber = bigint | number;
9
+ type Bytes = Uint8Array;
10
+
11
+ declare class Serializer {
12
+ private buffer;
13
+ private offset;
14
+ private littleEndian;
15
+ constructor(littleEndian?: boolean);
16
+ private ensureBufferWillHandleSize;
17
+ protected serialize(values: Bytes): void;
18
+ private serializeWithFunction;
19
+ /**
20
+ * Serializes a string. UTF8 string is supported. Serializes the string's bytes length "l" first,
21
+ * and then serializes "l" bytes of the string content.
22
+ *
23
+ * layout for "string": string_length | string_content. string_length is the bytes length of
24
+ * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const serializer = new Serializer();
29
+ * serializer.serializeStr("çå∞≠¢õß∂ƒ∫");
30
+ * assert(serializer.getBytes() === new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,
31
+ * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]));
32
+ * ```
33
+ */
34
+ serializeStr(value: string): void;
35
+ /**
36
+ * Serializes an array of bytes.
37
+ *
38
+ * layout for "bytes": bytes_length | bytes. bytes_length is the length of the bytes array that is
39
+ * uleb128/ubeb128 encoded. bytes_length is a u32 integer.
40
+ */
41
+ serializeBytes(value: Bytes): void;
42
+ /**
43
+ * Serializes an array of bytes with known length. Therefore length doesn't need to be
44
+ * serialized to help deserialization. When deserializing, the number of
45
+ * bytes to deserialize needs to be passed in.
46
+ */
47
+ serializeFixedBytes(value: Bytes): void;
48
+ /**
49
+ * Serializes a boolean value.
50
+ *
51
+ * layout for "boolean": One byte. "0x01" for True and "0x00" for False.
52
+ */
53
+ serializeBool(value: boolean): void;
54
+ /**
55
+ * Serializes a uint8 number.
56
+ *
57
+ * layout for "uint8": One byte. Binary format in little-endian representation.
58
+ */
59
+ serializeU8(value: Uint8): void;
60
+ /**
61
+ * Serializes a uint16 number.
62
+ *
63
+ * layout for "uint16": Two bytes. Binary format in little-endian representation.
64
+ * @example
65
+ * ```ts
66
+ * const serializer = new Serializer(true);
67
+ * serializer.serializeU16(4660);
68
+ * assert(serializer.getBytes() === new Uint8Array([0x34, 0x12]));
69
+ * const serializer = new Serializer(false);
70
+ * serializer.serializeU16(4660);
71
+ * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34]));
72
+ * ```
73
+ */
74
+ serializeU16(value: Uint16): void;
75
+ /**
76
+ * Serializes a uint32 number.
77
+ *
78
+ * layout for "uint32": Four bytes. Binary format in little-endian representation.
79
+ * @example
80
+ * ```ts
81
+ * const serializer = new Serializer(true);
82
+ * serializer.serializeU32(305419896);
83
+ * assert(serializer.getBytes() === new Uint8Array([0x78, 0x56, 0x34, 0x12]));
84
+ * const serializer = new Serializer(false);
85
+ * serializer.serializeU32(305419896);
86
+ * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78]));
87
+ * ```
88
+ */
89
+ serializeU32(value: Uint32): void;
90
+ /**
91
+ * Serializes a uint64 number.
92
+ *
93
+ * layout for "uint64": Eight bytes. Binary format in little-endian representation.
94
+ * @example
95
+ * ```ts
96
+ * const serializer = new Serializer(true);
97
+ * serializer.serializeU64(1311768467750121216);
98
+ * assert(serializer.getBytes() === new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));
99
+ * const serializer = new Serializer(false);
100
+ * serializer.serializeU64(1311768467750121216);
101
+ * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]));
102
+ * ```
103
+ */
104
+ serializeU64(value: AnyNumber): void;
105
+ /**
106
+ * Serializes a uint128 number.
107
+ *
108
+ * layout for "uint128": Sixteen bytes. Binary format in little-endian representation.
109
+ */
110
+ serializeU128(value: AnyNumber): void;
111
+ /**
112
+ * Serializes a uint256 number.
113
+ *
114
+ * layout for "uint256": Sixteen bytes. Binary format in little-endian representation.
115
+ */
116
+ serializeU256(value: AnyNumber): void;
117
+ /**
118
+ * Serializes a uint32 number with uleb128.
119
+ *
120
+ * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values
121
+ */
122
+ serializeU32AsUleb128(val: Uint32): void;
123
+ /**
124
+ * Serializes a uint32 number with unsigned Variable-Length Big-Endian Encoding.
125
+ *
126
+ * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values
127
+ */
128
+ serializeU32AsUbeb128(val: Uint32): void;
129
+ /**
130
+ * Returns the buffered bytes
131
+ */
132
+ getBytes(): Bytes;
133
+ }
134
+
135
+ declare class Deserializer {
136
+ private buffer;
137
+ private offset;
138
+ private littleEndian;
139
+ constructor(data: Bytes, littleEndian?: boolean);
140
+ private read;
141
+ /**
142
+ * Deserializes a string. UTF8 string is supported. Reads the string's bytes length "l" first,
143
+ * and then reads "l" bytes of content. Decodes the byte array into a string.
144
+ *
145
+ * layout for "string": string_length | string_content. string_length is the bytes length of
146
+ * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * const deserializer = new Deserializer(new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,
151
+ * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]), true);
152
+ * assert(deserializer.deserializeStr() === "çå∞≠¢õß∂ƒ∫");
153
+ * ```
154
+ */
155
+ deserializeStr(): string;
156
+ /**
157
+ * Deserializes an array of bytes.
158
+ *
159
+ * layout for "bytes": bytes_length | bytes. bytes_length is the length of the bytes array that is
160
+ * uleb128/ubeb128 encoded. bytes_length is a u32 integer.
161
+ */
162
+ deserializeBytes(): Bytes;
163
+ /**
164
+ * Deserializes an array of bytes. The number of bytes to read is already known.
165
+ *
166
+ */
167
+ deserializeFixedBytes(len: number): Bytes;
168
+ /**
169
+ * Deserializes a boolean value.
170
+ *
171
+ * layout for "boolean": One byte. "0x01" for True and "0x00" for False.
172
+ */
173
+ deserializeBool(): boolean;
174
+ /**
175
+ * Deserializes a uint8 number.
176
+ *
177
+ * layout for "uint8": One byte. Binary format in little-endian representation.
178
+ */
179
+ deserializeU8(): Uint8;
180
+ /**
181
+ * Deserializes a uint16 number.
182
+ *
183
+ * layout for "uint16": Two bytes. Binary format in little-endian representation.
184
+ * @example
185
+ * ```ts
186
+ * const deserializer = new Deserializer(new Uint8Array([0x34, 0x12]), true);
187
+ * assert(deserializer.deserializeU16() === 4660);
188
+ * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34]), false);
189
+ * assert(deserializer.deserializeU16() === 4660);
190
+ * ```
191
+ */
192
+ deserializeU16(): Uint16;
193
+ /**
194
+ * Deserializes a uint32 number.
195
+ *
196
+ * layout for "uint32": Four bytes. Binary format in little-endian representation.
197
+ * @example
198
+ * ```ts
199
+ * const deserializer = new Deserializer(new Uint8Array([0x78, 0x56, 0x34, 0x12]), true);
200
+ * assert(deserializer.deserializeU32() === 305419896);
201
+ * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78]), false);
202
+ * assert(deserializer.deserializeU32() === 305419896);
203
+ * ```
204
+ */
205
+ deserializeU32(): Uint32;
206
+ /**
207
+ * Deserializes a uint64 number.
208
+ *
209
+ * layout for "uint64": Eight bytes. Binary format in little-endian representation.
210
+ * @example
211
+ * ```ts
212
+ * const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]), true);
213
+ * assert(deserializer.deserializeU64() === 1311768467750121216);
214
+ * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]), false);
215
+ * assert(deserializer.deserializeU64() === 1311768467750121216);
216
+ * ```
217
+ */
218
+ deserializeU64(): Uint64;
219
+ /**
220
+ * Deserializes a uint128 number.
221
+ *
222
+ * layout for "uint128": Sixteen bytes. Binary format in little-endian representation.
223
+ */
224
+ deserializeU128(): Uint128;
225
+ /**
226
+ * Deserializes a uint256 number.
227
+ *
228
+ * layout for "uint256": Thirty-two bytes. Binary format in little-endian representation.
229
+ */
230
+ deserializeU256(): Uint256;
231
+ /**
232
+ * Deserializes a uleb128 encoded uint32 number.
233
+ *
234
+ * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values
235
+ */
236
+ deserializeUleb128AsU32(): Uint32;
237
+ /**
238
+ * Deserializes a unsigned Variable-Length Big-Endian Encoding encoded uint32 number.
239
+ *
240
+ * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values
241
+ */
242
+ deserializeUbeb128AsU32(): Uint32;
243
+ }
244
+
245
+ interface Serializable {
246
+ serialize(serializer: Serializer): void;
247
+ }
248
+ interface Deserializable<T> {
249
+ deserialize(deserializer: Deserializer): T;
250
+ }
251
+ /**
252
+ * Serializes a vector values that are "Serializable".
253
+ */
254
+ declare function serializeVector<T extends Serializable>(value: Seq<T>, serializer: Serializer): void;
255
+ /**
256
+ * Serializes a vector with specified item serialization function.
257
+ * Very dynamic function and bypasses static typechecking.
258
+ */
259
+ declare function serializeVectorWithFunc(value: unknown[], func: string): Bytes;
260
+ /**
261
+ * Deserializes a vector of values.
262
+ */
263
+ declare function deserializeVector<T>(deserializer: Deserializer, cls: Deserializable<T>): any[];
264
+ declare function bcsToBytes<T extends Serializable>(value: T): Bytes;
265
+ declare function bcsSerializeUint64(value: AnyNumber): Bytes;
266
+ declare function bcsSerializeU8(value: Uint8): Bytes;
267
+ declare function bcsSerializeU16(value: Uint16): Bytes;
268
+ declare function bcsSerializeU32(value: Uint32): Bytes;
269
+ declare function bcsSerializeU128(value: AnyNumber): Bytes;
270
+ declare function bcsSerializeU256(value: AnyNumber): Bytes;
271
+ declare function bcsSerializeBool(value: boolean): Bytes;
272
+ declare function bcsSerializeStr(value: string): Bytes;
273
+ declare function bcsSerializeBytes(value: Bytes): Bytes;
274
+ declare function bcsSerializeFixedBytes(value: Bytes): Bytes;
275
+
276
+ export { type AnyNumber, type Bytes, Deserializer, type Seq, Serializer, type Uint128, type Uint16, type Uint256, type Uint32, type Uint64, type Uint8, bcsSerializeBool, bcsSerializeBytes, bcsSerializeFixedBytes, bcsSerializeStr, bcsSerializeU128, bcsSerializeU16, bcsSerializeU256, bcsSerializeU32, bcsSerializeU8, bcsSerializeUint64, bcsToBytes, deserializeVector, serializeVector, serializeVectorWithFunc };
@@ -0,0 +1,276 @@
1
+ type Seq<T> = T[];
2
+ type Uint8 = number;
3
+ type Uint16 = number;
4
+ type Uint32 = number;
5
+ type Uint64 = bigint;
6
+ type Uint128 = bigint;
7
+ type Uint256 = bigint;
8
+ type AnyNumber = bigint | number;
9
+ type Bytes = Uint8Array;
10
+
11
+ declare class Serializer {
12
+ private buffer;
13
+ private offset;
14
+ private littleEndian;
15
+ constructor(littleEndian?: boolean);
16
+ private ensureBufferWillHandleSize;
17
+ protected serialize(values: Bytes): void;
18
+ private serializeWithFunction;
19
+ /**
20
+ * Serializes a string. UTF8 string is supported. Serializes the string's bytes length "l" first,
21
+ * and then serializes "l" bytes of the string content.
22
+ *
23
+ * layout for "string": string_length | string_content. string_length is the bytes length of
24
+ * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const serializer = new Serializer();
29
+ * serializer.serializeStr("çå∞≠¢õß∂ƒ∫");
30
+ * assert(serializer.getBytes() === new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,
31
+ * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]));
32
+ * ```
33
+ */
34
+ serializeStr(value: string): void;
35
+ /**
36
+ * Serializes an array of bytes.
37
+ *
38
+ * layout for "bytes": bytes_length | bytes. bytes_length is the length of the bytes array that is
39
+ * uleb128/ubeb128 encoded. bytes_length is a u32 integer.
40
+ */
41
+ serializeBytes(value: Bytes): void;
42
+ /**
43
+ * Serializes an array of bytes with known length. Therefore length doesn't need to be
44
+ * serialized to help deserialization. When deserializing, the number of
45
+ * bytes to deserialize needs to be passed in.
46
+ */
47
+ serializeFixedBytes(value: Bytes): void;
48
+ /**
49
+ * Serializes a boolean value.
50
+ *
51
+ * layout for "boolean": One byte. "0x01" for True and "0x00" for False.
52
+ */
53
+ serializeBool(value: boolean): void;
54
+ /**
55
+ * Serializes a uint8 number.
56
+ *
57
+ * layout for "uint8": One byte. Binary format in little-endian representation.
58
+ */
59
+ serializeU8(value: Uint8): void;
60
+ /**
61
+ * Serializes a uint16 number.
62
+ *
63
+ * layout for "uint16": Two bytes. Binary format in little-endian representation.
64
+ * @example
65
+ * ```ts
66
+ * const serializer = new Serializer(true);
67
+ * serializer.serializeU16(4660);
68
+ * assert(serializer.getBytes() === new Uint8Array([0x34, 0x12]));
69
+ * const serializer = new Serializer(false);
70
+ * serializer.serializeU16(4660);
71
+ * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34]));
72
+ * ```
73
+ */
74
+ serializeU16(value: Uint16): void;
75
+ /**
76
+ * Serializes a uint32 number.
77
+ *
78
+ * layout for "uint32": Four bytes. Binary format in little-endian representation.
79
+ * @example
80
+ * ```ts
81
+ * const serializer = new Serializer(true);
82
+ * serializer.serializeU32(305419896);
83
+ * assert(serializer.getBytes() === new Uint8Array([0x78, 0x56, 0x34, 0x12]));
84
+ * const serializer = new Serializer(false);
85
+ * serializer.serializeU32(305419896);
86
+ * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78]));
87
+ * ```
88
+ */
89
+ serializeU32(value: Uint32): void;
90
+ /**
91
+ * Serializes a uint64 number.
92
+ *
93
+ * layout for "uint64": Eight bytes. Binary format in little-endian representation.
94
+ * @example
95
+ * ```ts
96
+ * const serializer = new Serializer(true);
97
+ * serializer.serializeU64(1311768467750121216);
98
+ * assert(serializer.getBytes() === new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));
99
+ * const serializer = new Serializer(false);
100
+ * serializer.serializeU64(1311768467750121216);
101
+ * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]));
102
+ * ```
103
+ */
104
+ serializeU64(value: AnyNumber): void;
105
+ /**
106
+ * Serializes a uint128 number.
107
+ *
108
+ * layout for "uint128": Sixteen bytes. Binary format in little-endian representation.
109
+ */
110
+ serializeU128(value: AnyNumber): void;
111
+ /**
112
+ * Serializes a uint256 number.
113
+ *
114
+ * layout for "uint256": Sixteen bytes. Binary format in little-endian representation.
115
+ */
116
+ serializeU256(value: AnyNumber): void;
117
+ /**
118
+ * Serializes a uint32 number with uleb128.
119
+ *
120
+ * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values
121
+ */
122
+ serializeU32AsUleb128(val: Uint32): void;
123
+ /**
124
+ * Serializes a uint32 number with unsigned Variable-Length Big-Endian Encoding.
125
+ *
126
+ * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values
127
+ */
128
+ serializeU32AsUbeb128(val: Uint32): void;
129
+ /**
130
+ * Returns the buffered bytes
131
+ */
132
+ getBytes(): Bytes;
133
+ }
134
+
135
+ declare class Deserializer {
136
+ private buffer;
137
+ private offset;
138
+ private littleEndian;
139
+ constructor(data: Bytes, littleEndian?: boolean);
140
+ private read;
141
+ /**
142
+ * Deserializes a string. UTF8 string is supported. Reads the string's bytes length "l" first,
143
+ * and then reads "l" bytes of content. Decodes the byte array into a string.
144
+ *
145
+ * layout for "string": string_length | string_content. string_length is the bytes length of
146
+ * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * const deserializer = new Deserializer(new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,
151
+ * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]), true);
152
+ * assert(deserializer.deserializeStr() === "çå∞≠¢õß∂ƒ∫");
153
+ * ```
154
+ */
155
+ deserializeStr(): string;
156
+ /**
157
+ * Deserializes an array of bytes.
158
+ *
159
+ * layout for "bytes": bytes_length | bytes. bytes_length is the length of the bytes array that is
160
+ * uleb128/ubeb128 encoded. bytes_length is a u32 integer.
161
+ */
162
+ deserializeBytes(): Bytes;
163
+ /**
164
+ * Deserializes an array of bytes. The number of bytes to read is already known.
165
+ *
166
+ */
167
+ deserializeFixedBytes(len: number): Bytes;
168
+ /**
169
+ * Deserializes a boolean value.
170
+ *
171
+ * layout for "boolean": One byte. "0x01" for True and "0x00" for False.
172
+ */
173
+ deserializeBool(): boolean;
174
+ /**
175
+ * Deserializes a uint8 number.
176
+ *
177
+ * layout for "uint8": One byte. Binary format in little-endian representation.
178
+ */
179
+ deserializeU8(): Uint8;
180
+ /**
181
+ * Deserializes a uint16 number.
182
+ *
183
+ * layout for "uint16": Two bytes. Binary format in little-endian representation.
184
+ * @example
185
+ * ```ts
186
+ * const deserializer = new Deserializer(new Uint8Array([0x34, 0x12]), true);
187
+ * assert(deserializer.deserializeU16() === 4660);
188
+ * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34]), false);
189
+ * assert(deserializer.deserializeU16() === 4660);
190
+ * ```
191
+ */
192
+ deserializeU16(): Uint16;
193
+ /**
194
+ * Deserializes a uint32 number.
195
+ *
196
+ * layout for "uint32": Four bytes. Binary format in little-endian representation.
197
+ * @example
198
+ * ```ts
199
+ * const deserializer = new Deserializer(new Uint8Array([0x78, 0x56, 0x34, 0x12]), true);
200
+ * assert(deserializer.deserializeU32() === 305419896);
201
+ * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78]), false);
202
+ * assert(deserializer.deserializeU32() === 305419896);
203
+ * ```
204
+ */
205
+ deserializeU32(): Uint32;
206
+ /**
207
+ * Deserializes a uint64 number.
208
+ *
209
+ * layout for "uint64": Eight bytes. Binary format in little-endian representation.
210
+ * @example
211
+ * ```ts
212
+ * const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]), true);
213
+ * assert(deserializer.deserializeU64() === 1311768467750121216);
214
+ * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]), false);
215
+ * assert(deserializer.deserializeU64() === 1311768467750121216);
216
+ * ```
217
+ */
218
+ deserializeU64(): Uint64;
219
+ /**
220
+ * Deserializes a uint128 number.
221
+ *
222
+ * layout for "uint128": Sixteen bytes. Binary format in little-endian representation.
223
+ */
224
+ deserializeU128(): Uint128;
225
+ /**
226
+ * Deserializes a uint256 number.
227
+ *
228
+ * layout for "uint256": Thirty-two bytes. Binary format in little-endian representation.
229
+ */
230
+ deserializeU256(): Uint256;
231
+ /**
232
+ * Deserializes a uleb128 encoded uint32 number.
233
+ *
234
+ * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values
235
+ */
236
+ deserializeUleb128AsU32(): Uint32;
237
+ /**
238
+ * Deserializes a unsigned Variable-Length Big-Endian Encoding encoded uint32 number.
239
+ *
240
+ * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values
241
+ */
242
+ deserializeUbeb128AsU32(): Uint32;
243
+ }
244
+
245
+ interface Serializable {
246
+ serialize(serializer: Serializer): void;
247
+ }
248
+ interface Deserializable<T> {
249
+ deserialize(deserializer: Deserializer): T;
250
+ }
251
+ /**
252
+ * Serializes a vector values that are "Serializable".
253
+ */
254
+ declare function serializeVector<T extends Serializable>(value: Seq<T>, serializer: Serializer): void;
255
+ /**
256
+ * Serializes a vector with specified item serialization function.
257
+ * Very dynamic function and bypasses static typechecking.
258
+ */
259
+ declare function serializeVectorWithFunc(value: unknown[], func: string): Bytes;
260
+ /**
261
+ * Deserializes a vector of values.
262
+ */
263
+ declare function deserializeVector<T>(deserializer: Deserializer, cls: Deserializable<T>): any[];
264
+ declare function bcsToBytes<T extends Serializable>(value: T): Bytes;
265
+ declare function bcsSerializeUint64(value: AnyNumber): Bytes;
266
+ declare function bcsSerializeU8(value: Uint8): Bytes;
267
+ declare function bcsSerializeU16(value: Uint16): Bytes;
268
+ declare function bcsSerializeU32(value: Uint32): Bytes;
269
+ declare function bcsSerializeU128(value: AnyNumber): Bytes;
270
+ declare function bcsSerializeU256(value: AnyNumber): Bytes;
271
+ declare function bcsSerializeBool(value: boolean): Bytes;
272
+ declare function bcsSerializeStr(value: string): Bytes;
273
+ declare function bcsSerializeBytes(value: Bytes): Bytes;
274
+ declare function bcsSerializeFixedBytes(value: Bytes): Bytes;
275
+
276
+ export { type AnyNumber, type Bytes, Deserializer, type Seq, Serializer, type Uint128, type Uint16, type Uint256, type Uint32, type Uint64, type Uint8, bcsSerializeBool, bcsSerializeBytes, bcsSerializeFixedBytes, bcsSerializeStr, bcsSerializeU128, bcsSerializeU16, bcsSerializeU256, bcsSerializeU32, bcsSerializeU8, bcsSerializeUint64, bcsToBytes, deserializeVector, serializeVector, serializeVectorWithFunc };