@devgrid/smartbuffer
Version:
143 lines (142 loc) • 6.86 kB
TypeScript
import Long from 'long';
import { Buffer } from 'buffer';
export interface SNumber {
value: number;
length: number;
}
export interface SLong {
value: Long;
length: number;
}
export type NumberValue = SNumber | number;
export type LongValue = SLong | Long;
export declare const isSmartBuffer: (obj: any) => boolean;
export declare class SmartBuffer {
static EMPTY_BUFFER: Buffer<ArrayBuffer>;
static DEFAULT_CAPACITY: number;
static DEFAULT_NOASSERT: boolean;
static MAX_VARINT32_BYTES: number;
static MAX_VARINT64_BYTES: number;
static METRICS_CHARS: string;
static METRICS_BYTES: string;
buffer: Buffer;
woffset: number;
roffset: number;
noAssert: boolean;
constructor(capacity?: number, noAssert?: boolean);
get length(): number;
get capacity(): number;
readBitSet(offset?: number): boolean[];
read(length: number, offset?: number): SmartBuffer;
readInt8(offset?: number): number;
readUInt8(offset?: number): number | undefined;
readInt16LE(offset?: number): number;
readInt16BE(offset?: number): number;
readUInt16LE(offset?: number): number;
readUInt16BE(offset?: number): number;
readUInt24BE(offset?: number): number;
readInt32LE(offset?: number): number;
readInt32BE(offset?: number): number;
readUInt32LE(offset?: number): number;
readUInt32BE(offset?: number): number;
readInt64LE(offset?: number): Long;
readInt64BE(offset?: number): Long;
readUInt64LE(offset?: number): Long;
readUInt64BE(offset?: number): Long;
readBigIntBE(offset?: number): bigint;
readUBigIntBE(offset?: number): bigint;
readBigIntLE(offset?: number): bigint;
readUBigIntLE(offset?: number): bigint;
readFloatLE(offset?: number): number;
readFloatBE(offset?: number): number;
readDoubleLE(offset?: number): number;
readDoubleBE(offset?: number): number;
write(source: any, offset?: number, length?: number, encoding?: string): this;
writeBitSet(value: any[], offset?: number): number | this;
writeBuffer(buf: Buffer, offset?: number): this;
writeInt8(value: number, offset?: number): this;
writeUInt8(value: number, offset?: number): this;
writeInt16LE(value: number, offset?: number): this;
writeInt16BE(value: number, offset?: number): this;
writeUInt16LE(value: number, offset?: number): this;
writeUInt16BE(value: number, offset?: number): this;
writeUInt24BE(value: number, offset?: number): this;
writeInt32LE(value: number, offset?: number): this;
writeInt32BE(value: number, offset?: number): this;
writeUInt32LE(value: number, offset?: number): this;
writeUInt32BE(value: number, offset?: number): this;
writeInt64LE(value: Long, offset?: number): this;
writeInt64BE(value: Long, offset?: number): this;
writeUInt64LE(value: Long, offset?: number): this;
writeUInt64BE(value: Long, offset?: number): this;
writeBigIntBE(value: bigint, offset?: number): this;
writeUBigIntBE(value: bigint, offset?: number): this;
writeBigIntLE(value: bigint, offset?: number): this;
writeUBigIntLE(value: bigint, offset?: number): this;
writeFloatLE(value: number, offset?: number): this;
writeFloatBE(value: number, offset?: number): this;
writeDoubleLE(value: number, offset?: number): this;
writeDoubleBE(value: number, offset?: number): this;
_checkRead(bytes: number, offset?: number): number;
_checkWrite(value: any, bytes: number, offset?: number, isFloat?: boolean): number;
_checkWriteLong(value: any, offset?: number): any[];
writeVarint32(value: any, offset?: number): number | this;
writeVarint32ZigZag(value: any, offset?: number): number | this;
readVarint32(offset?: number): NumberValue;
readVarint32ZigZag(offset?: number): NumberValue;
writeVarint64(value: any, offset?: number): this | 5 | 10 | 1 | 7 | 2 | 3 | 4 | 6 | 8 | 9;
writeVarint64ZigZag(value: any, offset: number): this | 5 | 10 | 1 | 7 | 2 | 3 | 4 | 6 | 8 | 9;
readVarint64(offset?: number): LongValue;
readVarint64ZigZag(offset?: number): LongValue;
writeCString(str: any, offset?: number): any;
readCString(offset?: number): string | {
string: string;
length: number;
};
writeString(str: string, offset?: number): number | this;
readString(length: number, metrics: any, offset?: number): any;
writeVString(str: string, offset?: number): number | this;
readVString(offset?: number): any;
appendTo(target: SmartBuffer, offset?: number): this;
assert(assert: boolean): this;
reset(resetWOffset?: boolean): this;
clone(copy?: boolean): SmartBuffer;
compact(begin?: number, end?: number): this;
copy(begin?: number, end?: number): SmartBuffer;
copyTo(target: SmartBuffer, targetOffset?: number, sourceStart?: number, sourceEnd?: number): SmartBuffer;
ensureCapacity(capacity: number): this;
fill(value: any, begin?: number, end?: number): this;
prepend(source: any, offset?: number, encoding?: any): this;
prependTo(target: any, offset?: number): this;
resize(capacity: number): this;
reverse(begin?: number, end?: number): this;
skipRead(length: number): this;
skipWrite(length: number): this;
slice(begin?: number, end?: number): SmartBuffer;
toBuffer(forceCopy?: boolean, begin?: number, end?: number): Buffer<ArrayBufferLike>;
toArrayBuffer(): ArrayBuffer;
toString(encoding?: string, begin?: number, end?: number): string;
toBase64(begin?: number, end?: number): string;
toBinary(begin?: number, end?: number): string;
toDebug(columns?: boolean): string;
toHex(begin?: number, end?: number): string;
toUTF8(begin?: number, end?: number): string;
static alloc(capacity?: number, noAssert?: boolean): SmartBuffer;
static concat(buffers: any[], encoding?: any, noAssert?: boolean): SmartBuffer;
static wrap(buffer: any, encoding?: string, noAssert?: boolean): SmartBuffer;
static calculateVarint32(value: number): number;
static zigZagEncode32(n: number): number;
static zigZagDecode32(n: number): number;
static calculateVarint64(value: string | number | Long): 5 | 10 | 1 | 7 | 2 | 3 | 4 | 6 | 8 | 9;
static zigZagEncode64(value: string | number | LongValue): Long;
static zigZagDecode64(value: string | number | LongValue): Long;
static calculateUTF8Chars(str: string): any;
static calculateString(str: string): number;
static fromBase64(str: string): SmartBuffer;
static btoa(str: string): string;
static atob(b64: string): string;
static fromBinary(str: string): SmartBuffer;
static fromDebug(str: string, noAssert?: boolean): SmartBuffer;
static fromHex(str: string, noAssert?: boolean): SmartBuffer;
static fromUTF8(str: string, noAssert?: boolean): SmartBuffer;
}