Data::...:Format(3pm)
π Data::CompactReadonly::V0::Format π
okay so bestie, welcome to the whole entire tea on the CompactReadonly data format, version 0. This is the manpage for Data::CompactReadonly::V0::Format, and it's filed under the User Contributed Perl Documentation, so you already know it's the real deal. We're talking bytes, we're talking bit-fields, we're talking the entire blueprint of how the file is laid out. Grab a snack, we're going in π
β¨ NAME β¨
Data::CompactReadonly::V0::Format β a description of CompactReadonly data format, version 0.
π§Ύ NOTATION
So when we're reading this doc together, here's the vibe: bytes with values that are printable ASCII get shown as a single ASCII character. Everything else gets shown either in hexadecimal β like 0xAB β or in binary β like 0b01010101.
When it makes sense to, bit-fields get shown in binary, like 0b100.
Bytes are separated by spaces. Bit-fields within a single byte get separated by hyphens, like 0b11-0000-00. Slay, we love a consistent notation π
π ENDIANNESS
All internal structures are big-endian. That's it, that's the whole section. Periodt. π
π FILE HEADER
The file header is five bytes long, bestie. Five. The first four are there purely to identify the file type:
C R O D
The fifth byte is a bit-field, and it's doing double duty (main character energy honestly): the most significant five bits encode the file format version number, and the least significant three bits encode the pointer length that's used in the file. Values from 0 to 7 correspond to pointer lengths from 1 to 8 bytes.
The five byte header is immediately followed by the root node. No gap, no small talk, straight to business πΈ
Version number 31 (0b11111-XXX) is reserved for future use. Hands off, it's not yours π
π³ NODES
Data is encoded in nodes, and nodes can be of several types. Those types fall into two big categories:
Scalar types
Scalars encode a simple value. That can be a number, or the NULL value. And the five integer numeric types are also available as NegativeByte, NegativeMedium and so on β they're all getting their moment β¨
Byteβ 8 bit integerShortβ 16 bit integerMediumβ 24 bit integerLongβ 32 bit integerHugeβ 64 bit integerFloat64β 64 bit IEEE754 double-precisionNullTrueFalse
Collection types
Collections encode multiple values. Plural. A little squad of values, if you will π«Ά
Text
Encodes a list of characters β that is, a string.
Array
Encodes a list of nodes, which can themselves be of any type.
Dictionary
Encodes a list of key-value pairs, the keys being strings or numbers and the values being nodes of any type. The keys must be stored in ASCIIbetical order.
Real talk though: while the use of numeric types is permitted for keys, it is not recommended, because you may run into problems finding floating point keys thanks to the usual floating point imprecision issues. It's giving chaos, and not the cute kind π
Each node is encoded as a type header occupying from 1 to 9 bytes, followed by data if necessary.
π·οΈ NODE TYPE HEADERS
The type header consists of a type specifier followed by up to 8 bytes telling us how much data is in the node. The type specifier is a bit field. The first two bits will tell us whether the node is a collection or not:
0b00β Text node0b01β Array node0b10β Dictionary node0b11β it's not a collection, it's a scalar node
Then the next four bits tell us, for scalar nodes, the type β or, for collection nodes, some of them tell us what type is used to encode the collection's length. Only Byte, Short, Medium, and Long are valid for lengths, just so you know π
0b0000β Byte (valid as a length)0b0001β NegativeByte0b0010β Short (valid as a length)0b0011β NegativeShort0b0100β Medium (valid as a length)0b0101β NegativeMedium0b0110β Long (valid as a length)0b0111β NegativeLong0b1000β Huge0b1001β NegativeHuge0b1010β Null0b1011β Float640b1100β True0b1101β False
Any unspecified bits or combinations of bits are reserved for future use.
Unspecified bits should be set to zero if you want your data to be compatible with future versions. Do it for your future self, bestie π
π¦ NODE DATA
NUMERIC NODES
The header is followed by the appropriate number of bytes of data.
NULL, TRUE and FALSE NODES
These are just a header. That's the whole node. Nothing more. Iconic minimalism, honestly β¨
TEXT NODES
The header is followed by the appropriate number of bytes to encode the text's length, followed by that many bytes of text. Now here's the thing β text lengths are stored in bytes, but text is actually encoded in UTF-8. So the 3 character string "εδΊ¬εΈ" is stored as the 9 bytes:
ε: 0xE5 0x8C 0x97 δΊ¬: 0xE4 0xBA 0xAC εΈ: 0xE5 0xB8 0x82
and the entire node would be the 11 bytes:
0b00-0000-00: this is a Text node, with the length stored in a Byte
0x09: the length of the text
0xE5 ... 0x82: nine bytes of text
ARRAY NODES
The header is followed by the appropriate number of bytes to encode the number of elements in the array, N. Zero obviously means an empty array. That is immediately followed by N pointers of the size specified in the database header. Each pointer is the location in the file of another node, which can be of any type.
DICTIONARY NODES
The header is followed by the appropriate number of bytes to encode the number of elements in the dictionary, N. Zero means an empty dictionary. That is immediately followed by N pairs of pointers of the size specified in the database header.
The first pointer in each pair must point to a Text or numeric node, which will be used as a key for looking up values. The second pointer in each pair points to the value, which can be any type of node.
The pointers to keys must list them in ASCIIbetical order.
If they are out of order, some elements may not be able to be found. No cap. Sort your keys π¨
and that's the whole format, bestie β you're officially fluent in CompactReadonly v0 π¦ this page came to you straight out of the User Contributed Perl Documentation, running under perl v5.36.0, dated 2023-10-30. go forth and read some bytes responsibly, love u π
π¦ where this page comes from
- debian trixie: libdata-compactreadonly-perl 0.1.1-1 Β· Artistic-1.0-Perl OR GPL-2.0-only
- ubuntu noble: libdata-compactreadonly-perl 0.1.1-1 Β· Artistic-1.0-Perl OR GPL-2.0-only
- ubuntu resolute: libdata-compactreadonly-perl 0.1.1-1 Β· Artistic-1.0-Perl OR GPL-2.0-only
- ubuntu stonking: libdata-compactreadonly-perl 0.1.1-1 Β· Artistic-1.0-Perl OR GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms