UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

90 lines (89 loc) 3.7 kB
import { Writer } from '@jsonjoy.com/util/lib/buffers/Writer'; export declare class CrdtWriter extends Writer { /** * In the below encoding diagrams bits are annotated as follows: * * - "x" - vector table index, reference to the logical clock. * - "y" - time difference. * - "?" - whether the next byte is used for encoding. * * If x is less than 8 and y is less than 16, the relative ID is encoded as a * single byte: * * ``` * +--------+ * |0xxxyyyy| * +--------+ * ``` * * Otherwise the top bit of the first byte is set to 1; and x and y are encoded * separately using b1vuint28 and vuint39, respectively. * * ``` * x y * +===========+=========+ * | b1vuint28 | vuint39 | * +===========+=========+ * ``` * * The boolean flag of x b1vuint28 value is always set to 1. */ id(x: number, y: number): void; /** * #### `vu57` * * `vu57` stands for *variable length unsigned 57 bit integer*. It consumes * up to 8 bytes. The maximum size of the decoded value is 57 bits. * * The high bit `?` of each octet indicates if the next byte should be * consumed, up to 8 bytes. When `?` is set to `0`, it means that the current * byte is the last byte of the encoded value. * * ``` * byte 1 byte 2 byte 3 byte 4 byte 5 byte 6 byte 7 byte 8 * +--------+........+........+........+........+........+........+········+ * |?zzzzzzz|?zzzzzzz|?zzzzzzz|?zzzzzzz|?zzzzzzz|?zzzzzzz|?zzzzzzz|zzzzzzzz| * +--------+........+........+........+........+........+........+········+ * * 11111 2211111 2222222 3333332 4443333 4444444 55555555 * 7654321 4321098 1098765 8765432 5432109 2109876 9876543 76543210 * | | | | * 5th bit of z | | | * 28th bit of z | 57th bit of z * 39th bit of z * ``` * * @param num Number to encode as variable length unsigned 57 bit integer. */ vu57(num: number): void; /** * #### `b1vu56` * * `b1vu56` stands for: 1 bit flag followed by variable length unsigned 56 bit integer. * It consumes up to 8 bytes. * * The high bit "?" of each byte indicates if the next byte should be * consumed, up to 8 bytes. * * - f - flag * - z - variable length unsigned 56 bit integer * - ? - whether the next byte is used for encoding * * ``` * byte 1 byte 8 * +--------+........+........+........+........+........+........+········+ * |f?zzzzzz|?zzzzzzz|?zzzzzzz|?zzzzzzz|?zzzzzzz|?zzzzzzz|?zzzzzzz|zzzzzzzz| * +--------+........+........+........+........+........+........+········+ * * 1111 2111111 2222222 3333322 4433333 4444444 55555554 * 654321 3210987 0987654 7654321 4321098 1098765 8765432 65432109 * | | | | * 5th bit of z | | | * 27th bit of z | 56th bit of z * 38th bit of z * ``` * * @param num Number to encode as variable length unsigned 56 bit integer. */ b1vu56(flag: 0 | 1, num: number): void; }