UNPKG

1.91 kBTypeScriptView Raw
1/**
2 * A buffer maintaining a write position capable of writing primitive values
3 */
4export interface WriteBuffer {
5 writeUint8(byte: number): this;
6 writeUint16(value: number): this;
7 writeUint32(value: number): this;
8 writeString(value: string): this;
9 writeBytes(value: Uint8Array): this;
10 writeNumber(value: number): this;
11 writeLength(value: number): this;
12 writeRaw(bytes: Uint8Array): this;
13 /**
14 * Makes any writes to the buffer permanent, for example by sending the writes over a channel.
15 * You must obtain a new write buffer after committing
16 */
17 commit(): void;
18}
19export declare class ForwardingWriteBuffer implements WriteBuffer {
20 protected readonly underlying: WriteBuffer;
21 constructor(underlying: WriteBuffer);
22 writeUint8(byte: number): this;
23 writeUint16(value: number): this;
24 writeUint32(value: number): this;
25 writeLength(value: number): this;
26 writeString(value: string): this;
27 writeBytes(value: Uint8Array): this;
28 writeNumber(value: number): this;
29 writeRaw(bytes: Uint8Array): this;
30 commit(): void;
31}
32/**
33 * A buffer maintaining a read position in a buffer containing a received message capable of
34 * reading primitive values.
35 */
36export interface ReadBuffer {
37 readUint8(): number;
38 readUint16(): number;
39 readUint32(): number;
40 readString(): string;
41 readNumber(): number;
42 readLength(): number;
43 readBytes(): Uint8Array;
44 /**
45 * Returns a new read buffer whose starting read position is the current read position of this buffer.
46 * This is useful to create read buffers sub messages.
47 * (e.g. when using a multiplexer the beginning of the message might contain some protocol overhead which should not be part
48 * of the message reader that is sent to the target channel)
49 */
50 sliceAtReadPosition(): ReadBuffer;
51}
52//# sourceMappingURL=message-buffer.d.ts.map
\No newline at end of file