1
- import { PackMe , PackMeMessage } from 'packme' ;
1
+ import { PackMe , PackMeMessage } from '../../lib/ packme.mjs ' ;
2
2
3
3
/** @enum {number} */
4
4
const TypeEnum = {
@@ -51,11 +51,15 @@ class NestedObject extends PackMeMessage {
51
51
}
52
52
53
53
class TestMessage extends PackMeMessage {
54
+ /** @type {!Uint8Array } */ reqId ;
55
+ /** @type {!Uint8Array[] } */ reqIds ;
54
56
/** @type {!number } */ reqInt8 ;
55
57
/** @type {!number } */ reqUint16 ;
56
58
/** @type {!number } */ reqDouble ;
57
59
/** @type {!boolean } */ reqBool ;
58
60
/** @type {!string } */ reqString ;
61
+ /** @type {?Uint8Array } */ optId ;
62
+ /** @type {?Uint8Array[] } */ optIds ;
59
63
/** @type {?number } */ optInt8 ;
60
64
/** @type {?number } */ optUint16 ;
61
65
/** @type {?number } */ optDouble ;
@@ -69,11 +73,15 @@ class TestMessage extends PackMeMessage {
69
73
/** @type {?NestedObject } */ optNested ;
70
74
71
75
constructor (
76
+ /** !Uint8Array */ reqId ,
77
+ /** !Uint8Array[] */ reqIds ,
72
78
/** !number */ reqInt8 ,
73
79
/** !number */ reqUint16 ,
74
80
/** !number */ reqDouble ,
75
81
/** !boolean */ reqBool ,
76
82
/** !string */ reqString ,
83
+ /** ?Uint8Array */ optId ,
84
+ /** ?Uint8Array[] */ optIds ,
77
85
/** ?number */ optInt8 ,
78
86
/** ?number */ optUint16 ,
79
87
/** ?number */ optDouble ,
@@ -88,6 +96,8 @@ class TestMessage extends PackMeMessage {
88
96
) {
89
97
super ( ) ;
90
98
if ( arguments . length > 0 ) {
99
+ this . $check ( 'reqId' , reqId ) ;
100
+ this . $check ( 'reqIds' , reqIds ) ;
91
101
this . $check ( 'reqInt8' , reqInt8 ) ;
92
102
this . $check ( 'reqUint16' , reqUint16 ) ;
93
103
this . $check ( 'reqDouble' , reqDouble ) ;
@@ -97,11 +107,15 @@ class TestMessage extends PackMeMessage {
97
107
this . $check ( 'reqEnum' , reqEnum ) ;
98
108
this . $check ( 'reqNested' , reqNested ) ;
99
109
}
110
+ this . reqId = reqId ;
111
+ this . reqIds = reqIds ;
100
112
this . reqInt8 = reqInt8 ;
101
113
this . reqUint16 = reqUint16 ;
102
114
this . reqDouble = reqDouble ;
103
115
this . reqBool = reqBool ;
104
116
this . reqString = reqString ;
117
+ this . optId = optId ;
118
+ this . optIds = optIds ;
105
119
this . optInt8 = optInt8 ;
106
120
this . optUint16 = optUint16 ;
107
121
this . optDouble = optDouble ;
@@ -118,8 +132,19 @@ class TestMessage extends PackMeMessage {
118
132
/** @return {number } */
119
133
$estimate ( ) {
120
134
this . $reset ( ) ;
121
- let bytes = 22 ;
135
+ let bytes = 35 ;
136
+ bytes += 4 ;
137
+ bytes += 4 * this . reqIds . length ;
122
138
bytes += this . $stringBytes ( this . reqString ) ;
139
+ this . $setFlag ( this . optId != null ) ;
140
+ if ( this . optId != null ) {
141
+ bytes += 12 ;
142
+ }
143
+ this . $setFlag ( this . optIds != null ) ;
144
+ if ( this . optIds != null ) {
145
+ bytes += 4 ;
146
+ bytes += 4 * this . optIds . length ;
147
+ }
123
148
this . $setFlag ( this . optInt8 != null ) ;
124
149
if ( this . optInt8 != null ) {
125
150
bytes += 1 ;
@@ -162,12 +187,20 @@ class TestMessage extends PackMeMessage {
162
187
/** @return {undefined } */
163
188
$pack ( ) {
164
189
this . $initPack ( 475203406 ) ;
165
- for ( let i = 0 ; i < 1 ; i ++ ) this . $packUint8 ( this . $flags [ i ] ) ;
190
+ for ( let i = 0 ; i < 2 ; i ++ ) this . $packUint8 ( this . $flags [ i ] ) ;
191
+ this . $packBinary ( this . reqId , 12 ) ;
192
+ this . $packUint32 ( this . reqIds . length ) ;
193
+ for ( let item of this . reqIds ) this . $packBinary ( item , 4 ) ;
166
194
this . $packInt8 ( this . reqInt8 ) ;
167
195
this . $packUint16 ( this . reqUint16 ) ;
168
196
this . $packDouble ( this . reqDouble ) ;
169
197
this . $packBool ( this . reqBool ) ;
170
198
this . $packString ( this . reqString ) ;
199
+ if ( this . optId != null ) this . $packBinary ( this . optId , 12 ) ;
200
+ if ( this . optIds != null ) {
201
+ this . $packUint32 ( this . optIds . length ) ;
202
+ for ( let item of this . optIds ) this . $packBinary ( item , 4 ) ;
203
+ }
171
204
if ( this . optInt8 != null ) this . $packInt8 ( this . optInt8 ) ;
172
205
if ( this . optUint16 != null ) this . $packUint16 ( this . optUint16 ) ;
173
206
if ( this . optDouble != null ) this . $packDouble ( this . optDouble ) ;
@@ -188,12 +221,28 @@ class TestMessage extends PackMeMessage {
188
221
/** @return {undefined } */
189
222
$unpack ( ) {
190
223
this . $initUnpack ( ) ;
191
- for ( let i = 0 ; i < 1 ; i ++ ) this . $flags . push ( this . $unpackUint8 ( ) ) ;
224
+ for ( let i = 0 ; i < 2 ; i ++ ) this . $flags . push ( this . $unpackUint8 ( ) ) ;
225
+ this . reqId = this . $unpackBinary ( 12 ) ;
226
+ this . reqIds = [ ] ;
227
+ let reqIdsLength = this . $unpackUint32 ( ) ;
228
+ for ( let i = 0 ; i < reqIdsLength ; i ++ ) {
229
+ this . reqIds . push ( this . $unpackBinary ( 4 ) ) ;
230
+ }
192
231
this . reqInt8 = this . $unpackInt8 ( ) ;
193
232
this . reqUint16 = this . $unpackUint16 ( ) ;
194
233
this . reqDouble = this . $unpackDouble ( ) ;
195
234
this . reqBool = this . $unpackBool ( ) ;
196
235
this . reqString = this . $unpackString ( ) ;
236
+ if ( this . $getFlag ( ) ) {
237
+ this . optId = this . $unpackBinary ( 12 ) ;
238
+ }
239
+ if ( this . $getFlag ( ) ) {
240
+ this . optIds = [ ] ;
241
+ let optIdsLength = this . $unpackUint32 ( ) ;
242
+ for ( let i = 0 ; i < optIdsLength ; i ++ ) {
243
+ this . optIds . push ( this . $unpackBinary ( 4 ) ) ;
244
+ }
245
+ }
197
246
if ( this . $getFlag ( ) ) {
198
247
this . optInt8 = this . $unpackInt8 ( ) ;
199
248
}
@@ -233,7 +282,7 @@ class TestMessage extends PackMeMessage {
233
282
234
283
/** @return {string } */
235
284
toString ( ) {
236
- return `TestMessage\x1b[0m(reqInt8: ${ PackMe . dye ( this . reqInt8 ) } , reqUint16: ${ PackMe . dye ( this . reqUint16 ) } , reqDouble: ${ PackMe . dye ( this . reqDouble ) } , reqBool: ${ PackMe . dye ( this . reqBool ) } , reqString: ${ PackMe . dye ( this . reqString ) } , optInt8: ${ PackMe . dye ( this . optInt8 ) } , optUint16: ${ PackMe . dye ( this . optUint16 ) } , optDouble: ${ PackMe . dye ( this . optDouble ) } , optBool: ${ PackMe . dye ( this . optBool ) } , optString: ${ PackMe . dye ( this . optString ) } , reqList: ${ PackMe . dye ( this . reqList ) } , optList: ${ PackMe . dye ( this . optList ) } , reqEnum: ${ PackMe . dye ( this . reqEnum ) } , optEnum: ${ PackMe . dye ( this . optEnum ) } , reqNested: ${ PackMe . dye ( this . reqNested ) } , optNested: ${ PackMe . dye ( this . optNested ) } )` ;
285
+ return `TestMessage\x1b[0m(reqId: ${ PackMe . dye ( this . reqId ) } , reqIds: ${ PackMe . dye ( this . reqIds ) } , reqInt8: ${ PackMe . dye ( this . reqInt8 ) } , reqUint16: ${ PackMe . dye ( this . reqUint16 ) } , reqDouble: ${ PackMe . dye ( this . reqDouble ) } , reqBool: ${ PackMe . dye ( this . reqBool ) } , reqString: ${ PackMe . dye ( this . reqString ) } , optId: ${ PackMe . dye ( this . optId ) } , optIds: ${ PackMe . dye ( this . optIds ) } , optInt8: ${ PackMe . dye ( this . optInt8 ) } , optUint16: ${ PackMe . dye ( this . optUint16 ) } , optDouble: ${ PackMe . dye ( this . optDouble ) } , optBool: ${ PackMe . dye ( this . optBool ) } , optString: ${ PackMe . dye ( this . optString ) } , reqList: ${ PackMe . dye ( this . reqList ) } , optList: ${ PackMe . dye ( this . optList ) } , reqEnum: ${ PackMe . dye ( this . reqEnum ) } , optEnum: ${ PackMe . dye ( this . optEnum ) } , reqNested: ${ PackMe . dye ( this . reqNested ) } , optNested: ${ PackMe . dye ( this . optNested ) } )` ;
237
286
}
238
287
}
239
288
0 commit comments