@@ -33,6 +33,19 @@ var dummyRecord [29]byte = [29]byte{0x92, /* fix array 2 */
3333 0x01 , /* fix int 1 */
3434}
3535
36+ // dummyV2Record should be byte Array, not Slice to be able to Cast c array.
37+ var dummyV2Record [39 ]byte = [39 ]byte {0xdd , /* array 32 */ 0x00 , 0x00 , 0x00 ,
38+ 0x02 , /* count of array elements */
39+ 0xdd , /* array 32 */ 0x00 , 0x00 , 0x00 ,
40+ 0x02 , /* count of array elements */
41+ 0xd7 , 0x00 , 0x64 , 0xbe , 0x0e , 0xeb , 0x16 , 0x36 , 0xe1 , 0x28 , 0x80 , /* 2023/07/24 14:40:59 */
42+ 0x82 , /* fix map 2 */
43+ 0xa7 , 0x63 , 0x6f , 0x6d , 0x70 , 0x61 , 0x63 , 0x74 , /* fix str 7 "compact" */
44+ 0xc3 , /* true */
45+ 0xa6 , 0x73 , 0x63 , 0x68 , 0x65 , 0x6d , 0x61 , /* fix str 6 "schema" */
46+ 0x01 , /* fix int 1 */
47+ }
48+
3649func TestGetRecord (t * testing.T ) {
3750 dec := NewDecoder (unsafe .Pointer (& dummyRecord ), len (dummyRecord ))
3851 if dec == nil {
@@ -63,3 +76,34 @@ func TestGetRecord(t *testing.T) {
6376 t .Errorf (`record["schema"] is not 1 %d` , v )
6477 }
6578}
79+
80+ func TestGetV2Record (t * testing.T ) {
81+ dec := NewDecoder (unsafe .Pointer (& dummyV2Record ), len (dummyV2Record ))
82+ if dec == nil {
83+ t .Fatal ("dec is nil" )
84+ }
85+
86+ ret , timestamp , record := GetRecord (dec )
87+ if ret < 0 {
88+ t .Fatalf ("ret is negative: code %v" , ret )
89+ }
90+
91+ // test timestamp
92+ ts , ok := timestamp .(FLBTime )
93+ if ! ok {
94+ t .Fatalf ("cast error. Type is %s" , reflect .TypeOf (timestamp ))
95+ }
96+
97+ if ts .Unix () != int64 (0x64be0eeb ) {
98+ t .Errorf ("ts.Unix() error. given %d" , ts .Unix ())
99+ }
100+
101+ // test record
102+ v , ok := record ["schema" ].(int64 )
103+ if ! ok {
104+ t .Fatalf ("cast error. Type is %s" , reflect .TypeOf (record ["schema" ]))
105+ }
106+ if v != 1 {
107+ t .Errorf (`record["schema"] is not 1 %d` , v )
108+ }
109+ }
0 commit comments