@@ -292,6 +292,154 @@ func TestEncodeDecodeCompactNullableArray(t *testing.T) {
292292 }
293293}
294294
295+ func TestEncodeDecodeInt32Array (t * testing.T ) {
296+ tt := []struct {
297+ name string
298+ values []int32
299+ }{
300+ {name : "nil array" , values : nil },
301+ {name : "empty array" , values : []int32 {}},
302+ {name : "0" , values : []int32 {0 }},
303+ {name : "0s" , values : []int32 {0 , 0 }},
304+ {name : "1" , values : []int32 {1 }},
305+ {name : "1s" , values : []int32 {1 , 1 }},
306+ {name : "2" , values : []int32 {2 }},
307+ {name : "3" , values : []int32 {3 }},
308+ {name : "4" , values : []int32 {4 }},
309+ {name : "16" , values : []int32 {16 }},
310+ {name : "63" , values : []int32 {63 }},
311+ {name : "64" , values : []int32 {64 }},
312+ {name : "128" , values : []int32 {128 }},
313+ {name : "8191" , values : []int32 {8191 }},
314+ {name : "8192" , values : []int32 {8192 }},
315+ {name : "32767" , values : []int32 {math .MaxInt16 }},
316+ {name : "32767,-32768" , values : []int32 {math .MaxInt16 , math .MinInt16 }},
317+ {name : "2147483647,-2147483648" , values : []int32 {math .MaxInt32 , math .MinInt32 }},
318+ {name : "different values" , values : []int32 {0 , 1 , 2 , 3 , 4 , - 1 , 16 , 64 , 127 , 128 , 8191 , 8192 , 8191 , 128 , 127 , - 1 , 64 , 16 , 4 , 3 , 2 , 1 , - 1 , 0 }},
319+ }
320+ for _ , tc := range tt {
321+ request := & Int32ArrayHolder {
322+ values : tc .values ,
323+ }
324+ buf , err := Encode (request )
325+ if err != nil {
326+ t .Fatal (err )
327+ }
328+ response := & Int32ArrayHolder {}
329+ err = Decode (buf , response )
330+ if err != nil {
331+ t .Fatal (err )
332+ }
333+ if (request .values == nil && response .values != nil ) || (request .values != nil && response .values == nil ) {
334+ t .Fatalf ("Nils comparison error: expected %v, actual %v" , request .values == nil , response .values == nil )
335+ }
336+ if len (request .values ) != len (response .values ) {
337+ t .Fatalf ("Values array lengths differ: expected %v, actual %v" , request .values , response .values )
338+ }
339+ for i := range request .values {
340+ if request .values [i ] != response .values [i ] {
341+ t .Fatalf ("Values differ: index %d, expected %v, actual %v" , i , request .values [i ], response .values [i ])
342+ }
343+ }
344+ }
345+ }
346+
347+ func TestEncodeDecodeInt64Array (t * testing.T ) {
348+ tt := []struct {
349+ name string
350+ values []int64
351+ }{
352+ {name : "nil array" , values : nil },
353+ {name : "empty array" , values : []int64 {}},
354+ {name : "0" , values : []int64 {0 }},
355+ {name : "0s" , values : []int64 {0 , 0 }},
356+ {name : "1" , values : []int64 {1 }},
357+ {name : "1s" , values : []int64 {1 , 1 }},
358+ {name : "2" , values : []int64 {2 }},
359+ {name : "3" , values : []int64 {3 }},
360+ {name : "4" , values : []int64 {4 }},
361+ {name : "16" , values : []int64 {16 }},
362+ {name : "63" , values : []int64 {63 }},
363+ {name : "64" , values : []int64 {64 }},
364+ {name : "128" , values : []int64 {128 }},
365+ {name : "8191" , values : []int64 {8191 }},
366+ {name : "8192" , values : []int64 {8192 }},
367+ {name : "32767" , values : []int64 {math .MaxInt16 }},
368+ {name : "32767,-32768" , values : []int64 {math .MaxInt16 , math .MinInt16 }},
369+ {name : "2147483647" , values : []int64 {math .MaxInt32 }},
370+ {name : "2147483647,-2147483648" , values : []int64 {math .MaxInt32 , math .MinInt32 }},
371+ {name : "max,min" , values : []int64 {math .MaxInt64 , math .MinInt64 }},
372+ {name : "different values" , values : []int64 {0 , 1 , 2 , 3 , 4 , - 1 , 16 , 64 , 127 , 128 , 8191 , 8192 , 8191 , 128 , 127 , - 1 , 64 , 16 , 4 , 3 , 2 , 1 , - 1 , 0 }},
373+ }
374+ for _ , tc := range tt {
375+ request := & Int64ArrayHolder {
376+ values : tc .values ,
377+ }
378+ buf , err := Encode (request )
379+ if err != nil {
380+ t .Fatal (err )
381+ }
382+ response := & Int64ArrayHolder {}
383+ err = Decode (buf , response )
384+ if err != nil {
385+ t .Fatal (err )
386+ }
387+ if (request .values == nil && response .values != nil ) || (request .values != nil && response .values == nil ) {
388+ t .Fatalf ("%s: Nils comparison error: expected %v, actual %v" , tc .name , request .values == nil , response .values == nil )
389+ }
390+ if len (request .values ) != len (response .values ) {
391+ t .Fatalf ("Values array lengths differ: expected %v, actual %v" , request .values , response .values )
392+ }
393+ for i := range request .values {
394+ if request .values [i ] != response .values [i ] {
395+ t .Fatalf ("Values differ: index %d, expected %v, actual %v" , i , request .values [i ], response .values [i ])
396+ }
397+ }
398+ }
399+ }
400+
401+ type Int32ArrayHolder struct {
402+ values []int32
403+ }
404+
405+ func (r * Int32ArrayHolder ) encode (pe packetEncoder ) (err error ) {
406+ err = pe .putInt32Array (r .values )
407+ if err != nil {
408+ return err
409+ }
410+ return
411+ }
412+ func (r * Int32ArrayHolder ) decode (pd packetDecoder ) (err error ) {
413+ if r .values , err = pd .getInt32Array (); err != nil {
414+ return err
415+ }
416+ if pd .remaining () != 0 {
417+ return errors .Errorf ("remaining bytes %d" , pd .remaining ())
418+ }
419+ return
420+ }
421+
422+ type Int64ArrayHolder struct {
423+ values []int64
424+ }
425+
426+ func (r * Int64ArrayHolder ) encode (pe packetEncoder ) (err error ) {
427+ err = pe .putInt64Array (r .values )
428+ if err != nil {
429+ return err
430+ }
431+ return
432+ }
433+ func (r * Int64ArrayHolder ) decode (pd packetDecoder ) (err error ) {
434+ if r .values , err = pd .getInt64Array (); err != nil {
435+ return err
436+ }
437+ if pd .remaining () != 0 {
438+ return errors .Errorf ("remaining bytes %d" , pd .remaining ())
439+ }
440+ return
441+ }
442+
295443type CompactBytesHolder struct {
296444 values [][]byte
297445}
0 commit comments