mojombo/toml — pull request #170 by amattn (2013-03-06 18:42:40+00:00)
Title: Binary Data Primitives

Starting from the idea that Strings are Strings and Data is Data I have a proposal for handling explicit binary data.

It should be noted that this removes the \x escape characters from strings. Please consider the \u proposal from "Steal from JSON" as well.

From the commit:

Binary Data is represented as a sequence of bytes enclosed with backticks in one of two ways: escaped or encoded. Escaped form is typically for shorter, "readable" data, such as file permissions or bitfields. Encoded is typically used for longer, tool generated blobs of data, such as a favicon.

Escaped data is formatted as a hex, octal or binary sequence of bytes wrapped in single backticks.
No other control characters are allowed (\t, \n etc.). These are bytes, so the binary form must have digits (0 and 1's) in groups of 8, octal digits in groups of 4 and hex digits in groups of 2. If not parsers should produce an error.

ip = `\x0a\x00\x00\xA2` # capitalize as you will
perm = `\o0777`
binary = `\b0000111100001111`
mixed = `\x123456\o12345678\b01010101`

Encoded is base64 encoded string with the following charcteristics:

- `+` and `/` for the character index 62 and 63 respectively
- Padding `=`'s are mandatory
- Linebreak as you like, all whitespace is ignored.

Examples:

# it is easy to paste in from MIME header or other base64 tools

data = ```
TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=
```

# For those times you don't want to waste vertical space

data = ```ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=```