LLEncoding

Introduction

High level network encoding (over TCP, UDP, ...) to exchange data.

Goals:

Good implementation (with duck typed programming languages) will permit to send and receive (flat) arrays.

Motivations

In most text protocols, we receive a chunk of network bytes and check for ending valuee (like CR, CR-LF, empty lines or a 'dot only' lines (like in SMTP).

If the received chunk is not yet complete, we need to store it (bufferring) and wait for more data.

In general, it's more interesting to know about how many data we will receive, and to let the low level socket part wait for the right amount of data before continuing the 'normal' execution. It's the goal of this protocol.

This encoding is perfect for all message/block passing applications.

Technical description

The LLenc will code in the first byte, the length of the length of the successive datum (except for case 1).

ASCII Values:

1 49 ('1') to 57 ('9') Base 1 (values from 1 to 9)
2 65 ('A')- 90 ('Z') Base 10 (values from 10 to 10^26-1)

The choice of the base, depend of the length we must encode. When the first choice is no more possible, we skip to the next one. The goal is to be short and easily readable (in base 256, things are no more readable).

If we need to encode a datum of a length < 10, we use:

<L (1 byte [1-9]), length of datum> <DATUM>

If value is bigger than 9 chars, we use:

<L1 (1 byte [A-Z]), length of L2> <L2 (L1 byte(s), length of datum> <DATUM>

Examples

Example 1

You want to send "hello":

"hello".length() -> 5
(5 < 10) -> mode 1
LLenc:
5Hello

Example 2

You want to send "LLenc is great.":

"LLenc is great".length() => 14
(14 >= 10) -> mode 2
14.length() -> 2 -> 'B'
LLenc:
B14LLenc is great

Example 3

Send:
socket.send("data")
socket.send("A longer string")

LLenc:
4dataB16A longer string

Receive:
data = socket.receive()
string = socket.receive()

FAQ

Q: What means the name ?

LLEnc will mean LengthLengthEncoding or LorenzoLeoniniEncoding, the name of his author.

Implementations

Lua
Ruby