Block Types and Encoding
About 722 words
The main file consists of MessagePack objects one after another; each top-level object is called a block. The first field of a block, type (item 0 of the array in the Header), is the Type ID, which the reader uses to determine the kind of block.
Type ID
| Type ID (uint16) | Block | MessagePack type | Minimum level requiring reader support |
|---|---|---|---|
0 | Header | Array | Core |
1 | Header Extension | Map | Core |
2 | Canvas | Map | Core |
3 | Ink | Map | Core |
4 | Media | Map | Standard |
5 | Shape | Map | Core |
6 | Clear | Map | Inkeys extension |
Device is a nested Map in the Header Extension registry; it has no Type ID and never appears as a top-level block.
Type IDs 7 and above are reserved for future versions, and UInk defines no private Type IDs: app-private data is written in each block's extra (TYPE-4). A writer must not write an unregistered Type ID; a reader that meets one skips it according to TYPE-9.
type and inkType
The type of an Ink block is always 3; the kind of pen (erase, normal pen, highlighter…) is distinguished by inkType inside the block. There is no separate Eraser block, and there is no penType field.
Writing rules
- TYPE-1 A writer must use the exact MessagePack type and bit width declared in the field table. For example,
uint16must not be written as a positive fixint, andfloat32must not be written as float64. - TYPE-2 The Header must also follow its fixed array layout; see Header Block.
- TYPE-3 When saving again, numeric values accepted tolerantly during reading must be normalized to the type declared in the field table.
- TYPE-4 App-private fields must be placed in the
extraof the Map they belong to and must not be written as unregistered top-level keys.
Reading rules
- TYPE-5 A numeric field may tolerantly accept other MessagePack numeric encodings, but all of the following must hold: both the source value and the target are numeric (
boolis not numeric); the conversion does not change the value (an integer target requires the source value to be an integer, a floating-point target requires the value to be exactly representable); the converted value passes the field's own range check. - TYPE-6
bool,string, Array and Map must not be replaced by other types. - TYPE-7 When any known key appears more than once in the same Map, the whole block containing that Map is invalid.
- TYPE-8 A reader must ignore unknown keys, and unknown keys must not change the meaning of known fields.
- TYPE-9 When a reader meets an unknown Type ID and the object can be decoded completely, the reader must skip it and continue reading the next block; it must not reject the whole file because of it. When the end of the object cannot be determined, stop reading according to the crash recovery rules. Content blocks of future versions may occupy
contentIdnumbers, so a reader must not reject a file becausecontentIdis not consecutive; the drawing order still follows the object stream order. - TYPE-10 When a reader meets a registered block beyond its level (for example, a reader below Standard meets Media), it handles the block as described in the "Fallback" section of that block's page.
Private values
Values 128 and above of each enum field are private values, defined by each app itself. UInk provides no global vendor namespace and has no vendorId; only apps that have agreed on the same meaning in advance can interoperate. When a reader meets an unknown private value, it handles it according to the fallback rules of the corresponding field.
Saving files with unknown content
- TYPE-11 UInk does not require writers to preserve unknown blocks or keys as they are.
- TYPE-12 A file that the app created itself, and whose content it has confirmed it fully understands, may be overwritten directly. A file that was imported from outside, or that contains content the reader does not recognize or support, should by default be saved as a new file; the original file may be overwritten only after the user explicitly confirms that content may be lost.