Skip to content

Commit

Permalink
Incorporate review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
neelam-kushwah committed Oct 31, 2024
1 parent 9191406 commit 6985aee
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions up_transport_zenoh/zenohutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ def uattributes_to_attachment(uattributes: UAttributes):
uattributes_bytes = uattributes.SerializeToString()

# Combine version bytes and uattributes bytes into one list of bytes
attachment_bytes = version_bytes + uattributes_bytes
attachment_bytes = [version_bytes, uattributes_bytes]

# Convert the combined bytes to ZBytes
return ZBytes(attachment_bytes)
return attachment_bytes

@staticmethod
def attachment_to_uattributes(attachment: ZBytes) -> UAttributes:
try:
# Convert ZBytes to a list of bytes
attachment_bytes = bytes(attachment)
attachment_bytes = attachment.deserialize(list)

# Ensure there is at least one byte for the version
if len(attachment_bytes) < 1:
Expand All @@ -114,14 +114,14 @@ def attachment_to_uattributes(attachment: ZBytes) -> UAttributes:
raise UStatusError.from_code_message(code=UCode.INVALID_ARGUMENT, message=msg)

# Check the version
version = attachment_bytes[0]
version = int.from_bytes(bytes(attachment_bytes[0]), byteorder='big')
if version != UATTRIBUTE_VERSION:
msg = f"UAttributes version is {version} (should be {UATTRIBUTE_VERSION})"
logging.debug(msg)
raise UStatusError.from_code_message(code=UCode.INVALID_ARGUMENT, message=msg)

# Get the attributes from the remaining bytes
uattributes_data = attachment_bytes[1:]
uattributes_data = bytes(attachment_bytes[1])
if not uattributes_data:
msg = "Unable to get the UAttributes"
logging.debug(msg)
Expand Down

0 comments on commit 6985aee

Please sign in to comment.