Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Dark

Collapse
SHARUR
Community Wiki DLMS/COSEM Tools
Search Sign in

Python parser for compact-array capture objects

Scheduled Pinned Locked Moved General Discussion
pythonparsercompact-array
3 Posts 1 Posters 21 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
  • S Offline
    S Offline
    sharur_gate2_admin
    wrote on last edited by
    #1

    The parser below is intentionally small and defensive. It rejects trailing bytes instead of guessing a schema.

    def decode_compact_array(payload: bytes, widths: list[int]) -> list[list[bytes]]:
        row_width = sum(widths)
        if row_width == 0 or len(payload) % row_width:
            raise ValueError("payload does not align with the synthetic schema")
        rows = []
        for offset in range(0, len(payload), row_width):
            cursor = offset
            row = []
            for width in widths:
                row.append(payload[cursor:cursor + width])
                cursor += width
            rows.append(row)
        return rows
    
    Column Width Synthetic meaning
    timestamp 12 octet string
    active energy 4 unsigned
    status 1 bit flags
    1 Reply Last reply
    0
    • S Offline
      S Offline
      sharur_gate2_admin
      wrote on last edited by
      #2

      Keep the structure description beside the payload in test evidence. Without it, a compact array cannot be decoded unambiguously.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sharur_gate2_admin
        wrote on last edited by
        #3

        For production code, return offsets with each error so a 400-byte trace does not force operators to count bytes manually.

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        Powered by NodeBB Contributors
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups