Skip to content

Commit 38102d0

Browse files
committed
remove python stuff
1 parent acdc340 commit 38102d0

2 files changed

Lines changed: 3 additions & 59 deletions

File tree

python/tests/test_metadata.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -671,51 +671,6 @@ 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-
719674
def test_json_defaults_applied(self):
720675
schema = {
721676
"codec": "json+struct",

python/tskit/metadata.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)