Stream transport layers
Exchange of the data in streams is common abstraction that is provided by most of the transport layers (such as TCP/IP). The important operation to support streams in SHV RPC is to split stream to distinct messages. For this purpose there are two different protocols defined; Block and Serial protocols.
Block
The communication on bidirectional stream where delivery is ensured and checked. The transport layer establishes and maintains point-to-point connection on its own.
Message is transmitted in stream as one complete segment where message length is sent before data. The receiving side first reads size and thus knows how much data it should expect to receive. Message length is encoded as Chainpack unsigned integer.
+--------+------+
| length | data |
+--------+------+
The transport error is detected if there is no byte received from other side for more than 5 seconds during the message transfer.
Transport errors are handled by an immediate disconnect. It is expected that connecting side is able to reestablish connection.
The primary transport layer used with this is TCP/IP, but this also applies to Unix sockets or pair of pipes.
Serial
This is communication over data stream with possible on the line errors (such as data corruption).
The message data is encapsulated in start and stop byte and on link layers without error checking it is also verified with CRC32. The dedicated bytes for this are escaped in the message data.
+-----+------+-----------+---------+
| STX | data | ETX / ATX | *CRC32* |
+-----+------+-----------+---------+
STXstart of message0xA2ETXend of the message0xA3ATXabort the message0xA4ESCescape0xAASTXin data will be coded asESC0x02ETXin data will be coded asESC0x03ATXin data will be coded asESC0x04ESCin data will be coded asESC0x0A
- data - escaped message data
- CRC32 - escaped BigEndian CRC32 of
data(same as used in IEEE 802.3 and known as plain CRC-32) only on channels that do not provide data corruption prevention on its own and only afterETX(not afterATX).
The transport error is detected if there is no byte received from other side for
more than 5 seconds during the message transfer or when STX or ATX is
received before EXT or if CRC32 do not match received data (on channels with
possible corruption such as RS232 and not TCP/IP).
Transport errors do not have to be handled explicitly because any subsequent message can still be consistent. The invalid message should be just dropped.
The primary transport layer is RS232 with hardware flow control, but usage with other streams, such as TCP/IP or Unix domain named socket, is also possible.