Skip to content

Commit

Permalink
Remove more extra container ends
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed Sep 23, 2024
1 parent 51ce818 commit 3dd02a8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 21 deletions.
3 changes: 1 addition & 2 deletions circuitmatter/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def encode(self, value) -> memoryview:
buffer = memoryview(bytearray(value.max_length() + 2))
buffer[0] = tlv.ElementType.STRUCTURE
end = value.encode_into(buffer, 1)
buffer[end] = tlv.ElementType.END_OF_CONTAINER
return buffer[: end + 1]
return buffer[:end]


class OctetStringAttribute(Attribute):
Expand Down
2 changes: 0 additions & 2 deletions circuitmatter/tlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,6 @@ def encode_value_into(self, value, buffer: bytearray, offset: int) -> int:
else:
raise NotImplementedError("Unknown type")
offset = v.encode_into(buffer, offset + 1)
buffer[offset] = ElementType.END_OF_CONTAINER
offset += 1
buffer[offset] = ElementType.END_OF_CONTAINER
return offset + 1

Expand Down
36 changes: 19 additions & 17 deletions test_data/recorded_packets.jsonl
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
["urandom", 611538362769836, 8, "7IqPDolswXE="]
["receive", 611542342146276, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "BAAAALOJYA42R2d4e1fWQQUg4sIAABUwASDozjMsxicrnDj/NjeSaB9m8NX7G4LdPJnqm4uWwo7S9iUCVnMkAwAoBDUFJQH0ASUCLAElA6APJAQRJAULJgYAAAMBJAcBGBg="]
["urandom", 611542373385499, 32, "amrbDtzcWt2dJboBhSVhVAriSUlrFBxMUpW8ti+9lWw="]
["send", 611542373589975, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AQAAANMJMg42R2d4e1fWQQIh4sIAALOJYA4VMAEg6M4zLMYnK5w4/zY3kmgfZvDV+xuC3TyZ6puLlsKO0vYwAiBqatsO3Nxa3Z0lugGFJWFUCuJJSWsUHExSlby2L72VbCUDAQA1BCYBECcAADACIObgj9CEx2MyPagRHuoX1OB32N8u1aKUpNKjb4b854YkGBg="]
["receive", 611542379685073, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "BAAAALSJYA42R2d4e1fWQQUi4sIAABUwAUEE4dM8AKRxdKyocQVO66aeobNSpjdAT+SUaM9WRRwvUQxYlDRgG6tvGzME1em13s/p3s0UxOGd8ZfjjnlP6g07Khg="]
["randbelow", 611542379785923, 115792089210356248762697446949407573529996955224135760342422259061068512044369, 18686455751714252099427219551429565272567932817770329314969969789848945100921]
["send", 611542395205834, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AQAAANQJMg42R2d4e1fWQQIj4sIAALSJYA4VMAFBBKVs5C/yQ3zmpRjWWITnJFvTA5eK04zPlLpZ/xFHnrjXZ6KvD4CwYeH3XRUN/ogNaN1g9yl4WqCUyPpgTLn9jDYwAiBdQqEMicwLaMyAl13/N6aoyXZlObtk5/S9nUsm+pVWVBg="]
["receive", 611542395669018, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "BAAAALWJYA42R2d4e1fWQQUk4sIAABUwASDTWToRuOYxnSZIUTzy/5Fsd4ytbi9Bn8MrOw8A1v6lTRg="]
["send", 611542395771731, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AQAAANUJMg42R2d4e1fWQQJA4sIAALWJYA4AAAAAAAAAAA=="]
["receive", 611542395940870, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AAEAAB0yugTvmTZ+TWtppwYBzVVge27aOTCoKcz8bddeiIPpiK9FKYNhjU8NYXkThvO48PxKDSXNup6TnxzxLIr4WlRdIgDDhjxw1ZFNWCl+w6VAW22ewNv5ZmS8IVfbKBGzsKlIremKCLjZ5ru3Z2tBvmF/h+aCPP/eIyOBIwQQ+WU="]
["send", 611542396948932, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AFZzAO5wmAop3tJHsU/2PUDdpaQCNFauxcgwzp3GWJuCQWdVI6MeiAmEQwgTl9caHeohNo3j3ySc+DagOwyz1BhkyV2F5L0Kdnzxc4hBrYKZaqVA/NKQy4jQ1d9/Jsp/JZWSwDUPKlmwgBYXom9jYPTJ/Q6AHrIRoUuhjj60m5VVsNdLf9G/hw8XWr4OmwduzQGRJntAoRvArhax8hzII/fnTS2UgSPUF1Xt283CHdMrdZ4oeOlPMo9V07bgDs0zvJLyV6OO1LdUxeT8g2mRKSiepjoR5mEQe+lLpYh2jDn3Y5Kt4SfzCZH7ssmwTZyoheQtUHTOyFu4DPrDQWR91ISAvK7vwrMvPd+xms/Fh8duEyRGL9mgrwLDLkBgMrFX9lRDoGBHMIJYYw39R1H6qvcE5guEXqnS8v5KSBR6Phwm"]
["receive", 611542397100839, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AAEAAB4yugQRmjD6ItRCbJzoGAHAbdXYq9K3559GlLfYG4XYLic="]
["receive", 611542397196479, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AAEAAB8yugQGuEaWHI2lm801cUoFP3zTOjHD8ZALr6FM9LM9m2OrWWToL8VwGuMa6NJGXohvkhXeRu3fJQl3tQqckkYk267vy/H6QbreqIA2HNb91w=="]
["send", 611542397496766, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AFZzAO9wmAqY4GYHxiwxqrs+Jh4i+msLc7f5d5WaiFrIacMs89uk3eNOX42c55b5kh9ZtGCpAavifRjWJNwp1cCk9kV+9RWp"]
["receive", 611542398355386, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AAEAACAyugT0CApC4YECx60j1svaX1+xPU+rgo1Mxktq7xX2TD8="]
["receive", 611542398452960, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AAEAACEyugSo6dyOf3rdLZogs5AXfa0nGZyMzJb776xye5L4/n5mdxsYu8Gy0Jx/pK/vwaf4E49W39id9SJwV88="]
["send", 611542398901516, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 33687, 0, 0], "AFZzAPBwmArRIbed47XNIBhM1dGbfV2EsZbpg0DjI7maFko4C61hoB/7WEvLEbvH1aV3AdXMS5FuEcmJQUacYCnnsPZAkhAsDszflspu+kWkWecwp2rEQWy4reEDGwUWrzl+HVGLR207Zd8="]
["urandom", 615386218116488, 8, "H7JptUR2dI8="]
["receive", 615390509290148, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "BAAAAMsxPAn5lKlXrK6EIgUgHF8AABUwASBDN5VT4qEZHWLnSF7HoM8OgCtvfKkSpg26+++4bDQJmyUChtEkAwAoBDUFJQH0ASUCLAElA6APJAQRJAULJgYAAAMBJAcBGBg="]
["urandom", 615390539734900, 32, "PaQiCjhxs8ODMZ5GthBmb4/MZ4hJigr5XQgxtBNfujM="]
["send", 615390539901344, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AQAAAJMHSAP5lKlXrK6EIgIhHF8AAMsxPAkVMAEgQzeVU+KhGR1i50hex6DPDoArb3ypEqYNuvvvuGw0CZswAiA9pCIKOHGzw4Mxnka2EGZvj8xniEmKCvldCDG0E1+6MyUDAQA1BCYBECcAADACIObgj9CEx2MyPagRHuoX1OB32N8u1aKUpNKjb4b854YkGBg="]
["receive", 615390546155785, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "BAAAAMwxPAn5lKlXrK6EIgUiHF8AABUwAUEE0gefLFj+xRmFkURaSBa2o9k+BK7IeSGuMUJd8vOlfzqxfeZWVNwPLq67Kc0dH8WfMo9nOJh1ViqUgtFGLY6pdxg="]
["randbelow", 615390546249471, 115792089210356248762697446949407573529996955224135760342422259061068512044369, 74944978393438142966461922107606904469387315672506885538396514800631953724932]
["send", 615390561660608, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AQAAAJQHSAP5lKlXrK6EIgIjHF8AAMwxPAkVMAFBBNvQdssgf55XSmuJ7O6c4bd7LQNjaaf8kjD/yUCNkfo2UnP5+/klM4hRqOvJz3DE3HacfTrhYOtFwevfxuagAYEwAiAZMTjp8AuJYGksjRhRFtmQx9QSClKzPml4KfOTG5spvhg="]
["receive", 615390562074710, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "BAAAAM0xPAn5lKlXrK6EIgUkHF8AABUwASBfqp677T23h0QftAJ7cvU7+c6kBjML4AYBz1RL0aEp6Bg="]
["send", 615390562156564, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AQAAAJUHSAP5lKlXrK6EIgJAHF8AAM0xPAkAAAAAAAAAAA=="]
["receive", 615390562331504, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AAEAADkFHQDX3mortC46vkGGtXfugQfkllyodwMhALyTz4s3J3MIlTvLuIYEWxIuGWQ4vKdcFv20DQxg5YBfykBE+Pz8I2i1YXlNa32KSQpNbcNI/Adz6EF1Y65N+siene6yPM+D0j9kNNGgqc5+kUwbBPhueoo3QPCT0QTOX2VnngU="]
["send", 615390563235680, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AIbRAJQzkwZaqHWX2x5Iu3noT87Cit/znpsXK5LT5bUk4dyDQX3u5X8S5TQZJucEx/Jx8lMMqu2q6Ws1cIYo1BruealZSIqoI5s3bnWKzQ2p5PDy6adWghpI6dwrSoCjIr9WmOg7PmlSt/ZF+92qHRyTJk6CILdCfdJ7eG4fzKQ8ed9akhCk7yoCyyO0sy6G4Xw/zVraVT+0saRtZ+d5h+Hv/Mxlm+YQO6k3ZCQZKsSFjSD38W4Qw+FMDTu5SVt3A8/FihppOa1/NzkRQ+zW54Egh6MmG0FWWQaCCkbdtNnz4CCsWmUDniAabCE+Py5Sd0UzRYiB6IRbwUJ1zUbQq1T71Zgos53G2eEuSru2wArQikThd7vTYwnrQ0qLWn5pa4guND4onTrB1mBIiRYJDFOD6uHZ9OXZ"]
["receive", 615390572146082, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AAEAADoFHQDtsggGX7t7Yodo7vzgHLwu4KNA9k4+MR+q+GJmIHQ="]
["receive", 615390572246762, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AAEAADsFHQCGLf05sAAi+NRh8y1W1AXSfBBqUdFFUaJ07gQq6uV3JR1ssKHk2qntj0vWjz8OaB2d5vla3bYvADTP0aEN8n2sLRe48oyzaAaeMEXqMg=="]
["send", 615390572532622, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AIbRAJUzkwbUOdyJspVGWQhX1NpL6PKsZIZ5ajCCrPJGg1N5pU+NA7PDlsuenOcn2JWdkwdOYx7WMN9A7Z9dfgJd8ooWGCU="]
["receive", 615390573914860, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AAEAADwFHQA/IQ7uy5OJdjXnYZFbuuknc/bJn09dppQvhpw8fa4="]
["receive", 615390574036349, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AAEAAD0FHQB4bFd583wEfXys5WQGiyo55a4qdiuvPofqp5CIKlqSAWhp1v1qy2vNpz3UK5Vmx0x5fNkSg4Fse8s="]
["send", 615390574416837, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AIbRAJYzkwaHh6H2vW2FUZ7DwMed6ErviWwSifdImMsGnpnbvebtNxKHOGo+fGZJdt9EcnBG+pJivWWKY3taEzXBD1rfr6vIklLsKkwVhXt8+o6BbzNTslC2PlGuR5UrTThld9K+J1urqw=="]
["receive", 615390576223385, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AAEAAD4FHQDL8Hq5PN6fTUZ4SToLwk55moIVzbDKdBh6+fj8pn0toERxbVSDI+i7bNqjxaJ+7RUndx9frvOsaso="]
["send", 615390576563778, ["fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", 48793, 0, 0], "AIbRAJczkwbClUzCYE3z9GkY1jbnKcRvzgkgM5Bwp3JXhTts8HdgDnn8pe2IrDO8zABfkuQ5G4VrRidWvQbtureE6+nxzSGIPSyup8AeuwrP8PhAKib/JcWj0M78TUSiJxq2QHfmZo8iwQ=="]
50 changes: 50 additions & 0 deletions tests/test_tlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,3 +583,53 @@ def test_encode(self):
s.encode().tobytes()
== b"\x15\xc2\xda\x0a\x00\x0f\x23\x01\x2a\x00\x00\x00\xe2\xda\x0a\x00\x0f\x45\x23\x01\x00\xef\xff\xff\xff\x18"
)


class InnerList(tlv.List):
a = tlv.IntMember(0, signed=True, optional=True, octets=4)
b = tlv.IntMember(1, signed=True, optional=True, octets=4)


class OuterStructList(tlv.Structure):
sublist = tlv.ListMember(0, InnerList)


class TestList:
def test_encode(self):
s = OuterStructList()
inner = InnerList()
inner.a = 42
inner.b = -17
s.sublist = inner
assert (
s.encode().tobytes()
== b"\x15\x37\x00\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18"
)


class OuterStructArray(tlv.Structure):
a = tlv.ArrayMember(0, InnerList)


class TestArray:
def test_encode(self):
s = OuterStructArray()
inner = InnerList()
inner.a = 42
inner.b = -17
s.a = [inner]
assert (
s.encode().tobytes()
== b"\x15\x36\x00\x17\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18\x18"
)

def test_encode2(self):
s = OuterStructArray()
inner = InnerList()
inner.a = 42
inner.b = -17
s.a = [inner, inner]
assert (
s.encode().tobytes()
== b"\x15\x36\x00\x17\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x17\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18\x18"
)

0 comments on commit 3dd02a8

Please sign in to comment.