Spaces:
Configuration error
Configuration error
File size: 3,344 Bytes
5641073 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
/**
* @author jdiaz5513
*/
/**
* Compute the Hamming weight (number of bits set to 1) of a number. Used to figure out how many bytes follow a tag byte
* while computing the size of a packed message.
*
* WARNING: Using this with floating point numbers will void your warranty.
*
* @param {number} x A real integer.
* @returns {number} The hamming weight (integer).
*/
export declare function getHammingWeight(x: number): number;
export declare type byte = number;
/**
* Compute the tag byte from the 8 bytes of a 64-bit word.
*
* @param {byte} a The first byte.
* @param {byte} b The second byte.
* @param {byte} c The third byte.
* @param {byte} d The fourth byte.
* @param {byte} e The fifth byte.
* @param {byte} f The sixth byte.
* @param {byte} g The seventh byte.
* @param {byte} h The eighth byte (phew!).
* @returns {number} The tag byte.
*/
export declare function getTagByte(a: byte, b: byte, c: byte, d: byte, e: byte, f: byte, g: byte, h: byte): number;
/**
* Efficiently calculate the length of a packed Cap'n Proto message.
*
* @export
* @param {ArrayBuffer} packed The packed message.
* @returns {number} The length of the unpacked message in bytes.
*/
export declare function getUnpackedByteLength(packed: ArrayBuffer): number;
/**
* Compute the number of zero bytes that occur in a given 64-bit word, provided as eight separate bytes.
*
* @param {byte} a The first byte.
* @param {byte} b The second byte.
* @param {byte} c The third byte.
* @param {byte} d The fourth byte.
* @param {byte} e The fifth byte.
* @param {byte} f The sixth byte.
* @param {byte} g The seventh byte.
* @param {byte} h The eighth byte (phew!).
* @returns {number} The number of these bytes that are zero.
*/
export declare function getZeroByteCount(a: byte, b: byte, c: byte, d: byte, e: byte, f: byte, g: byte, h: byte): number;
/**
* Pack a section of a Cap'n Proto message into a compressed format. This will efficiently compress zero bytes (which
* are common in idiomatic Cap'n Proto messages) into a compact form.
*
* For stream-framed messages this is called once for the frame header and once again for each segment in the message.
*
* The returned array buffer is trimmed to the exact size of the packed message with a single copy operation at the end.
* This should be decent on CPU time but does require quite a lot of memory (a normal array is filled up with each
* packed byte until the packing is complete).
*
* @export
* @param {ArrayBuffer} unpacked The message to pack.
* @param {number} [byteOffset] Starting byte offset to read bytes from, defaults to 0.
* @param {number} [byteLength] Total number of bytes to read, defaults to the remainder of the buffer contents.
* @returns {ArrayBuffer} A packed version of the message.
*/
export declare function pack(unpacked: ArrayBuffer, byteOffset?: number, byteLength?: number): ArrayBuffer;
/**
* Unpack a compressed Cap'n Proto message into a new ArrayBuffer.
*
* Unlike the `pack` function, this is able to efficiently determine the exact size needed for the output buffer and
* runs considerably more efficiently.
*
* @export
* @param {ArrayBuffer} packed An array buffer containing the packed message.
* @returns {ArrayBuffer} The unpacked message.
*/
export declare function unpack(packed: ArrayBuffer): ArrayBuffer;
|