Skip to content

encoding

3 posts with the tag “encoding”

Sorted as Bytes

A number codec whose bytes compare like the numbers they hold.

An index compares keys as raw bytes, and it does not care that some of those bytes were an integer and some were a double. The thirty-seventh familiar makes that blindness safe: any number, in any of three types, becomes a short string whose byte order is the numeric order, exact down to the last bit of a 64-bit integer.

Bytes You Can Type

A binary blob, rewritten as one big number in an alphabet a human can actually type.

Sooner or later a pile of bytes has to face a human: an id in a URL, a hash in a log line, a key read off a screen and typed into another. Hex is twice too long, base64 carries characters that break in URLs and look alike on paper. The tenth familiar makes bytes typeable by treating the whole blob as one enormous number and rewriting it in a friendlier base.

Packing a UUID

Shrinking a 128-bit id by noticing how much of it is not random.

A UUID is sixteen bytes, and we treat them as sixteen bytes of pure randomness. A time-based UUID is nothing of the sort: it is a timestamp and a clock and a machine id wearing a hex costume, and a stream of them from one server repeats itself enormously. The ninth familiar reads that structure and packs the same id into eight bytes, decoded in nanoseconds and sortable by time.