Initial: 2003-09-12
Modified: 2003-09-12

MRPT 0.2.1

MRPT 0.1 was not satisfactory, I will define MRPT 0.2. MRPT will not have a fixed type system, the type system may be extended as needed. The type system will try to be much more simplistic than other MRP type protocols.
MRPT 0.2.1: Changing general encoding a bit.

MRPT Base Encoding

This encoding will borrow some ideas from ASN.1.
Both types and semantic objects will be included in the type system.
ASN.1 may be considered as a possible encoding.

Each object will begin with a 2 byte tag:

The the top 2 bits of the first byte will be a class:
0: base types;
1: implementation types;
2: context specific types;
3: dynamic types.

the next bit will specify whether it is a primitive or compound type:
0: primitive;
1: compound.

the next 3 bits are reserved and will be set to 0.

the lower 2 bits and the next byte together will form a 10 bit tag (with the next byte being the lower 8).

The tag is followed by a VLI num. Each byte in a VLI num has the MSB set to 1 to indicate a subsequent byte comprising lower bits, otherwise the byte is considered as being terminal (holds the lowest 7 bits). An encoder is allowed to insert pad bytes (0x80) if so needed.
This number indicates the length of the following data, with the meaning of the data depending on the type.

For primitive objects the contents will be raw data, with a meaning only explained by the type.
For compound objects the contents will be an array of objects.

There is to be no padding between objects.

Length fields make it easier for the decoder to determine if an entire structure is present and to allocate temporary storage.
As a cost of using lengths, it will be necessary that an encoder make use of buffers (or forward-predict the size of the data).

MRPT Base Types

These will be generally required for MRPT conformance, Implementation extension types are allowed as well, however it is required that an implementation verify that the other end knows/sends the same types as it (as to avoid interpreting invalid/garbage when dealing with an unknown implementation).
Implementation types are allowed to be fixed on both the sender and reciever, wheras dynamic types are allowed to vary (but will likely be fixed from the point of view of the sender), but are required to be variable for the reciever.

Unless stated otherwise all multibyte integers are to be interpreted as 2's complement big-endian ("Network Byte Order"). All floating point values are to follow the IEEE encoding and also be in big-endian ordering.


Tag Value
Negotiation String.
Reserved for primitive protocol types.
Reserved for compound protocol types.
Integer(value), required to have a power of 2 size.
Special(value), single byte {0=false,1=true, 2=null, 3-255 reserved}.
Narrow String(value), 7-bit ascii only.
Wide String(value), UTF-16.
Floating point(value), 4/8 bytes.
Raw Data(value).
Date String(value), 'YYYY-MM-DD', 'YYYY-MM-DD hh:mm:ss', 'YYYY-MM-DD hh:mm:ss.fff'.
Symbolic String (value), UTF-8. If the implementation does not distinguish between strings and symbols or does not support symbols, then this is to be interpreted as a string. This is not to be sent by an implementation which does not distinguish symbols/strings.
Reserved for MRPT primitive values.


Tag Value
Reserved for primitive protocol types.
Call, Contents are a: Method-ID (String or Implementation Dependant Integer); Arguments (Array); and, an Id-Value (Integer).
Return, Contents are a return value, and the Id-Value from the call.
Error, Contents are the Id-Value and an Error-String.
Pass, Contents are a: Method-ID (String or Implementation Dependant Integer); Arguments (Array). A pass is a call that does not return a value.
Reserved for compound protocol types.
Reserved for MRPT primitive values.
Array(value) of values.
Structure(value), Contents are an array of name strings and value objects.

Establishing Connections

MRPT will by default use port 7937.
On connection the client is to write the raw string "MRPTID", and the server is to respond with "MRPTOK". The connection is to be closed if any other values are recieved, or if a response is not recieved within "a reasonable amount of time".

Negotiation strings can be sent to request/declare information to the other end of the node, each will have the form 'C...', where C is a special key character. '<' and '>' are used to indicate variables embedded in the form, they do not appear in the transmission of the string.
Any unknown negotiation strings are to be ignored. The connection is to be closed if unacceptable values can't be reached.
Request the value of the variable on the other end.
=<var> <val>
Response to a request for a value/assignment.
!<var> <val>
Try to assign a value on the other end.
Try to enable an extension.
Extension Enabled.
F<ext> <reason...>
Extension Failed, reason is an implementation dependant string.
K<hhhh> <name>
hhhh is the hex form of a tag value, name is the name of the tag. This is a possible response of enabling extensions.

Variable/extension names will be viewed as implementation dependant.
Implementation dependant extensions should have a name of the form:
'<implementation>-<extension>' or '<creator>-<extension>'. '<creator>-<implementation>-<extension>' may be used if names may collide within projects of the same creator.

An implementation may not enable/negotiate an extension it does not support.