The pyro wire protocol message.
Pyro write protocol message.
Wire messages contains of a fixed size header, an optional set of annotation chunks, and then the payload data. This class doesn’t deal with the payload data: (de)serialization and handling of that data is done elsewhere. Annotation chunks are only parsed, except the ‘HMAC’ chunk: that is created and validated because it is used as a message digest.
The header format is:
4 id ('PYRO')
2 protocol version
2 message type
2 message flags
2 sequence number
4 data length
2 data serialization format (serializer id)
2 annotations length (total of all chunks, 0 if no annotation chunks present)
2 (reserved)
2 checksum
After the header, zero or more annotation chunks may follow, of the format:
4 id (ASCII)
2 chunk length
x annotation chunk databytes
After that, the actual payload data bytes follow.
The sequencenumber is used to check if response messages correspond to the actual request message. This prevents the situation where Pyro would perhaps return the response data from another remote call (which would not result in an error otherwise!) This could happen for instance if the socket data stream gets out of sync, perhaps due To some form of signal that interrupts I/O.
The header checksum is a simple sum of the header fields to make reasonably sure that we are dealing with an actual correct PYRO protocol header and not some random data that happens to start with the ‘PYRO’ protocol identifier.
An ‘HMAC’ annotation chunk contains the hmac digest of the message data bytes and all of the annotation chunk data bytes (except those of the HMAC chunk itself).
Parses a message header. Does not yet process the annotations chunks and message data.
returns the hmac of the data and the annotation chunk values (except HMAC chunk itself)
Receives a pyro message from a given connection. Accepts the given message types (None=any, or pass a sequence). Also reads annotation chunks and the actual payload data. Validates a HMAC chunk if present.
creates a byte stream containing the header followed by annotations (if any) followed by the data
The various message types
Various flags that modify the characteristics of the message