//#region src/common/bin/lib0/encoding.d.ts
/**
 * Original at https://github.com/dmonad/lib0
 *
 * Efficient schema-less binary encoding with support for variable length encoding.
 *
 * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.
 *
 * Encodes numbers in little-endian order (least to most significant byte order)
 * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
 * which is also used in Protocol Buffers.
 *
 * ```js
 * // encoding step
 * const encoder = new encoding.createEncoder()
 * encoding.writeVarUint(encoder, 256)
 * encoding.writeVarString(encoder, 'Hello world!')
 * const buf = encoding.toUint8Array(encoder)
 * ```
 *
 * ```js
 * // decoding step
 * const decoder = new decoding.createDecoder(buf)
 * decoding.readVarUint(decoder) // => 256
 * decoding.readVarString(decoder) // => 'Hello world!'
 * decoding.hasContent(decoder) // => false - all data is read
 * ```
 */
/**
 * A BinaryEncoder handles the encoding to an Uint8Array.
 */
declare class BinEncoder {
  cpos: number;
  cbuf: Uint8Array;
  bufs: Uint8Array[];
  constructor();
}
declare function createBinEncoder(): BinEncoder;
/**
 * The current length of the encoded data.
 */
declare function length(encoder: BinEncoder): number;
/**
 * Transform to Uint8Array.
 */
declare function encodeToUint8Array(encoder: BinEncoder): Uint8Array;
/**
 * Verify that it is possible to write `len` bytes wtihout checking. If
 * necessary, a new Buffer with the required length is attached.
 */
declare function verifyLen(encoder: BinEncoder, len: number): void;
/**
 * Write one byte to the encoder.
 */
declare function write(encoder: BinEncoder, num: number): void;
/**
 * Write one byte at a specific position.
 * Position must already be written (i.e. encoder.length > pos)
 */
declare function set(encoder: BinEncoder, pos: number, num: number): void;
/**
 * Write one byte as an unsigned integer.
 */
declare const writeUint8: typeof write;
/**
 * Write one byte as an unsigned Integer at a specific location.
 */
declare const setUint8: typeof set;
/**
 * Write two bytes as an unsigned integer.
 */
declare function writeUint16(encoder: BinEncoder, num: number): void;
/**
 * Write two bytes as an unsigned integer at a specific location.
 */
declare function setUint16(encoder: BinEncoder, pos: number, num: number): void;
/**
 * Write two bytes as an unsigned integer
 */
declare function writeUint32(encoder: BinEncoder, num: number): void;
/**
 * Write two bytes as an unsigned integer in big endian order.
 * (most significant byte first)
 */
declare function writeUint32BigEndian(encoder: BinEncoder, num: number): void;
/**
 * Write two bytes as an unsigned integer at a specific location.
 */
declare function setUint32(encoder: BinEncoder, pos: number, num: number): void;
/**
 * Write a variable length unsigned integer. Max encodable integer is 2^53.
 */
declare function writeVarUint(encoder: BinEncoder, num: number): void;
declare function isNegativeZero(n: number): boolean;
/**
 * Write a variable length integer.
 *
 * We use the 7th bit instead for signaling that this is a negative number.
 */
declare function writeVarInt(encoder: BinEncoder, num: number): void;
/**
 * Append fixed-length Uint8Array to the encoder.
 */
declare function writeUint8Array(encoder: BinEncoder, uint8Array: Uint8Array): void;
/**
 * Append an Uint8Array to BinEncoder.
 */
declare function writeVarUint8Array(encoder: BinEncoder, uint8Array: Uint8Array): void;
/**
 * Write a variable length string.
 */
declare function writeVarString(encoder: BinEncoder, str: string): void;
/**
 * Write the content of another Encoder.
 *
 * @TODO: can be improved!
 *        - Note: Should consider that when appending a lot of small Encoders, we should rather clone than referencing the old structure.
 *                Encoders start with a rather big initial buffer.
 */
declare function writeBinaryEncoder(encoder: BinEncoder, append: BinEncoder): void;
/**
 * Create an DataView of the next `len` bytes. Use it to write data after
 * calling this function.
 *
 * ```js
 * // write float32 using DataView
 * const dv = writeOnDataView(encoder, 4)
 * dv.setFloat32(0, 1.1)
 * // read float32 using DataView
 * const dv = readFromDataView(encoder, 4)
 * dv.getFloat32(0) // => 1.100000023841858 (leaving it to the reader to find out why this is the correct result)
 * ```
 */
declare function writeOnDataView(encoder: BinEncoder, len: number): DataView;
declare function writeFloat32(encoder: BinEncoder, num: number): void;
declare function writeFloat64(encoder: BinEncoder, num: number): void;
declare function writeBigInt64(encoder: BinEncoder, num: bigint): void;
declare function writeBigUint64(encoder: BinEncoder, num: bigint): void;
/**
 * Encode data with efficient binary format.
 *
 * Differences to JSON:
 * • Transforms data to a binary format (not to a string)
 * • Encodes undefined, NaN, and ArrayBuffer (these can't be represented in JSON)
 * • Numbers are efficiently encoded either as a variable length integer, as a
 *   32 bit float, as a 64 bit float, or as a 64 bit bigint.
 *
 * Encoding table:
 *
 * | Data Type           | Prefix   | Encoding Method    | Comment |
 * | ------------------- | -------- | ------------------ | ------- |
 * | undefined           | 127      |                    | Functions, symbol, and everything that cannot be identified is encoded as undefined |
 * | null                | 126      |                    | |
 * | integer             | 125      | writeVarInt        | Only encodes 32 bit signed integers |
 * | float32             | 124      | writeFloat32       | |
 * | float64             | 123      | writeFloat64       | |
 * | bigint              | 122      | writeBigInt64      | |
 * | boolean (false)     | 121      |                    | True and false are different data types so we save the following byte |
 * | boolean (true)      | 120      |                    | - 0b01111000 so the last bit determines whether true or false |
 * | string              | 119      | writeVarString     | |
 * | object<string,any>  | 118      | custom             | Writes {length} then {length} key-value pairs |
 * | array<any>          | 117      | custom             | Writes {length} then {length} json values |
 * | Uint8Array          | 116      | writeVarUint8Array | We use Uint8Array for any kind of binary data |
 *
 * Reasons for the decreasing prefix:
 * We need the first bit for extendability (later we may want to encode the
 * prefix with writeVarUint). The remaining 7 bits are divided as follows:
 * [0-30]   the beginning of the data range is used for custom purposes
 *          (defined by the function that uses this library)
 * [31-127] the end of the data range is used for data encoding by
 *          lib0/encoding.js
 */
declare function writeAny(encoder: BinEncoder, data: undefined | null | number | bigint | boolean | string | {
  [s: string]: any;
} | Array<any> | Uint8Array): void;
//#endregion
export { BinEncoder, createBinEncoder, encodeToUint8Array, isNegativeZero, length, set, setUint16, setUint32, setUint8, verifyLen, write, writeAny, writeBigInt64, writeBigUint64, writeBinaryEncoder, writeFloat32, writeFloat64, writeOnDataView, writeUint16, writeUint32, writeUint32BigEndian, writeUint8, writeUint8Array, writeVarInt, writeVarString, writeVarUint, writeVarUint8Array };
//# sourceMappingURL=encoding.d.cts.map