abla/bytes

Generated from source.

Import with import "abla/bytes".

Source: abla/bytes/entry.ab

ablaByteEncode (extern)

noescape extern:"intrinsic" fun ablaByteEncode(value: int): string

Returns a one-byte string for 0 through 255, or an empty string outside that range.

ablaByteChunksJoin (extern)

noescape extern:"intrinsic" fun ablaByteChunksJoin(
    chunks: array<string>,
    byteCount: int
): string

Joins byte chunks in order using their known combined length.

byteEncode (fun)

fun byteEncode(value: int): string

Returns the one-byte string for 0...255, or an empty string outside that range. Unlike UTF-8 scalar encoding, values above 127 remain one byte.

ByteBuffer (class)

class ByteBuffer(
    val chunks: array<string>,
    var byteCount: int,
    var stage: string = "",
    var staged: int = 0
)

Small appends are copied into stage, a string the buffer alone owns and writes in place; a full stage becomes a chunk as it is. Stages grow with the buffer, from BYTE_BUFFER_FIRST bytes to BYTE_BUFFER_STAGE, so a buffer that only ever holds a few bytes stays small. A document written a token at a time (a JSON encoder's punctuation, keys and numbers) used to keep a string and an array slot per token, and numbers are written without making a string at all (appendInt, appendFixed). Appends of BYTE_BUFFER_LARGE bytes or more stay their own chunk, uncopied.

ablaAtCompileTime (fun)

fun ablaAtCompileTime(): bool

True while ablac's compile-time evaluator runs the caller: the evaluator answers this call itself, takes only the then branch of an if (ablaAtCompileTime()), and counts the effects of that branch alone, so the else may use raw memory it cannot. Compiled code always sees false.

ablaCompileTimeNativeHost (fun)

fun ablaCompileTimeNativeHost(): bool

True while ablac runs the caller at compile time as native code for the host (the jit tier, or auto for a site it runs natively): such code can take the same raw-memory path compiled code does. False in the evaluator, in a slice built for another target (a cross-target site, which must stay portable), and in compiled code. The compile-time analyses take it as false, so the then of if (ablaCompileTimeNativeHost()) is never what they look at; a dispatcher reads if (ablaCompileTimeNativeHost()) native() else if (ablaAtCompileTime()) portable() else native()

BYTE_BUFFER_LARGE (val)

val BYTE_BUFFER_LARGE

Appends of at least this many bytes are kept as chunks instead of staged together.

ByteSlice (class)

class ByteSlice(
    val buffer: ByteBuffer,
    val begin: int,
    val end: int
)

A view over bytes from begin inclusive to end exclusive in buffer. Use isValid to check bounds.

ByteSlice.size (method)

fun size(): int

Returns the span length or zero when its endpoints are reversed.

ByteSlice.isValid (method)

fun isValid(): bool

Returns true if both endpoints form an ordered range within the current buffer.

byteBuffer (fun)

fun byteBuffer(): ByteBuffer

Creates an empty byte buffer.

bytes (fun)

fun bytes(text: string): ByteBuffer

Creates a buffer initialized with the bytes of text.

ByteBuffer.size (extension fun)

fun ByteBuffer.size(): int

Returns the number of stored bytes.

ByteBuffer.appendText (extension fun)

fun ByteBuffer.appendText(text: string): void

Appends the bytes of text in order. An empty string has no effect.

ByteBuffer.appendChunk (extension fun)

fun ByteBuffer.appendChunk(text: string): void

Appends nonempty text as a separate chunk after sealing existing staged bytes.

ByteBuffer.stageText (extension fun)

trusted fun ByteBuffer.stageText(text: string): void

Appends text to the staging buffer or keeps a large input as its own chunk.

ByteBuffer.stageReserve (extension fun)

trusted fun ByteBuffer.stageReserve(bytes: int): int

The address where bytes more bytes can be written into the stage, which the caller then counts in staged and byteCount.

ByteBuffer.seal (extension fun)

fun ByteBuffer.seal(): void

Moves the staged bytes into a chunk of their own.

ByteBuffer.stagedText (extension fun)

fun ByteBuffer.stagedText(): string

Returns the bytes currently staged, excluding all sealed chunks.

ByteBuffer.appendInt (extension fun)

fun ByteBuffer.appendInt(value: int): void

value in decimal, as "$value" writes it, straight into the stage.

ByteBuffer.appendFixed (extension fun)

fun ByteBuffer.appendFixed(value: int, decimals: int): void

value / 10^decimals in decimal with exactly decimals digits after the point: (15, 1) "1.5", (5, 3) "0.005", (-25, 2) "-0.25", (7, 0) "7".

ByteBuffer.stageFixed (extension fun)

trusted fun ByteBuffer.stageFixed(value: int, decimals: int): void

Appends the signed integer as a fixed-point decimal with the requested number of fractional digits.

ByteBuffer.pieceCount (extension fun)

fun ByteBuffer.pieceCount(): int

The buffer's pieces in order: its chunks, then the staged bytes.

ByteBuffer.piece (extension fun)

fun ByteBuffer.piece(index: int): string

Returns sealed chunk index if it precedes the staged tail, or the staged text for later indices. A negative index panics. Iterate over 0 until pieceCount for the actual pieces.

ByteBuffer.appendByte (extension fun)

fun ByteBuffer.appendByte(byte: string): bool

A byte is represented by a one-byte string at the portable language layer. This preserves all 256 values, including bytes originating in files/sockets, without pretending that an integer is a Unicode character.

ByteBuffer.appendByteValue (extension fun)

@inline trusted fun ByteBuffer.appendByteValue(value: int): bool

Appends one byte and returns true. Values outside 0 through 255 return false without changing the buffer.

ByteBuffer.appendByteValueNative (extension fun)

@inline trusted fun ByteBuffer.appendByteValueNative(value: int): bool

Appends a byte through native staging. Returns false without changing the buffer when the value is outside 0 through 255.

ByteBuffer.appendBuffer (extension fun)

fun ByteBuffer.appendBuffer(other: ByteBuffer): void

Appends the pieces of other in order. Pass a distinct buffer because the source is traversed as this buffer grows.

ByteBuffer.byteAt (extension fun)

fun ByteBuffer.byteAt(index: int): int

Returns the unsigned byte at zero-based index, or -1 if out of range.

ByteBuffer.slice (extension fun)

fun ByteBuffer.slice(begin: int, end: int): borrow(this) ByteSlice

Borrows a view over bytes from begin inclusive to end exclusive. Bounds are checked by the view's read methods.

ByteBuffer.toText (extension fun)

fun ByteBuffer.toText(): string

Returns all stored bytes in order as a string. Bytes are preserved even when they are invalid UTF-8.

ByteSlice.byteAt (extension fun)

fun ByteSlice.byteAt(index: int): int

Returns the unsigned byte at slice-relative index, or -1 when either the slice or the index is out of range.

ByteSlice.toText (extension fun)

fun ByteSlice.toText(): string

Returns the slice's bytes as a string, or an empty string if the slice is invalid.

stableTextHash (fun)

fun stableTextHash(text: string): int

Deterministic and overflow-safe on Abla's signed 64-bit integer. This is a content fingerprint, not a cryptographic hash.

ByteBuffer.stableHash (extension fun)

fun ByteBuffer.stableHash(): int

Returns a deterministic, noncryptographic fingerprint of the stored bytes.

ByteSlice.stableHash (extension fun)

fun ByteSlice.stableHash(): int

Returns a deterministic, noncryptographic fingerprint of the slice. An invalid slice hashes as an empty string.

Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.