@@ -201,12 +201,6 @@ class JSONStructCodec(AbstractMetadataCodec):
201201 The codec expects a metadata schema with separate ``json`` and ``struct``
202202 subschemas and produces a single dict containing the union of the keys from
203203 those subschemas after decoding.
204-
205- The structure of the encoded metadata is as follows: first, a fixed-size
206- header that contains the number of bytes for both ``json`` and ``struct``
207- portions; next, the json; then a variable number of zeroed padding bytes
208- that brings the length to a multiple of 8 for alignment; and finally
209- the struct-encoded binary portion.
210204 """
211205
212206 MAGIC = b"JBLB"
@@ -300,25 +294,20 @@ def encode(self, obj: Any) -> bytes:
300294 header = self ._HDR .pack (
301295 self .MAGIC , self .VERSION , len (json_bytes ), len (blob_bytes )
302296 )
303- padding_bytes = bytes ((- (len (header ) + len (json_bytes ))) % 8 )
304- return header + json_bytes + padding_bytes + blob_bytes
297+ return header + json_bytes + blob_bytes
305298
306299 def decode (self , encoded : bytes ) -> Any :
307300 if len (encoded ) >= self ._HDR .size and encoded [:4 ] == self .MAGIC :
308301 _ , version , jlen , blen = self ._HDR .unpack_from (encoded )
309302 if version != self .VERSION :
310303 raise ValueError ("Unsupported json+struct version" )
311304 start = self ._HDR .size
312- padding_length = (- (start + jlen )) % 8
313- if (
314- jlen > len (encoded ) - start
315- or blen > len (encoded ) - start - jlen - padding_length
316- ):
305+ if jlen > len (encoded ) - start or blen > len (encoded ) - start - jlen :
317306 raise ValueError (
318307 "Invalid json+struct payload: declared lengths exceed buffer size"
319308 )
320309 json_bytes = encoded [start : start + jlen ]
321- blob_bytes = encoded [start + jlen : start + jlen + blen + padding_length ]
310+ blob_bytes = encoded [start + jlen : start + jlen + blen ]
322311 json_data = self .json_codec .decode (json_bytes )
323312 struct_data = self .struct_codec .decode (blob_bytes )
324313 overlap = set (json_data ).intersection (struct_data )
0 commit comments