Agent protocol

Client and agent talk in a binary protocol of their own. The client speaks first: the agent sends nothing until it gets a request, and then sends one response for each request.

MESSAGES

Every message is a 4-byte big-endian length followed by that many bytes. Those bytes are one object between the characters `[` and `]`.

An object is the character `L`, a type number, a version number, the object's fields in a fixed order, and the character `;`. The type number says what the object is: an open request, a read request, a response to a read. The fields carry no names; the type decides how many there are and what each one means. A field can itself be an object, for example the list of arguments of a subroutine call.

VALUES

Each value starts with a character that says what follows. All numbers are big-endian.

Starts withValue
Ia 4-byte integer
sa string: a 2-byte length, the bytes, then `;`
xa long string: a 4-byte length, the bytes, then `;`
jba block of bytes, such as a record: a 4-byte length, the bytes, then `;;`
Lan object, as above; type number 1 stands for a missing object

Strings and records travel as they are in jBASE, with the attribute, value and subvalue marks (bytes 0xfe, 0xfd and 0xfc) left in. There are no other types: a flag is an integer 0 or 1, a list is a count followed by its elements.

A request to open the file F is these 23 bytes:

     00 00 00 13                 length of what follows: 19
     5b                          [
     4c 49 00 00 00 cd           L, type 205: open a file
     49 00 00 00 00              version 0
     73 00 01 46 3b              the file name "F"
     3b                          end of the object
     5d                          ]

A CONVERSATION

The first request on a connection must be an authentication request with the client's credentials. If it is anything else, or the credentials are wrong, the agent closes the connection without a reply.

Below is a session as the client sees it. Each request is shown with `>` and each response with `<`, as an object name and its fields in order.

     > Authentication{UserCredentials{"user", "password"}}
     < Authentication{2}                          the session's port number
     > OpenFile{"CUSTOMER"}
     < Jedi{1, "", null}                          1: opened
     > WriteRecord{WRITE, "CUSTOMER", "C1", "Smith^London"}
     < Jedi{1, "", null}
     > ReadRecord{READ, "CUSTOMER", "C1"}
     < Jedi{1, "Smith^London", null}              1: found, with the record
     > ReadRecord{READ, "CUSTOMER", "C2"}
     < Jedi{0, "", null}                          0: not found
     > Conv{OCONV, "21523", "D4"}
     < Conv{"04 DEC 2026"}
     > Execute{"COUNT CUSTOMER", null}
     < Execute{SelectList{...}, "^ 1 Records counted ", "407]1]QLNUMCNT"}
     > Subroutine{"ADDONE", Parameters{"41", ""}}
     < Output{"in ADDONE 41"}                     what ADDONE printed with CRT
     < Subroutine{0, Parameters{"41", "42"}}      the arguments after the call

Here ^ and ] stand for the attribute and value marks.

NOTES

A missing record is not an error: the read response carries a status of 0. A request that fails gets an error response with an SQL-style class, a code and a message: an execute request for a command that does not exist gets IE, 011, "Failed to execute command".

The client can ask the agent to compress large messages. A compressed message holds the characters GZIP and a gzip stream between `[` and `]`.

TLS, when the agent is started with -c and -k, covers the whole connection; the protocol inside it is the same.