Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codec objects #364

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Commits on Nov 25, 2024

  1. Add codec objects

    Codecs are any objects that can be en- and decoded into PDUs. The
    approach so far was to derive all "composite" codecs from
    `BasicStructure` and to use a subset of that API for "simple" codable
    objects like DOPs or parameters. In particular, the previous approach
    to composite objects was sub-optimal because `BASIC-STRUCTURE`
    features subtags that other codable objects like `Request` and
    `Response` do not exhibit (i.e., `.byte_size`).
    
    Since codecs do not play very nicely with inheritance, the new
    approach is based on typing protocols (Java would call these
    "interfaces"): `codec.py` defines a few runtime checkable
    `typing.Protocol` classes which codecs must implement: `Codec` for the
    basic functionality, `CompositeCodec` defines the API for codecs that
    are composed of a list of parameters like structures, requests,
    responses or environment datas, and `ToplevelCodec` defines the
    "external" API for requests and responses that is supposed to be
    called by user scripts. Any codable class implementing these APIs can
    check if it is compliant using `isinstance()` in the `__post_init__()`
    method of the respective class.
    
    Signed-off-by: Andreas Lauser <[email protected]>
    Signed-off-by: Alexander Walz <[email protected]>
    Signed-off-by: Gunnar Andersson <[email protected]>
    andlaus committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    fbfbfe7 View commit details
    Browse the repository at this point in the history
  2. refrain from checking adherence of DOPs and basic structures to the C…

    …odec APIs at runtime
    
    as [at]kayoub5 correctly notes, this is already done by `mypy` ahead of time.
    
    Signed-off-by: Andreas Lauser <[email protected]>
    andlaus committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    428b2ee View commit details
    Browse the repository at this point in the history
  3. Message: remove deprecated .structure property

    this property has been deprecated for more than a year and after this
    pull request, request and response objects are no longer structures.
    
    Signed-off-by: Andreas Lauser <[email protected]>
    andlaus committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    5f97146 View commit details
    Browse the repository at this point in the history
  4. Request/Response: remove unnecessary exception handling

    the intention of this was to make the code more robust in non-strict
    mode, but come think about it, exceptions raised by
    `._resolve_snref()` will not be caught even in non-strict mode, so we
    can as well simply skip the exception handling entirely. (besides
    this, `context.response` is now properly set in
    `Response._resolve_snrefs()`.)
    
    thanks to [at]kayoub5 for noticing this...
    
    Signed-off-by: Andreas Lauser <[email protected]>
    andlaus committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    e1688c8 View commit details
    Browse the repository at this point in the history
  5. remove the ToplevelCodec type protocol

    As [at]kayoub5 rightfully notes, this was not used anywere for
    real. (Also, the `Response` class did not even strictly implement it,
    because the `.decode()` and `.encode()` methods accept the additional
    `coded_request` argument.)
    
    Signed-off-by: Andreas Lauser <[email protected]>
    andlaus committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    96b8e26 View commit details
    Browse the repository at this point in the history
  6. DataObjectProperty: remove unnecessary .byte_size property

    this was an artifact stemming from the development history of this PR:
    originally, the `Codec` type protocol mandated this property, but it
    turned out that the better approach was to move handling of
    statically-sized structures from the generic function
    (`composite_codec_get_static_bit_length()`) to the
    `get_static_bit_length()` method of structures.
    
    Signed-off-by: Andreas Lauser <[email protected]>
    andlaus committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    068f479 View commit details
    Browse the repository at this point in the history
  7. remove misleading comment

    Thanks for the catch, [at]kayoub5.
    
    Signed-off-by: Andreas Lauser <[email protected]>
    andlaus committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    1da10e7 View commit details
    Browse the repository at this point in the history
  8. replace structure by composite codec in some comments

    thanks to [at]kayoub5
    
    Signed-off-by: Andreas Lauser <[email protected]>
    andlaus committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    4483a3b View commit details
    Browse the repository at this point in the history
  9. DiagCodedType: remove spurious byte_size property

    thanks to [at]kayoub5
    
    Signed-off-by: Andreas Lauser <[email protected]>
    andlaus committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    bf33ea2 View commit details
    Browse the repository at this point in the history