kitty.model.low_level.encoder module

Encoders are used for encoding fields and containers. The encoders are passed as an argument to the fields/container, during the field rendering, the encoder’s encode method is called.

There are four families of encoders:

Bits Encoders:Used to encode fields/containers that their value is of type Bits (Container, ForEach etc.)
String Encoders:
 Used to encode fields that their value is of type str (String, Delimiter, RandomBytes etc.)
BitField Encoders:
 Used to encode fields that inherit from BitField or contain BitField (UInt8, Size, Checksum etc.) Those encoders are also refferred to as Int Encoders.
FloatingPoint Encoders:
 Used to encode fields that inherit from FloatingPoint field (Float, Double) Those encoders are also refferred to as Float Encoders
class kitty.model.low_level.encoder.BitFieldAsciiEncoder(fmt)[source]

Bases: kitty.model.low_level.encoder.BitFieldEncoder

Encode int as ascii

__init__(fmt)[source]
Parameters:fmt – format for encoding (from BitFieldAsciiEncoder.formats)
encode(value, length, signed)[source]
formats = ['%d', '%x', '%X', '%#x', '%#X']
class kitty.model.low_level.encoder.BitFieldBinEncoder(mode)[source]

Bases: kitty.model.low_level.encoder.BitFieldEncoder

Encode int as binary

__init__(mode)[source]
Parameters:mode (str) – mode of binary encoding. ‘le’ for little endian, ‘be’ for big endian, ‘’ for non-byte aligned
encode(value, length, signed)[source]
Parameters:
  • value – value to encode
  • length – length of value in bits
  • signed – is value signed
class kitty.model.low_level.encoder.BitFieldEncoder[source]

Bases: object

Base encoder class for BitField values

Singleton Name Encoding Class
ENC_INT_BIN Encode as binary bits BitFieldBinEncoder
ENC_INT_LE Encode as a little endian binary bits
ENC_INT_BE Encode as a big endian binary bits
ENC_INT_DEC Encode as a decimal value BitFieldAsciiEncoder
ENC_INT_HEX Encode as a hex value
ENC_INT_HEX_UPPER Encode as an upper case hex value
ENC_INT_DEFAULT Same as ENC_INT_BIN BitFieldBinEncoder
encode(value, length, signed)[source]
Parameters:
  • value (int) – value to encode
  • length (int) – length of value in bits
  • signed (boolean) – is value signed
class kitty.model.low_level.encoder.BitFieldMultiByteEncoder(mode='be')[source]

Bases: kitty.model.low_level.encoder.BitFieldEncoder

Encode int as multi-byte (used in WBXML format)

__init__(mode='be')[source]
Parameters:mode (str) – mode of binary encoding. ‘le’ for little endian, ‘be’ for big endian, ‘’ for non-byte aligned
encode(value, length, signed)[source]
Parameters:
  • value – value to encode
  • length – length of value in bits
  • signed – is value signed
class kitty.model.low_level.encoder.BitsEncoder[source]

Bases: object

Base encoder class for Bits values

The Bits encoders encode function receives a Bits object as an argument and returns an encoded Bits object.

Singleton Name Encoding Class
ENC_BITS_NONE None, returns the same value received BitsEncoder
ENC_BITS_BYTE_ALIGNED Appends bits to the received object to make it byte aligned ByteAlignedBitsEncoder
ENC_BITS_REVERSE Reverse the order of bits ReverseBitsEncoder
ENC_BITS_BASE64 Encode a Byte aligned bits in base64 StrEncoderWrapper
ENC_BITS_BASE64_NO_NL Encode a Byte aligned bits in base64, but removes the new line from the end
ENC_BITS_UTF8 Encode a Byte aligned bits in UTF-8
ENC_BITS_HEX Encode a Byte aligned bits in hex
ENC_BITS_DEFAULT Same as ENC_BITS_NONE  
encode(value)[source]
Parameters:value (Bits) – value to encode
class kitty.model.low_level.encoder.BitsFuncEncoder(func)[source]

Bases: kitty.model.low_level.encoder.BitsEncoder

Encode bits using a given function

__init__(func)[source]
Parameters:func – encoder function(Bits)->Bits
encode(value)[source]
class kitty.model.low_level.encoder.ByteAlignedBitsEncoder[source]

Bases: kitty.model.low_level.encoder.BitsEncoder

Stuff bits for byte alignment

encode(value)[source]
Parameters:value – value to encode
class kitty.model.low_level.encoder.FloatAsciiEncoder(fmt)[source]

Bases: kitty.model.low_level.encoder.FloatEncoder

Encode a floating point number in ascii as described by IEEE 754 (decimal*)

__init__(fmt)[source]
Parameters:fmt (str) – format of ascii encoding (see floating point encoding in string docs.)
encode(value)[source]
Parameters:value – value to encode
class kitty.model.low_level.encoder.FloatBinEncoder(fmt)[source]

Bases: kitty.model.low_level.encoder.FloatEncoder

Encode a floating point number in binary format as described by IEEE 754 (binary32 and binary64)

__init__(fmt)[source]
Parameters:fmt (str) – format of binary encoding (see floating point encoding in struct docs.)
encode(value)[source]
Parameters:value – value to encode
class kitty.model.low_level.encoder.FloatEncoder[source]

Bases: object

Base encoder class for FloatingPoint values

Singleton Name Encoding Class
ENC_FLT_LE Encode as a little endian 32 bit FloatBinEncoder
ENC_FLT_BE Encode as a big endian 32 bit
ENC_DBL_LE Encode as a little endian 64 bit
ENC_DBL_BE Encode as a big endian 64 bit
ENC_FLT_FP Fixed point FloatAsciiEncoder
ENC_FLT_EXP Exponent notation
ENC_FLT_EXP_UPPER Exponent notation, with upper case E
ENC_FLT_GEN General format
ENC_FLT_GEN_UPPER General format, with upper case
ENC_FLT_DEFAULT Same as ENC_FLT_BE FloatBinEncoder
encode(value)[source]
Parameters:value (float) – value to encode
Return type:Bits
Returns:encoded value in bits
class kitty.model.low_level.encoder.ReverseBitsEncoder[source]

Bases: kitty.model.low_level.encoder.BitsEncoder

Reverse the order of bits

encode(value)[source]
Parameters:value – value to encode
class kitty.model.low_level.encoder.StrBase64NoNewLineEncoder[source]

Bases: kitty.model.low_level.encoder.StrEncoder

Encode the string as base64, but without the new line at the end

encode(value)[source]
Parameters:value – value to encode
class kitty.model.low_level.encoder.StrEncodeEncoder(encoding)[source]

Bases: kitty.model.low_level.encoder.StrEncoder

Encode the string using str.encode function

__init__(encoding)[source]
Parameters:encoding (str) – encoding to be used, should be a valid argument for str.encode
encode(value)[source]
Parameters:value – value to encode
class kitty.model.low_level.encoder.StrEncoder[source]

Bases: object

Base encoder class for str values The String encoders encode function receives a str object as an argument and returns an encoded Bits object.

Singleton Name Encoding Class
ENC_STR_UTF8 Encode the str in UTF-8 StrEncodeEncoder
ENC_STR_HEX Encode the str in hex
ENC_STR_BASE64 Encode the str in base64
ENC_STR_BASE64_NO_NL Encode the str in base64 but remove the new line from the end StrBase64NoNewLineEncoder
ENC_STR_DEFAULT Do nothing, just convert the str to Bits object StrEncoder
encode(value)[source]
Parameters:value (str) – value to encode
class kitty.model.low_level.encoder.StrEncoderWrapper(encoder)[source]

Bases: kitty.model.low_level.encoder.ByteAlignedBitsEncoder

Encode the data using str.encode function

__init__(encoder)[source]
Parameters:encoding (StrEncoder) – encoder to wrap
encode(value)[source]
Parameters:value – value to encode
class kitty.model.low_level.encoder.StrFuncEncoder(func)[source]

Bases: kitty.model.low_level.encoder.StrEncoder

Encode string using a given function

__init__(func)[source]
Parameters:func – encoder function(str)->str
encode(value)[source]
class kitty.model.low_level.encoder.StrNullTerminatedEncoder[source]

Bases: kitty.model.low_level.encoder.StrEncoder

Encode the string as c-string, with null at the end

encode(value)[source]
Parameters:value – value to encode