💾 Archived View for vierkantor.com › xukut › manual › swail › serialization.gmi captured on 2024-05-10 at 10:35:09. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

XukutOS manual → Swail → Serialization

For now, serialization works very simply: to serialize an object, generate code that will load that object back into memory. To load an object, simply execute the code. To make this slightly less ridiculously unsafe, we limit the allowed constructs, so that we're really executing the code in a small interpreter.

The overall structure is line-based for easier parsing. Each line starts with a command, which is a sequence of non-whitespace printing characters, followed by some data, and is finished by a `\n' character, i.e. a byte with value 0x0a. (The last line should also have a `\n'!) You can refer back to the result of an earlier command by counting back a number of lines. So a backref of 0 refers to the output of the current line (if that makes sense), a backref of 1 to the line before that, etc.

Empty lines are skipped; they are not counted for backrefs.

`swail:bin <n = [0-9]+> <data = .*>'

Binary data, given as a count of bytes `n' followed by that amount of bytes. The data can contain any bytes, including newlines. The newline character must come exactly after the end of the data, to prevent tampering.

`swail:cons <head = backref> <tail = backref>'

Create a new cons cell with the results of deserializing <head> resp. <tail>.

`swail:done <data = backref>'

Just the same as the object from the backref. This is useful for indicating the end of a transmission in stream-based protocols: when a `swail:done' command arrives through the stream, the object it represents can be handed to the part that processes the objects being streamed (such as a message handler).

Apart from this special meaning, this works just like a normal command, so subsequent commands can backref to this command (thereby backreferencing the `data' that is referenced by the `done' command in turn).

`swail:int <val = -?[0-9]+>'

Numbers are represented by a series of decimal digits `val', negated if it starts with a `-' sign.

`swail:span <data = backref> <begin = [0-9]+> <size = [0-9]+>'

Create a span filled with `data[begin:begin+size['.

`swail:str <encoding = backref> <data = backref>'

Create a string with the given encoding and data. The encoding is specified as binary data (encoded in ASCII by default), and can be one of:

* "ascii": ASCII encoding, one byte per codepoint.

The data is specified as a span.

`swail:tuple <n = [0-9]+> <elem0 = backref> <elem1 = backref> ... <elemn = backref>'

Create a tuple of given length and elements.

Any questions? Contact me:

By email at vierkantor@vierkantor.com

Through mastodon @vierkantor@mastodon.vierkantor.com

XukutOS user's manual: Swail

XukutOS user's manual

XukutOS main page