dhcpkit_kafka.messages module

Messages that are sent over Kafka

class dhcpkit_kafka.messages.DHCPKafkaMessage(server_name: str = '', timestamp_in: Union[int, float] = 0, message_in: dhcpkit.ipv6.messages.Message = None, timestamp_out: Union[int, float] = 0, message_out: dhcpkit.ipv6.messages.Message = None)[source]

Bases: dhcpkit_kafka.messages.KafkaMessage

A message for publishing DHCPv6 messages over Kafka for analysis.

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    msg-type   |   name-len    |                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               .
.                 server-name (variable length)                 .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         timestamp-in                          |
|                        (double float)                         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                          message-in                           .
.                      (variable length)                        .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         timestamp-out                         |
|                        (double float)                         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                          message-out                          .
.                      (variable length)                        .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
load_from(buffer: bytes, offset: int = 0, length: int = None) → int[source]

Load the internal state of this object from the given buffer.

Parameters:
  • buffer – The buffer to read data from
  • offset – The offset in the buffer where to start reading
  • length – The amount of data we are allowed to read from the buffer
Returns:

The number of bytes used from the buffer

message_type = 1
save() → Union[bytes, bytearray][source]

Save the internal state of this object as a buffer.

Returns:The buffer with the data from this element
validate()[source]

Validate that the contents of this object

class dhcpkit_kafka.messages.KafkaMessage[source]

Bases: dhcpkit.protocol_element.ProtocolElement

The base class for Kafka messages.

classmethod determine_class(buffer: bytes, offset: int = 0) → type[source]

Return the appropriate subclass from the registry, or UnknownClientServerMessage if no subclass is registered.

Parameters:
  • buffer – The buffer to read data from
  • offset – The offset in the buffer where to start reading
Returns:

The best known class for this message data

message_type = 0
class dhcpkit_kafka.messages.UnknownKafkaMessage(message_type: int = 0, message_data: bytes = b'')[source]

Bases: dhcpkit_kafka.messages.KafkaMessage

Container for raw message content for cases where we don’t know how to decode the message.

load_from(buffer: bytes, offset: int = 0, length: int = None) → int[source]

Load the internal state of this object from the given buffer. The buffer may contain more data after the structured element is parsed. This data is ignored.

Parameters:
  • buffer – The buffer to read data from
  • offset – The offset in the buffer where to start reading
  • length – The amount of data we are allowed to read from the buffer
Returns:

The number of bytes used from the buffer

save() → Union[bytes, bytearray][source]

Save the internal state of this object as a buffer.

Returns:The buffer with the data from this element
validate()[source]

Validate that the contents of this object conform to protocol specs.