Primitive Types¶
Primitive data types and bit string representations used in the DNP3 object library.
This module defines the canonical mappings between DNP3’s primitive object types and Python equivalents (e.g., UINT8, INT32, FLT32). It also includes implementations for bit string objects (BSTRn, DBSTRn) as described in section 11.3.3 of the DNP3 specification.
Two kinds of bit string encodings are implemented:
BSTRn: Packed bit strings, where each bit represents a boolean value.
DBSTRn: Double-bit strings, where each pair of bits encodes a double-bit state (used, for example, to represent binary inputs with intermediate states).
Note
These types are used internally by the unpacking and packing mechanisms when parsing or constructing DNP3 Application Layer objects.
- icspacket.proto.dnp3.objects.primitive.UINT8 = <int8>¶
8-bit unsigned integer.
- icspacket.proto.dnp3.objects.primitive.UINT16 = <int16>¶
16-bit unsigned integer.
- icspacket.proto.dnp3.objects.primitive.UINT24 = <uint24>¶
24-bit unsigned integer.
- icspacket.proto.dnp3.objects.primitive.UINT32 = <int32>¶
32-bit unsigned integer.
- icspacket.proto.dnp3.objects.primitive.INT16 = <int16>¶
16-bit signed integer.
- icspacket.proto.dnp3.objects.primitive.INT32 = <int32>¶
32-bit signed integer.
- icspacket.proto.dnp3.objects.primitive.VSTR¶
Variable-length string.
- icspacket.proto.dnp3.objects.primitive.OSTR¶
Octet string (arbitrary-length byte sequence).
- icspacket.proto.dnp3.objects.primitive.FLT32 = <float32>¶
32-bit IEEE-754 floating point.
- icspacket.proto.dnp3.objects.primitive.FLT64 = <float64>¶
64-bit IEEE-754 floating point.
- class icspacket.proto.dnp3.objects.primitive.BCD(count: int)[source]¶
Binary-coded decimal (BCD) type.
Implements DNP3 section 11.3.6: Binary-coded decimal values use the notation BCDn, where ``n`` represents the number of BCD characters. For example, ``BCD8`` requires 8 BCD characters.
Each BCD character is stored in 4 bits (a nibble). Two characters are packed into a single byte in little-endian order.
- decode(parsed: bytes, context) str[source]¶
Encode a string of decimal digits into BCD bytes.
- Parameters:
obj (str) – The decimal string to encode. A ‘-’ character may be used to represent a nibble value of 10.
context (Any) – Transformation context (unused in this implementation).
- Returns:
Encoded BCD bytes.
- Return type:
bytes
- class icspacket.proto.dnp3.objects.primitive.BSTRn[source]¶
Packed bit string (BSTRn) representation.
This class implements the parsing and serialization of packed bit strings used in DNP3 objects. Each bit encodes a boolean value, with the least significant bit occupying the lowest bit position in a field.
For example, a 10-bit bit string will be encoded into 2 octets. When unpacked, it is represented as a
bitarray.bitarraywith little-endian ordering.
- class icspacket.proto.dnp3.objects.primitive.DBSTRn[source]¶
Double-bit string (DBSTRn) representation.
This class implements parsing and serialization of double-bit strings, where each pair of bits encodes a state. For example:
00→ intermediate or indeterminate state01→ determined OFF10→ determined ON11→ reserved
Each octet encodes four double-bit values.
Internally, unpacked values are represented as lists of integers.