u9n / dlms-cosem

A Python library for DLMS/COSEM
Other
80 stars 41 forks source link

Remove the need for the general A XDR parser. #26

Open Krolken opened 3 years ago

Krolken commented 3 years ago

The current A XDR parser was made so that it was possible to just write a parsing config to APDUs and it would output the correct dict to create the object.

But it has proven that it is just was smoother to handparse each APDU. Some of the larger and more complex ones might be a little bit annoying but on the whole it is much clearer in the code when the parsing is done explicitly.

The use we want to keep it for is to parse dynamic DLMS data returned from meters. If we remove the general parsing and make it into a dlms response data parse we can get a smoother solution than:


def parse_as_dlms_data(data: bytes):
    data_decoder = a_xdr.AXdrDecoder(
        encoding_conf=a_xdr.EncodingConf(
            attributes=[a_xdr.Sequence(attribute_name="data")]
        )
    )
    return data_decoder.decode(data)["data"]