Skip to content

Request & Response

veltix.network.request.Request

Represents a message to be sent over the network.

Attributes:

Name Type Description
type

Message type defining the purpose

content bytes

Message payload as bytes

request_id str

Unique identifier (auto-generated UUID if not provided)

respond

respond(response: Response)

Update this request's ID to match a received response.

This method is used to correlate a sent request with its corresponding response by updating the request_id to match the response's request_id.

Parameters:

Name Type Description Default
response Response

The Response object received from the network

required

parse staticmethod

parse(data: bytes, max_message_size: int = 10 * 1024 * 1024) -> Response

Parse binary data into a Response object.

Parameters:

Name Type Description Default
data bytes

Raw binary data to parse

required
max_message_size int

Maximum allowed message size (default: 10MB)

10 * 1024 * 1024

Returns:

Name Type Description
Response Response

Parsed response object

Raises:

Type Description
RequestError

If data is invalid or corrupted

compile

compile() -> bytes

Compile Request into wire format for transmission.

Returns:

Type Description
bytes

Complete message as bytes (header + content)

Raises:

Type Description
RequestError

If content exceeds maximum size (4GB)

__repr__

__repr__() -> str

String representation of Request.

veltix.network.request.Response dataclass

Represents a received message with all its metadata.

Attributes:

Name Type Description
type MessageType

Message type

content bytes

Message content as bytes

timestamp int

Send timestamp in milliseconds (from sender's clock)

hash bytes

SHA256 hash of content for integrity verification

received_at int

Receive timestamp in milliseconds (local clock)

request_id str

Unique request identifier (UUID format)

latency property

latency: int

Calculate round-trip latency in milliseconds.

Note: Assumes sender and receiver clocks are synchronized. For accurate latency, use PING/PONG with send_and_wait.