menu

ByteBuffer

import { ByteBuffer } from "destack:bytes";

Growable byte buffer.

language/library/src/bytes/buffer.ds:7:98
1export class ByteBuffer {2    storage: Unique<[MaybeUninit<uint8>]>;3    initializedLength: isize;4    allocatedCapacity: usize;5    static new(): ^ByteBuffer;6    static withCapacity(capacity: usize): ^ByteBuffer;7    static from(bytes: &'a readonly [uint8]): ^ByteBuffer;8    get length(): isize;9    get size(): isize;10    get capacity(): usize;11    get isEmpty(): boolean;12    reserve(additional: usize): void;13    clear(): void;14    compact(): void;15    writeByte(value: uint8): void;16    write(bytes: &'b readonly [uint8]): void;17    fill(value: uint8, count: isize): void;18    asBytes<const A: Access = "readonly">(): WithAccess<&[uint8], A>;19    toBytes(): readonly [uint8];20    intoBytes(): readonly [uint8];21}

Members

storage: Unique<[MaybeUninit<uint8>]>

The owned byte storage.

initializedLength: isize

The initialized byte count.

allocatedCapacity: usize

The allocated byte capacity.

static new(): ^ByteBuffer

Create an empty byte buffer.

static withCapacity(capacity: usize): ^ByteBuffer

Create a byte buffer with room for at least capacity bytes.

static from(bytes: &'a readonly [uint8]): ^ByteBuffer

Create a byte buffer containing bytes.

get length(): isize

Return the initialized byte count.

get size(): isize

Return the initialized byte count.

get capacity(): usize

Return the allocated byte capacity.

get isEmpty(): boolean

Return whether this buffer has no initialized bytes.

reserve(additional: usize): void

Reserve room for at least additional more bytes.

clear(): void

Remove all initialized bytes.

compact(): void

Release unused capacity.

writeByte(value: uint8): void

Append one byte.

write(bytes: &'b readonly [uint8]): void

Append bytes.

fill(value: uint8, count: isize): void

Append count copies of value.

asBytes<const A: Access = "readonly">(): WithAccess<&[uint8], A>

Borrow initialized bytes.

toBytes(): readonly [uint8]

Clone initialized bytes into immutable storage.

intoBytes(): readonly [uint8]

Move initialized bytes into immutable storage.