← Standard library

BinaryWriter

sealed class BinaryWriter
import BinaryWriter from Wax;

A growable byte buffer with an explicit byte order and cursor. Numeric writes preserve bit patterns, including floating-point values. Seeking past the end does not extend the buffer until a write; extension fills gaps with zero bytes. ToArray returns a separate snapshot.

import BinaryWriter from Wax;
import BinaryReader from Wax;
api fn Main() : int32 {
    var writer = new BinaryWriter.BigEndian();
    writer.Write<uint16>(513u);
    var bytes = writer.ToArray();
    var reader = new BinaryReader.BigEndian(bytes);
    return reader.Read<uint16>() as int32;
}

BinaryWriter.wax:23

Inherits from object. Follow these links for inherited members.

Members

LittleEndianconstructor

public constructor LittleEndian ()

Creates a little-endian cursor at byte position zero.

BinaryWriter.wax:31

BigEndianconstructor

public constructor BigEndian ()

Creates a big-endian cursor at byte position zero.

BinaryWriter.wax:40

positiongetter

public get position() : int32

The current zero-based byte offset.

BinaryWriter.wax:49

lengthgetter

public get length() : int32

The number of bytes in the backing data.

BinaryWriter.wax:53

Seekmethod

public fn Seek(int32 offset) : void

Sets an absolute byte offset, clamping negative offsets to zero. A position past length is allowed and does not itself allocate.

BinaryWriter.wax:59

Skipmethod

public fn Skip(int32 count) : void

Moves by a signed byte count. Positions below zero clamp to zero; positions above the signed 32-bit limit panic. Does not itself extend the buffer.

BinaryWriter.wax:68

Resetmethod

public fn Reset() : void

Moves the cursor to byte zero without clearing or changing the backing data.

BinaryWriter.wax:78

EnsureLengthmethod

public fn EnsureLength(int32 required) : void

Extends the written length to at least required bytes, growing storage and zero-filling newly exposed bytes. Does not move the cursor or shrink existing data.

BinaryWriter.wax:84

EnsureSizemethod

public fn EnsureSize(int32 needed) : void

Ensures that needed bytes fit after the current cursor, extending the written length and zero-filling gaps as necessary. Does not move the cursor. Supply a nonnegative needed count; resulting length overflow panics.

BinaryWriter.wax:97

Writemethod

public fn Write<T>(T value) : void where T is numeric

Writes sizeof(T) bytes at the cursor and advances it. Overwrites existing bytes or grows the buffer, zero-filling any gap. A resulting length above the signed 32-bit limit panics.

BinaryWriter.wax:107

WriteAtmethod

public fn WriteAt<T>(int32 offset, T value) : void where T is numeric

Writes a numeric value at an absolute offset without moving the cursor. Extends and zero-fills as needed. Negative offsets or an overflowing resulting length panic.

BinaryWriter.wax:122

ToArraymethod

public fn ToArray() : uint8[]

Copies all written bytes, including any zero-filled gaps, into an independent byte array. The cursor position does not limit the copy.

BinaryWriter.wax:139