X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fzx303proto.py;h=a2132f6c3c658aee30995d5326cf4d8701f93ba3;hb=5ac485743c88a3814821bea386df01b9aaa1d4a1;hp=efb02d249f6c118185ce2a66b23675c9acf85efd;hpb=dbdf9d63af31770ad57302e16b17a2fdc526773f;p=loctrkd.git diff --git a/loctrkd/zx303proto.py b/loctrkd/zx303proto.py index efb02d2..a2132f6 100755 --- a/loctrkd/zx303proto.py +++ b/loctrkd/zx303proto.py @@ -35,9 +35,9 @@ __all__ = ( "Stream", "class_by_prefix", "inline_response", + "proto_handled", "parse_message", "probe_buffer", - "proto_by_name", "proto_name", "DecodeError", "Respond", @@ -81,7 +81,7 @@ __all__ = ( "UNKNOWN_B3", ) -PROTO_PREFIX = "ZX" +PROTO_PREFIX = "ZX:" ### Deframer ### @@ -92,10 +92,6 @@ class Stream: def __init__(self) -> None: self.buffer = b"" - @staticmethod - def enframe(buffer: bytes) -> bytes: - return b"xx" + buffer + b"\r\n" - def recv(self, segment: bytes) -> List[Union[bytes, str]]: """ Process next segment of the stream. Return successfully deframed @@ -150,6 +146,10 @@ class Stream: return ret +def enframe(buffer: bytes, imei: Optional[str] = None) -> bytes: + return b"xx" + buffer + b"\r\n" + + ### Parser/Constructor ### @@ -875,20 +875,14 @@ def class_by_prefix( return CLASSES[proto] -def proto_name(obj: Union[MetaPkt, GPS303Pkt]) -> str: - return ( - PROTO_PREFIX - + ":" - + ( - obj.__class__.__name__ - if isinstance(obj, GPS303Pkt) - else obj.__name__ - ) - ).ljust(16, "\0")[:16] +def proto_handled(proto: str) -> bool: + return proto.startswith(PROTO_PREFIX) -def proto_by_name(name: str) -> int: - return PROTOS.get(name, -1) +def proto_name(obj: Union[MetaPkt, GPS303Pkt]) -> str: + return PROTO_PREFIX + ( + obj.__class__.__name__ if isinstance(obj, GPS303Pkt) else obj.__name__ + ) def proto_of_message(packet: bytes) -> str: