hio.core.packeting ================== .. py:module:: hio.core.packeting .. autoapi-nested-parse:: hio.core.packeting Module Module Contents --------------- .. py:class:: Part(size=None, packed=None, **kwa) Bases: :py:obj:`hio.hioing.Mixin` Base class for packet part classes with .packed .size and len .. py:property:: size Property size .. py:method:: show() Returns descriptive string for display purposes .. py:class:: PackerPart(fmt=None, raw=None, **kwa) Bases: :py:obj:`Part` Base class for packet packer part classes with .packer and .fmt .fmt is the struct string format for the fixed size portion of part .. py:method:: verifySize(raw=bytearray(b'')) Return True if len(raw) is at least long enough for packed size .. py:method:: parse(raw) Parse raw bytearray and assign to fields Return offset into raw of unparsed portion Base method to be overridden in subclass .. py:method:: pack(**kwa) Return .packed with data if any Base method to be overridden in sub class .. py:class:: PackifierPart(fmt=None, raw=None, **kwa) Bases: :py:obj:`Part` Base class for packet packifier part classes with packify .fmt .fmt is the packify string format for the fixed size portion of part packify allows bit field packing packify/unpackify format is string of white space separated bit field lengths The packed values are provided as sequence of bit field values that are packed into bytearray of size bytes using fmt string. Each white space separated field of fmt is the length of the associated bit field If not provided size is the least integer number of bytes that hold the fmt. If reverse is true reverse the order of the bytes in the byte array before returning. This is useful for converting between bigendian and littleendian. Assumes unsigned fields values. Assumes network big endian so first fields element is high order bits. Each field in format string is number of bits for the associated bit field. Fields with length of 1 are treated as having boolean truthy field values that is, nonzero is True and packs as a 1. For 2+ length bit fields the field element is truncated to the number of low order bits in the bit field. If sum of number of bits in fmt less than size bytes then the last byte in the bytearray is right zero padded. If sum of number of bits in fmt greater than size bytes returns exception. to pad just use 0 value in source field. Example:: packify("1 3 2 2", (True, 4, 0, 3)). returns bytearry([0xc3]) .. py:property:: fmtSize Property fmtSize .. py:method:: verifySize(raw=bytearray(b'')) Return True if len(raw) is at least long enough for formatted size .. py:method:: parse(raw) Parse raw bytearray and assign to fields Return offset into raw of unparsed portion Base method to be overridden in subclass .. py:method:: pack(**kwa) Return .packed with data if any Base method to be overridden in sub class .. py:method:: show() Returns descriptive string for display purposes .. py:class:: PacketPart(packet=None, **kwa) Bases: :py:obj:`Part` PacketPart base class for parts of packets. Allows PacketPart to reference other parts of its Packet .. py:method:: show() Returns descriptive string for display purposes .. py:class:: Packet(stack=None, **kwa) Bases: :py:obj:`Part` Packet base class Allows packet to reference its stack .. py:method:: parse(raw) Parse raw data into .packed .. py:method:: pack() Pack into .packed