Skip to content

Encoder class lacks a code property exposing the prefix byte #47

Description

@sumanjeet0012

The Encoder class stores the prefix code internally as self._codec.code but doesn't expose it as a public property. Users who need the prefix byte must access the private _codec attribute or call get_encoding_info().

Problem

enc = Encoder("base16")
enc.encoding   # "base16" ✅ — name is public
enc.code       # ❌ AttributeError — prefix byte not exposed
enc._codec.code  # b"f" — works but accesses private attribute

Go's Encoder exposes the encoding code:

func (p Encoder) Encoding() Encoding {
    return p.enc  // Returns the Encoding constant (e.g., Base16 = 'f')
}

Proposed Solution

Add a code property to the Encoder class:

class Encoder:
    @property
    def code(self) -> bytes:
        """The multibase prefix byte for this encoding."""
        return self._codec.code

Add tests and update __init__.py exports if needed.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions