Skip to content

Commit 5cc8056

Browse files
fix demo
1 parent 37bd976 commit 5cc8056

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

demo/DemoMessage.1.0.dsdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ bool flag
44
uint32 counter
55
float64 temperature
66
float32[4] numeric_data
7-
uint8[<=256] text_data # UTF-8 encoded text data
7+
utf8[<=256] text_data # UTF-8 encoded text data
88
byte[<=64] binary_data # Raw binary data
99

1010
@extent 1024 * 8

demo/demo_serdes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def main() -> None:
1919
)
2020
schema = types[0]
2121
print(f"✓ Loaded type: {schema.full_name} v{schema.version.major}.{schema.version.minor}")
22-
print(f" Fields: {[f.name for f in schema.fields_except_padding]}")
22+
print(" Fields:", [f"{f.data_type} {f.name}" for f in schema.fields_except_padding])
2323

2424
print("Creating example object:")
2525
obj = {

pydsdl/_test_serdes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,23 @@ def test_array_utf8_type_error() -> None:
979979
_serialize_array(_BitWriter(), schema, 123)
980980

981981

982+
def test_api_accepts_str_and_bytes_for_utf8_and_byte_arrays() -> None:
983+
schema = _mk_structure(
984+
"test.StringLikeArrays",
985+
[
986+
Field(VariableLengthArrayType(UTF8Type(), 64), "text"),
987+
Field(VariableLengthArrayType(ByteType(), 64), "blob"),
988+
],
989+
)
990+
991+
cases = [
992+
({"text": "hello", "blob": b"\x00\x01\x02"}, {"text": "hello", "blob": b"\x00\x01\x02"}),
993+
({"text": b"world", "blob": "abc"}, {"text": "world", "blob": b"abc"}),
994+
]
995+
for obj, expected in cases:
996+
assert deserialize(schema, serialize(schema, obj)) == expected
997+
998+
982999
def test_array_unknown_type_error() -> None:
9831000
class MockArray:
9841001
element_type = UnsignedIntegerType(8, CM.TRUNCATED)
@@ -1286,6 +1303,7 @@ def _unittest_serdes_branch_coverage_tests() -> None:
12861303
test_array_byte_from_list_input((104, 105))
12871304
test_array_byte_type_error()
12881305
test_array_utf8_type_error()
1306+
test_api_accepts_str_and_bytes_for_utf8_and_byte_arrays()
12891307
test_array_unknown_type_error()
12901308
test_array_deserialized_length_overflow()
12911309
test_array_composite_elements()

0 commit comments

Comments
 (0)