@@ -671,6 +671,51 @@ def test_round_trip_with_struct_and_json(self):
671671 out = ms .decode_row (encoded )
672672 assert out == row
673673
674+ def test_blob_bytes_aligned (self ):
675+ # test that the portion of the encoded metadata up until the struct
676+ # is 8-byte aligned; we do that in the pedantic way
677+ # of figuring out how much memory is being used per int
678+ # in the struct part and subtracting that off
679+ def schema_with_blobs (k ):
680+ schema = {
681+ "codec" : "json+struct" ,
682+ "json" : {
683+ "type" : "object" ,
684+ "properties" : {
685+ "label" : {"type" : "string" },
686+ "count" : {"type" : "number" },
687+ },
688+ "required" : ["label" ],
689+ },
690+ "struct" : {
691+ "type" : "object" ,
692+ "properties" : {},
693+ },
694+ }
695+ for j in range (k ):
696+ schema ["struct" ]["properties" ][f"b{ j } " ] = {
697+ "type" : "integer" ,
698+ "binaryFormat" : "i" ,
699+ }
700+ return tskit .MetadataSchema (schema )
701+
702+ k_list = (0 , 1 , 2 , 3 )
703+ schemas = [schema_with_blobs (k ) for k in k_list ]
704+ rows = []
705+ for k in k_list :
706+ row = {"label" : "alpha" , "count" : 7 }
707+ for j in range (k ):
708+ row [f"b{ j } " ] = j
709+ rows .append (row )
710+ encoded = [ms .validate_and_encode_row (row ) for ms , row in zip (schemas , rows )]
711+ dbytes = len (encoded [2 ]) - len (encoded [1 ])
712+ assert len (encoded [3 ]) - len (encoded [2 ]) == dbytes
713+ for k , en in zip (k_list , encoded ):
714+ assert (len (en ) - k * dbytes ) % 8 == 0
715+ for ms , en , row in zip (schemas , encoded , rows ):
716+ decoded = ms .decode_row (en )
717+ assert decoded == row
718+
674719 def test_json_defaults_applied (self ):
675720 schema = {
676721 "codec" : "json+struct" ,
0 commit comments