hio.core.packeting

hio.core.packeting Module

Module Contents

class hio.core.packeting.Part(size=None, packed=None, **kwa)

Bases: hio.hioing.Mixin

Base class for packet part classes with .packed .size and len

property size

Property size

show()

Returns descriptive string for display purposes

class hio.core.packeting.PackerPart(fmt=None, raw=None, **kwa)

Bases: 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

verifySize(raw=bytearray(b''))

Return True if len(raw) is at least long enough for packed size

parse(raw)

Parse raw bytearray and assign to fields Return offset into raw of unparsed portion Base method to be overridden in subclass

pack(**kwa)

Return .packed with data if any Base method to be overridden in sub class

class hio.core.packeting.PackifierPart(fmt=None, raw=None, **kwa)

Bases: 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])
property fmtSize

Property fmtSize

verifySize(raw=bytearray(b''))

Return True if len(raw) is at least long enough for formatted size

parse(raw)

Parse raw bytearray and assign to fields Return offset into raw of unparsed portion Base method to be overridden in subclass

pack(**kwa)

Return .packed with data if any Base method to be overridden in sub class

show()

Returns descriptive string for display purposes

class hio.core.packeting.PacketPart(packet=None, **kwa)

Bases: Part

PacketPart base class for parts of packets. Allows PacketPart to reference other parts of its Packet

show()

Returns descriptive string for display purposes

class hio.core.packeting.Packet(stack=None, **kwa)

Bases: Part

Packet base class Allows packet to reference its stack

parse(raw)

Parse raw data into .packed

pack()

Pack into .packed