Module
LinkBytes stores immutable octets. ByteBuffer is a mutable value with a fixed length. Indexing counts bytes and text conversion uses an explicit encoding.
Why
LinkBinary data needs exact byte values, explicit text encodings, and a mutable buffer for incremental work.
Availability
LinkImport std.bytes in language mode 5.21. The current compiler selects std/bytes.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Exported types
Linkexport type Bytes = Bytes
export type Byte
Type members keep the compiler-owned type name shown in their declarations. Importing a module does not create a new type identity.
Public API
LinkPending contracts
LinkRead collection sizes, keys, and values as properties
LinkRead collection sizes, keys, and values as properties
Bytes.length and ByteBuffer.length are read-only int properties that report the number of bytes.
JSONValue.length is an Option<int> property. Arrays and objects return Some(count) for their element or member count. Other JSON kinds return None().
JSONValue.keys and JSONValue.values are properties returning Option<Array<string>> and Option<Array<JSON. Objects return Some(keys) or Some(values). Other JSON kinds return None().
Read these properties without parentheses, as with Array.length, Map.length, Map.keys, Map.values, and Set.length. Calling a property value is rejected as a non-callable value.
Why
The same collection observation should use the same syntax across core collections and library values. Keeping JSONValue results optional preserves its distinction between collections and scalar values.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read the same properties on core collections
Linkimport std.iolet array = [2, 3]let entries = map { "name": "Topaz" }let values = set { 2, 3 }io.writeLine("{array.length}:{entries.length}:{values.length}")io.writeLine(entries.keys[0])io.writeLine(entries.values[0])
2:1:2 name Topaz
Expected result
Expected result
Execution completes. Exit code 0.
2:1:2nameTopaz
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read a byte sequence size
Linkimport std.bytes { Bytes }import std.iolet bytes = Bytes.empty()let size: int = bytes.lengthio.writeLine("{size}")
0
Expected result
Expected result
Execution completes. Exit code 0.
0
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read a byte buffer size
Linkimport std.bytes { ByteBuffer }import std.iolet buffer = ByteBuffer.allocate(3)let size: int = buffer.lengthio.writeLine("{size}")
3
Expected result
Expected result
Execution completes. Exit code 0.
3
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read JSON sizes and preserve optional results
Linkimport std.jsonimport std.testimport std.iolet array = test.assertOk(json.parse("[1,2]"))let object = test.assertOk(json.parse("\{\"name\":\"Topaz\"\}"))let scalar = test.assertOk(json.parse("42"))let arraySize: Option<int> = array.lengthlet objectSize: Option<int> = object.lengthlet scalarSize: Option<int> = scalar.lengthtest.assertEq(test.assertSome(arraySize), 2)test.assertEq(test.assertSome(objectSize), 1)test.assertNone(scalarSize)io.writeLine("JSON sizes read")
JSON sizes read
Expected result
Expected result
Execution completes. Exit code 0.
JSON sizes read
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read JSON object keys
Linkimport std.jsonimport std.testimport std.iolet object = test.assertOk(json.parse("\{\"name\":\"Topaz\"\}"))let array = test.assertOk(json.parse("[]"))let scalar = test.assertOk(json.parse("42"))let names: Option<Array<string>> = object.keystest.assertEq(test.assertSome(names)[0], "name")test.assertNone(array.keys)test.assertNone(scalar.keys)io.writeLine("JSON keys read")
JSON keys read
Expected result
Expected result
Execution completes. Exit code 0.
JSON keys read
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read JSON object values
Linkimport std.jsonimport std.testimport std.iolet object = test.assertOk(json.parse("\{\"name\":\"Topaz\"\}"))let array = test.assertOk(json.parse("[]"))let scalar = test.assertOk(json.parse("42"))let values = test.assertSome(object.values)test.assertEq(test.assertSome(values[0].asString()), "Topaz")test.assertNone(array.values)test.assertNone(scalar.values)io.writeLine("JSON values read")
JSON values read
Expected result
Expected result
Execution completes. Exit code 0.
JSON values read
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Reject calling Bytes.length
Linkimport std.bytes { Bytes }function inspect(value: Bytes) -> () {let result = value.length()return ()}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5005stdlib-property-not-callable atmain.tpz:3:22
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Reject calling ByteBuffer.length
Linkimport std.bytes { ByteBuffer }function inspect(value: ByteBuffer) -> () {let result = value.length()return ()}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5005stdlib-property-not-callable atmain.tpz:3:22
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Reject calling JSONValue.length
Linkimport std.json { JSONValue }function inspect(value: JSONValue) -> () {let result = value.length()return ()}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5005stdlib-property-not-callable atmain.tpz:3:22
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Reject calling JSONValue.keys
Linkimport std.json { JSONValue }function inspect(value: JSONValue) -> () {let result = value.keys()return ()}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5005stdlib-property-not-callable atmain.tpz:3:22
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Reject calling JSONValue.values
Linkimport std.json { JSONValue }function inspect(value: JSONValue) -> () {let result = value.values()return ()}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5005stdlib-property-not-callable atmain.tpz:3:22
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Diagnostics
LinkTest collection emptiness with length
LinkTest collection emptiness with length
Test whether a Bytes, Map, or Set value is empty by comparing its length property with zero. The comparison is true exactly when the collection has no bytes, entries, or elements.
Bytes, Map, and Set do not expose an isEmpty member. Read the length property and use the ordinary equality operator.
Why
A collection already exposes its count through length. Comparing that value with zero expresses emptiness for every collection without another query name or a type-specific method.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Test empty and nonempty maps with length
Linkimport std.iolet empty: Map<string, int> = map {}let filled = map { "one": 1 }io.writeLine("{empty.length == 0}:{filled.length == 0}")
true:false
Expected result
Expected result
Execution completes. Exit code 0.
true:false
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Test empty and nonempty sets with length
Linkimport std.iolet empty: Set<int> = set {}let filled = set { 1 }io.writeLine("{empty.length == 0}:{filled.length == 0}")
true:false
Expected result
Expected result
Execution completes. Exit code 0.
true:false
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Test empty and nonempty byte sequences with length
Linkimport std.bytes { Bytes }import std.testimport std.iolet empty = Bytes.empty()let filled = test.assertOk(Bytes.fromArray([1]))io.writeLine("{empty.length == 0}:{filled.length == 0}")
true:false
Expected result
Expected result
Execution completes. Exit code 0.
true:false
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Reject Bytes.isEmpty
Linkimport std.bytes { Bytes }function inspect(value: Bytes) -> () {let result = value.isEmpty()return ()}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Reject Map.isEmpty
Linkfunction inspect(value: Map<string, int>) -> () {let result = value.isEmpty()return ()}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Reject Set.isEmpty
Linkfunction inspect(value: Set<int>) -> () {let result = value.isEmpty()return ()}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Diagnostics
LinkConstruct and inspect immutable byte sequences
LinkConstruct and inspect immutable byte sequences
A Bytes value is an immutable ordered sequence of octets. Each octet is an int from 0 through 255.
Bytes.empty returns the empty sequence. Bytes.fromArray accepts an Array<int> and returns an independent snapshot in Ok.
Bytes.fromArray returns Err with a string identifying the first element outside 0 through 255. It does not wrap, clamp, or return a partial sequence.
Bytes.toArray returns a new Array<int> in byte order. Mutating that array or the original input array does not change an existing Bytes value.
Bytes.concat returns the receiver bytes followed by the argument bytes. Either input may be empty and both inputs retain their contents.
Bytes.get uses a zero-based byte index. It returns Some(byte) within the sequence and None() for every negative or past-end index.
Bytes.length is the number of bytes and is read as a property. Compare it with zero to test emptiness.
Receivers and supplied arguments evaluate once from left to right before the operation begins. These operations perform no I/O or text normalization.
A correctly typed lookup or concatenation has no data-dependent Result failure. Allocation exhaustion is an operational failure and is not a decoded data error.
Why
Exact octets keep binary payloads independent of text encoding. Snapshot conversion prevents later array edits from silently changing a payload.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Preserve empty values and byte order
Linkimport std.bytes { Bytes }import std.ioimport std.testlet empty = test.assertOk(Bytes.fromArray([]))let value = test.assertOk(Bytes.fromArray([0, 128, 255]))io.writeLine(Bytes.empty().toHex())io.writeLine(empty.concat(value).toHex())io.writeLine(value.concat(test.assertOk(Bytes.fromArray([1]))).toHex())
0080ff 0080ff01
Expected result
Expected result
Execution completes. Exit code 0.
0080ff0080ff01
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Reject out-of-range array elements
Linkimport std.bytes { Bytes }import std.iofor values in ([[0, -1, 255], [0, 256, 255]]) {match (Bytes.fromArray(values)) {case Err(_) => io.writeLine("invalid byte")case Ok(_) => io.writeLine("accepted")}}
invalid byte invalid byte
Expected result
Expected result
Execution completes. Exit code 0.
invalid byteinvalid byte
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Read optional bytes at both boundaries
Linkimport std.bytes { Bytes }import std.ioimport std.testlet value = test.assertOk(Bytes.fromArray([0, 128, 255]))for index in ([-1, 0, 2, 3]) {match (value.get(index)) {case Some(byte) => io.writeLine("{byte}")case None() => io.writeLine("absent")}}
absent 0 255 absent
Expected result
Expected result
Execution completes. Exit code 0.
absent0255absent
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Keep array edits independent from bytes
Linkimport std.bytes { Bytes }import std.ioimport std.testlet mut input = [0, 255]let value = test.assertOk(Bytes.fromArray(input))let mut output = value.toArray()input[0] = 7output[1] = 8io.writeLine(value.toHex())io.writeLine("{input[0]},{output[1]}")
00ff 7,8
Expected result
Expected result
Execution completes. Exit code 0.
00ff7,8
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Evaluate the receiver before its argument
Linkimport std.bytes { Bytes }import std.iofunction receiver() -> Bytes {io.writeLine("receiver")return "a".encodeUtf8()}function argument() -> Bytes {io.writeLine("argument")return "b".encodeUtf8()}io.writeLine(receiver().concat(argument()).toHex())
receiver argument 6162
Expected result
Expected result
Execution completes. Exit code 0.
receiverargument6162
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Select explicit byte intervals
LinkSelect explicit byte intervals
Bytes.slice uses a start position and an exclusive end position measured in bytes.
Valid bounds satisfy 0 <= start <= end <= length. The result contains exactly the bytes from start through end minus one.
Equal endpoints produce empty Bytes, including endpoints at zero and at length. A full interval preserves every byte.
Negative bounds, inverted bounds, and endpoints beyond length produce TPZ4001 at runtime. Bounds are not clamped or interpreted from the end.
Slicing never changes the receiver. The receiver, start, and end expressions evaluate once in that order before the bounds are checked.
A byte interval may split a UTF-8 encoding. Bytes.slice preserves those selected octets and Bytes.decodeUtf8 reports invalid text when they form an incomplete sequence.
Why
An explicit interval should identify exactly the requested payload. Rejecting an invalid interval makes a mistaken byte count visible before subsequent decoding.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 308 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 329 -
topaz.stdlib.contract.bytes-sliceatworking-tree - topaz.decision.bytes-slice-bounds.1 at
topaz.decisi
Select empty and nonempty intervals
Linkimport std.iolet value = "abcd".encodeUtf8()io.writeLine(value.slice(0, 0).toHex())io.writeLine(value.slice(1, 3).toHex())io.writeLine(value.slice(4, 4).toHex())io.writeLine(value.toHex())
6263 61626364
Expected result
Expected result
Execution completes. Exit code 0.
626361626364
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 308 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 329 -
topaz.stdlib.contract.bytes-sliceatworking-tree - topaz.decision.bytes-slice-bounds.1 at
topaz.decisi
Keep byte slicing separate from UTF-8 validation
Linkimport std.iolet byte = "é".encodeUtf8().slice(0, 1)io.writeLine(byte.toHex())match (byte.decodeUtf8()) {case Err(_) => io.writeLine("invalid UTF-8")case Ok(_) => io.writeLine("accepted")}
c3 invalid UTF-8
Expected result
Expected result
Execution completes. Exit code 0.
c3invalid UTF-8
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 308 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 329 -
topaz.stdlib.contract.bytes-sliceatworking-tree - topaz.decision.bytes-slice-bounds.1 at
topaz.decisi
Reject a negative slice start
Linkimport std.bytes { Bytes }let value = "abcd".encodeUtf8()value.slice(-1, 2)
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 308 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 329 -
topaz.stdlib.contract.bytes-sliceatworking-tree - topaz.decision.bytes-slice-bounds.1 at
topaz.decisi
Reject an inverted byte interval
Linkimport std.bytes { Bytes }let value = "abcd".encodeUtf8()value.slice(3, 2)
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 308 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 329 -
topaz.stdlib.contract.bytes-sliceatworking-tree - topaz.decision.bytes-slice-bounds.1 at
topaz.decisi
Reject an endpoint beyond the sequence
Linkimport std.bytes { Bytes }let value = "abcd".encodeUtf8()value.slice(0, 5)
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 308 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 329 -
topaz.stdlib.contract.bytes-sliceatworking-tree - topaz.decision.bytes-slice-bounds.1 at
topaz.decisi
Diagnostics
LinkUse a canonical hexadecimal spelling
LinkUse a canonical hexadecimal spelling
Bytes.toHex emits two lowercase ASCII hexadecimal digits per byte with the high nibble first. Empty Bytes produces an empty string.
Bytes.fromHex accepts an even number of digits drawn from 0 through 9 and a through f. Empty text returns Ok with empty Bytes.
Uppercase letters, prefixes, separators, whitespace, non-ASCII characters, and an odd digit count return Err with a string describing invalid hex input.
Decoding returns the entire byte sequence in Ok or an error with no decoded prefix. It never mutates an input value.
Encoding then decoding recovers the bytes exactly. Decoding then encoding preserves every accepted input spelling.
The input expression evaluates once. These conversions perform no I/O and do not apply Unicode normalization.
Why
One accepted hexadecimal spelling makes serialized byte text stable for comparison and reproduction. Data that uses another spelling can be normalized explicitly before decoding.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 56 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 123 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 132 -
topaz.stdlib.contract.bytes-hexatworking-tree - topaz.decision.bytes-hex-canonical-input.1 at
topaz.decisi
Decode byte pairs and emit lowercase text
Linkimport std.bytes { Bytes }import std.ioimport std.testio.writeLine(test.assertOk(Bytes.fromHex("")).toHex())io.writeLine(test.assertOk(Bytes.fromHex("000f80ff")).toHex())
000f80ff
Expected result
Expected result
Execution completes. Exit code 0.
000f80ff
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 56 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 123 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 132 -
topaz.stdlib.contract.bytes-hexatworking-tree - topaz.decision.bytes-hex-canonical-input.1 at
topaz.decisi
Reject malformed hexadecimal strings
Linkimport std.bytes { Bytes }import std.iofor text in (["0", "gg", "0x00", "00 11", "00"]) {match (Bytes.fromHex(text)) {case Err(_) => io.writeLine("invalid hex")case Ok(_) => io.writeLine("accepted")}}
invalid hex invalid hex invalid hex invalid hex invalid hex
Expected result
Expected result
Execution completes. Exit code 0.
invalid hexinvalid hexinvalid hexinvalid hexinvalid hex
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 56 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 123 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 132 -
topaz.stdlib.contract.bytes-hexatworking-tree - topaz.decision.bytes-hex-canonical-input.1 at
topaz.decisi
Reject uppercase hexadecimal input
Linkimport std.bytes { Bytes }import std.iomatch (Bytes.fromHex("CAfe")) {case Err(_) => io.writeLine("uppercase rejected")case Ok(_) => io.writeLine("accepted")}
uppercase rejected
Expected result
Expected result
Execution completes. Exit code 0.
uppercase rejected
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 56 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 123 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 132 -
topaz.stdlib.contract.bytes-hexatworking-tree - topaz.decision.bytes-hex-canonical-input.1 at
topaz.decisi
Encode and validate padded Base64
LinkEncode and validate padded Base64
Bytes.toBase64 uses the RFC 4648 standard alphabet with plus and slash. Its output has no whitespace or line wrapping.
A final group containing one byte ends with two equals signs. A final group containing two bytes ends with one equals sign.
Bytes.fromBase64 accepts complete groups of four characters. Padding appears at the end of the final group and all unused bits are zero.
Missing or misplaced padding, nonzero unused bits, whitespace, non-ASCII characters, minus signs, and underscores return Err with a string.
Empty bytes encode as empty text and empty text decodes to Ok with empty Bytes. Invalid text never returns a partial byte sequence.
The input is evaluated once and is unchanged. Encoding then decoding recovers the input bytes exactly without any external effects.
Why
A precise alphabet and padding rule let independent implementations exchange the same bytes. Rejecting nonzero unused bits prevents several texts from representing one accepted encoding.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 158 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 164 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 195 -
topaz.stdlib.contract.bytes-base64atworking-tree
Use standard Base64 vectors
Linkimport std.bytes { Bytes }import std.ioimport std.testfor text in (["", "f", "fo", "foo"]) {io.writeLine(text.encodeUtf8().toBase64())}for text in (["", "Zg==", "Zm8=", "Zm9v"]) {io.writeLine(test.assertOk(Bytes.fromBase64(text)).toHex())}
Zg== Zm8= Zm9v 66 666f 666f6f
Expected result
Expected result
Execution completes. Exit code 0.
Zg==Zm8=Zm9v66666f666f6f
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 158 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 164 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 195 -
topaz.stdlib.contract.bytes-base64atworking-tree
Reject padding and alphabet errors
Linkimport std.bytes { Bytes }import std.iofor text in (["Zg", "Zh==", "Zg== ", "_w==", "Zg==Zg==", "=g=="]) {match (Bytes.fromBase64(text)) {case Err(_) => io.writeLine("invalid Base64")case Ok(_) => io.writeLine("accepted")}}
invalid Base64 invalid Base64 invalid Base64 invalid Base64 invalid Base64 invalid Base64
Expected result
Expected result
Execution completes. Exit code 0.
invalid Base64invalid Base64invalid Base64invalid Base64invalid Base64invalid Base64
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 158 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 164 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 195 -
topaz.stdlib.contract.bytes-base64atworking-tree
Decode UTF-8 without replacing data
LinkDecode UTF-8 without replacing data
Bytes.decodeUtf8 returns Ok with the exact Unicode scalar sequence encoded by valid UTF-8 bytes.
Empty Bytes returns Ok with an empty string. A leading UTF-8 encoding of U+FEFF remains in the returned string.
Overlong encodings, isolated continuation bytes, incomplete sequences, surrogate encodings, and values above U+10FFFF return Err with a string.
Decoding does not insert replacement characters, normalize scalars, alter newline sequences, or discard a byte order mark.
For a string, encodeUtf8 followed by decodeUtf8 returns the original string. Re-encoding any successfully decoded sequence recovers its original bytes.
The receiver evaluates once and remains unchanged. No text is exposed before the entire sequence has passed validation.
Why
Lossless decoding keeps malformed input visible and preserves distinctions needed by file formats, checksums, and text layout.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 107 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 114 -
topaz.stdlib.contract.bytes-utf8atworking-tree
Retain a byte order mark and combining sequence
Linkimport std.bytes { Bytes }import std.ioimport std.testfor hex in (["", "efbbbf", "65cc81", "0d0a", "f09f9880"]) {let decoded = test.assertOk(test.assertOk(Bytes.fromHex(hex)).decodeUtf8())io.writeLine(decoded.encodeUtf8().toHex())}
efbbbf 65cc81 0d0a f09f9880
Expected result
Expected result
Execution completes. Exit code 0.
efbbbf65cc810d0af09f9880
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 107 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 114 -
topaz.stdlib.contract.bytes-utf8atworking-tree
Reject malformed UTF-8 categories
Linkimport std.bytes { Bytes }import std.ioimport std.testfor hex in (["80", "c080", "e282", "eda080", "f4908080"]) {match (test.assertOk(Bytes.fromHex(hex)).decodeUtf8()) {case Err(_) => io.writeLine("invalid UTF-8")case Ok(_) => io.writeLine("accepted")}}
invalid UTF-8 invalid UTF-8 invalid UTF-8 invalid UTF-8 invalid UTF-8
Expected result
Expected result
Execution completes. Exit code 0.
invalid UTF-8invalid UTF-8invalid UTF-8invalid UTF-8invalid UTF-8
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 107 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 114 -
topaz.stdlib.contract.bytes-utf8atworking-tree
Allocate buffers and convert byte values
LinkAllocate buffers and convert byte values
ByteBuffer.allocate accepts a nonnegative int length and an int initial value from 0 through 255. The initial value defaults to zero.
The new buffer has exactly that many copies of the initial byte. Zero length is valid and still requires a valid initial byte.
A negative length produces TPZ4001 at runtime. An invalid initial byte or an allocation that cannot be satisfied produces TPZ5001 at runtime.
ByteBuffer.fromBytes converts an immutable Bytes value into a mutable ByteBuffer value containing the same bytes.
ByteBuffer.toBytes converts the current buffer contents into an immutable Bytes value.
ByteBuffer.length is a read-only byte count property. Buffer operations never change its length.
Assignment, argument passing, return, capture, and aggregate storage follow collection value semantics.
Supplied expressions evaluate once from left to right before allocation or conversion. These operations have no I/O effects.
Why
A fixed length gives binary algorithms stable byte positions. Explicit conversion distinguishes mutable construction from immutable byte data.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 108 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 127 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 137 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 315 -
topaz.stdlib.contract.byte-buffer-storageatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Allocate zero-filled and initialized buffers
Linkimport std.bytes { ByteBuffer }import std.ioio.writeLine(ByteBuffer.allocate(0).toBytes().toHex())io.writeLine(ByteBuffer.allocate(3).toBytes().toHex())io.writeLine(ByteBuffer.allocate(2, 255).toBytes().toHex())
000000 ffff
Expected result
Expected result
Execution completes. Exit code 0.
000000ffff
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 108 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 127 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 137 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 315 -
topaz.stdlib.contract.byte-buffer-storageatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Keep the original buffer and converted bytes unchanged
Linkimport std.bytes { ByteBuffer }import std.iolet source = "ab".encodeUtf8()let buffer = ByteBuffer.fromBytes(source)let independent = ByteBuffer.fromBytes(source)let before = buffer.toBytes()let mut alias = bufferalias.set(0, 99)io.writeLine(source.toHex())io.writeLine(before.toHex())io.writeLine(independent.toBytes().toHex())io.writeLine(buffer.toBytes().toHex())
6162 6162 6162 6162
Expected result
Expected result
Execution completes. Exit code 0.
6162616261626162
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 108 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 127 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 137 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 315 -
topaz.stdlib.contract.byte-buffer-storageatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Reject a negative buffer length
Linkimport std.bytes { ByteBuffer }ByteBuffer.allocate(-1)
No stdout.
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4001byte-buffer-negative-bound atmain.tpz:2:1
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 108 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 127 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 137 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 315 -
topaz.stdlib.contract.byte-buffer-storageatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Validate the initial byte of an empty buffer
Linkimport std.bytes { ByteBuffer }import std.ioByteBuffer.allocate(0, -1)io.writeLine("after")
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 108 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 127 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 137 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 315 -
topaz.stdlib.contract.byte-buffer-storageatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Validate the initial byte of an empty buffer
Linkimport std.bytes { ByteBuffer }import std.ioByteBuffer.allocate(0, 256)io.writeLine("after")
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 108 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 127 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 137 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 315 -
topaz.stdlib.contract.byte-buffer-storageatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Diagnostics
LinkValidate buffer regions before writing
LinkValidate buffer regions before writing
ByteBuffer.get and ByteBuffer.set use zero-based byte indices from zero through length minus one. Get returns an int byte.
ByteBuffer.set replaces one byte. ByteBuffer.fill replaces length bytes beginning at start. Both require values from 0 through 255.
ByteBuffer.copy receives the source buffer, sourceStart, targetStart, and length in that order. The receiver is the destination.
Fill and copy use byte intervals from each start to start plus length. Starts and lengths must be nonnegative. Every complete source and destination interval must fit its buffer without arithmetic overflow.
A zero length region at the end of a buffer is valid. A start beyond the end is invalid even when length is zero.
Copy observes the source interval before its first destination write. Copying within one buffer therefore supports overlap in either direction.
Set, fill, and copy return unit. They require a let mut root binding and update its destination value under collection value semantics.
The receiver and supplied arguments evaluate once from left to right. Every range and byte check finishes before the first write.
An invalid index or region produces TPZ4001 at runtime. An invalid byte value produces TPZ5001 at runtime, including a fill of zero bytes.
A rejected operation performs no buffer writes. Effects performed while evaluating its receiver or arguments remain visible.
When several preconditions fail, the selected failing precondition is unspecified. The operation still completes every argument evaluation before validation and performs no writes.
Why
Checking complete regions prevents a malformed count from leaving half-written data. Reading the source interval before writing gives one result for every overlap direction.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 89 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 156 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 195 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 232 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 283 -
topaz.stdlib.contract.byte-buffer-mutationatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Copy overlapping regions and preserve an earlier buffer value
Linkimport std.bytes { Bytes, ByteBuffer }import std.ioimport std.testlet mut buffer = ByteBuffer.fromBytes(test.assertOk(Bytes.fromHex("000102030405")))let alias = bufferbuffer.copy(buffer, 0, 1, 5)io.writeLine(buffer.toBytes().toHex())buffer.fill(2, 2, 255)buffer.set(0, 128)io.writeLine(buffer.toBytes().toHex())buffer.copy(buffer, 1, 0, 5)buffer.fill(6, 0, 0)buffer.copy(buffer, 6, 6, 0)io.writeLine(buffer.toBytes().toHex())io.writeLine(alias.toBytes().toHex())io.writeLine("{alias.get(0)}")
000001020304 8000ffff0304 00ffff030404 000102030405 0
Expected result
Expected result
Execution completes. Exit code 0.
0000010203048000ffff030400ffff0304040001020304050
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 89 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 156 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 195 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 232 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 283 -
topaz.stdlib.contract.byte-buffer-mutationatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Keep an independent source buffer unchanged
Linkimport std.bytes { ByteBuffer }import std.iolet source = ByteBuffer.fromBytes("abc".encodeUtf8())let mut target = ByteBuffer.allocate(4, 0)target.copy(source, 1, 1, 2)io.writeLine(target.toBytes().toHex())io.writeLine(source.toBytes().toHex())
00626300 616263
Expected result
Expected result
Execution completes. Exit code 0.
00626300616263
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 89 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 156 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 195 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 232 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 283 -
topaz.stdlib.contract.byte-buffer-mutationatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Reject a read at the exclusive end
Linkimport std.bytes { ByteBuffer }let buffer = ByteBuffer.allocate(2)buffer.get(2)
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 89 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 156 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 195 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 232 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 283 -
topaz.stdlib.contract.byte-buffer-mutationatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Reject a negative write index
Linkimport std.bytes { ByteBuffer }let mut buffer = ByteBuffer.allocate(2)buffer.set(-1, 0)
No stdout.
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4001byte-buffer-negative-bound atmain.tpz:3:1
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 89 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 156 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 195 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 232 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 283 -
topaz.stdlib.contract.byte-buffer-mutationatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Reject a fill whose complete region does not fit
Linkimport std.bytes { ByteBuffer }let mut buffer = ByteBuffer.allocate(2)buffer.fill(1, 2, 0)
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 89 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 156 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 195 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 232 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 283 -
topaz.stdlib.contract.byte-buffer-mutationatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Reject an empty copy beyond the buffer end
Linkimport std.bytes { ByteBuffer }let mut buffer = ByteBuffer.allocate(2)buffer.copy(buffer, 3, 2, 0)
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 89 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 156 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 195 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 232 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 283 -
topaz.stdlib.contract.byte-buffer-mutationatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Reject an invalid byte at a valid write index
Linkimport std.bytes { ByteBuffer }import std.iolet mut buffer = ByteBuffer.allocate(1)buffer.set(0, -1)io.writeLine("after")
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 89 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 156 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 195 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 232 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 283 -
topaz.stdlib.contract.byte-buffer-mutationatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Validate the byte for a fill of zero bytes
Linkimport std.bytes { ByteBuffer }import std.iolet mut buffer = ByteBuffer.allocate(1)buffer.fill(1, 0, 256)io.writeLine("after")
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 89 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 156 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 195 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 232 - compiler/crates/topaz_value/src/value/builtins/byte_buffer.rs at
912a5e86e1f9· 283 -
topaz.stdlib.contract.byte-buffer-mutationatworking-tree - topaz.decision.collection-value-semantics.1 at
topaz.decisi
Compute interoperable checksums and digests
LinkCompute interoperable checksums and digests
Bytes.crc32 returns the unsigned CRC-32/ISO-HDLC value as an int from 0 through 4294967295.
CRC-32 uses width 32, polynomial 0x04c11db7, reflected input and output, initial value 0xffffffff, and final XOR 0xffffffff.
Bytes.sha256 and Bytes.sha512 implement FIPS 180-4 and return 32 and 64 digest bytes respectively.
Bytes.hmacSha256 uses its receiver as the key and its argument as the message. It returns the 32-byte HMAC-SHA-256 value from RFC 2104.
HMAC hashes a key longer than the 64-byte SHA-256 block before zero-padding it. Empty keys and messages are valid.
Empty input is valid for every checksum and digest. CRC-32 of empty input is zero.
These operations process stored bytes without decoding or normalization. Inputs remain unchanged and correctly typed calls have no data-dependent failure.
The receiver and any message argument evaluate once in that order. No external state, random input, or I/O affects the result.
Use toHex or toBase64 on a digest when a text encoding is required. Those encodings are separate from the digest bytes.
Why
Named standard algorithms must agree with independent implementations. Keeping digest bytes separate from their text representation makes the same digest usable in binary and text formats.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 22 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 947 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 1042 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 1158 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2963 -
topaz.stdlib.contract.bytes-digestsatworking-tree
Match established checksum and hash vectors
Linkimport std.bytes { Bytes }import std.ioio.writeLine("{Bytes.empty().crc32()}")let checksum = "123456789".encodeUtf8().crc32()io.writeLine("{checksum}")io.writeLine("abc".encodeUtf8().sha256().toHex())io.writeLine("abc".encodeUtf8().sha512().toHex())io.writeLine("key".encodeUtf8().hmacSha256("The quick brown fox jumps over the lazy dog".encodeUtf8()).toHex())
0 3421780262 ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8
Expected result
Expected result
Execution completes. Exit code 0.
03421780262ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015adddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49ff7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 22 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 947 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 1042 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 1158 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2963 -
topaz.stdlib.contract.bytes-digestsatworking-tree
Distinguish raw DEFLATE from zlib framing
LinkDistinguish raw DEFLATE from zlib framing
Bytes.deflateCompress returns Ok with one complete raw RFC 1951 DEFLATE stream. It adds no zlib or gzip header or checksum.
Bytes.deflateFixedCompress returns Ok with one final fixed Huffman block. Empty input is valid and the final unused bits are zero.
Fixed Huffman compression accepts at most 268435456 input bytes. Larger inputs return Err with a string before producing output.
Bytes.zlibFixedCompress applies the same fixed Huffman compression and input bound, with an RFC 1950 zlib header and Adler-32 trailer.
The zlib stream declares a 32768-byte window and no preset dictionary. Its header bytes are 0x78 and 0x01.
Bytes.deflateDecompress accepts raw streams containing stored, fixed Huffman, and dynamic Huffman blocks. It reconstructs the original bytes in Ok.
The decoder consumes one complete stream. Malformed or truncated blocks, invalid back-references, and complete trailing bytes return Err with a string.
Final unused padding bits are not decoded as data. A zlib or gzip wrapper is not a raw DEFLATE stream.
Bytes.deflateDecompress reverses either raw compressor for every supported input. Bytes.zlibFixedCompress requires a zlib decoder because its wrapper is part of the result.
Each receiver evaluates once and remains unchanged. The operations perform no I/O and errors expose no partially decoded Bytes.
Compression does not promise a particular size reduction. Except for the fixed block and wrapper requirements, encoded byte choices may change while preserving the stream format.
Why
Raw DEFLATE and zlib are different wire formats. The fixed Huffman operation additionally specifies block coding, so it serves a distinct format requirement rather than another name for a general compressor.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Recover bytes from a raw stream
Linkimport std.ioimport std.testlet encoded = test.assertOk("hello".encodeUtf8().deflateCompress())io.writeLine(test.assertOk(encoded.deflateDecompress()).toHex())io.writeLine(test.assertOk("".encodeUtf8().deflateFixedCompress()).toHex())io.writeLine(test.assertOk("".encodeUtf8().zlibFixedCompress()).toHex())
68656c6c6f 0300 7801030000000001
Expected result
Expected result
Execution completes. Exit code 0.
68656c6c6f03007801030000000001
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Decode a valid fixed Huffman stream
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("cb48cdc9c90700"))match (encoded.deflateDecompress()) {case Ok(bytes) => io.writeLine(bytes.toHex())case Err(_) => io.writeLine("rejected")}
68656c6c6f
Expected result
Expected result
Execution completes. Exit code 0.
68656c6c6f
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Decode short nonfinal stored blocks
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("000100feff41010100feff42"))match (encoded.deflateDecompress()) {case Ok(bytes) => io.writeLine(bytes.toHex())case Err(_) => io.writeLine("rejected")}
4142
Expected result
Expected result
Execution completes. Exit code 0.
4142
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Ignore stored block alignment bits
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("f90100feff41"))match (encoded.deflateDecompress()) {case Ok(bytes) => io.writeLine(bytes.toHex())case Err(_) => io.writeLine("rejected")}
41
Expected result
Expected result
Execution completes. Exit code 0.
41
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Reject truncated streams and trailing bytes
Linkimport std.bytes { Bytes }import std.ioimport std.testfor hex in (["", "010100feff", "010000ffff00", "070000"]) {match (test.assertOk(Bytes.fromHex(hex)).deflateDecompress()) {case Err(_) => io.writeLine("invalid DEFLATE")case Ok(_) => io.writeLine("accepted")}}
invalid DEFLATE invalid DEFLATE invalid DEFLATE invalid DEFLATE
Expected result
Expected result
Execution completes. Exit code 0.
invalid DEFLATEinvalid DEFLATEinvalid DEFLATEinvalid DEFLATE
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Read and write complete gzip members
LinkRead and write complete gzip members
Bytes.gzipCompress returns Ok with one RFC 1952 gzip member containing the receiver bytes. Empty input is valid.
The compressor does not read a clock or derive a filename from its environment. The header timestamp is zero and optional name and comment fields are absent.
Bytes.gzipDecompress accepts one member with compression method DEFLATE, including valid timestamp, operating system, extra field, name, comment, and header CRC fields.
The decoder accepts stored, fixed Huffman, and dynamic Huffman DEFLATE blocks. It validates the member CRC-32 and uncompressed size modulo 4294967296.
Reserved header flags, malformed optional fields, invalid compressed data, checksum mismatches, and truncation return Err with a string.
A second member or other bytes after the member return Err. A Bytes value represents one complete compressed payload in this API.
Decoding a successfully compressed value recovers the original bytes. A decoder failure never exposes a prefix of the output.
The receiver evaluates once and remains unchanged. Compression and decompression perform no I/O and do not decode the payload as text.
Why
Standard header and block handling allows gzip data to move between programs. Requiring one complete member prevents unconsumed suffixes from being silently discarded.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 81 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 118 -
topaz.stdlib.contract.bytes-gzipatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Recover empty and nonempty payloads
Linkimport std.ioimport std.testfor text in (["", "hello"]) {let encoded = test.assertOk(text.encodeUtf8().gzipCompress())io.writeLine(test.assertOk(encoded.gzipDecompress()).toHex())}
68656c6c6f
Expected result
Expected result
Execution completes. Exit code 0.
68656c6c6f
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 81 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 118 -
topaz.stdlib.contract.bytes-gzipatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Accept ordinary gzip header metadata
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("1f8b0800010000000003010500faff68656c6c6f86a6103605000000"))match (encoded.gzipDecompress()) {case Ok(bytes) => io.writeLine(bytes.toHex())case Err(_) => io.writeLine("rejected")}
68656c6c6f
Expected result
Expected result
Execution completes. Exit code 0.
68656c6c6f
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 81 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 118 -
topaz.stdlib.contract.bytes-gzipatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Accept compressed gzip blocks
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("1f8b08000000000000ffcb48cdc9c9070086a6103605000000"))match (encoded.gzipDecompress()) {case Ok(bytes) => io.writeLine(bytes.toHex())case Err(_) => io.writeLine("rejected")}
68656c6c6f
Expected result
Expected result
Execution completes. Exit code 0.
68656c6c6f
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 81 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 118 -
topaz.stdlib.contract.bytes-gzipatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Reject a truncated member and an invalid checksum
Linkimport std.bytes { Bytes }import std.ioimport std.testfor hex in (["1f8b0800", "1f8b08000000000000ff010500faff68656c6c6f87a6103605000000"]) {match (test.assertOk(Bytes.fromHex(hex)).gzipDecompress()) {case Err(_) => io.writeLine("invalid gzip")case Ok(_) => io.writeLine("accepted")}}
invalid gzip invalid gzip
Expected result
Expected result
Execution completes. Exit code 0.
invalid gzipinvalid gzip
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 81 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 118 -
topaz.stdlib.contract.bytes-gzipatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Use Zstandard frames and explicit effort levels
LinkUse Zstandard frames and explicit effort levels
Bytes.zstdCompress accepts an int level from 1 through 22. The default is 3 and other values return Err with a string.
The level is a compression effort hint. The API does not promise a size ratio, execution time, or different bytes for every pair of levels.
A successful call returns Ok with one RFC 8878 frame requiring no external dictionary. Empty input is valid.
Bytes.zstdDecompress accepts one standard frame containing raw, RLE, or compressed blocks, with valid frame parameters and an optional content checksum.
A frame requiring an unavailable dictionary, a malformed header or block, a size or checksum mismatch, and truncation return Err with a string.
Skippable frames, additional frames, and other trailing bytes return Err. The entire input must represent one data frame.
Decompression returns all uncompressed bytes in Ok or an error without a partial output. Compressing then decompressing preserves the input bytes.
The receiver and explicit level expression evaluate once in that order. The input remains unchanged and the operation performs no I/O.
Why
A bounded level range keeps calls portable. A complete frame boundary and explicit dictionary failure make the returned bytes independent of hidden decoder state.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 718 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 760 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 799 -
topaz.stdlib.contract.bytes-zstdatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Use the default and both supported level boundaries
Linkimport std.ioimport std.testlet source = "hello".encodeUtf8()io.writeLine(test.assertOk(test.assertOk(source.zstdCompress()).zstdDecompress()).toHex())for level in ([1, 22]) {io.writeLine(test.assertOk(test.assertOk(source.zstdCompress(level)).zstdDecompress()).toHex())}for level in ([0, 23]) {match (source.zstdCompress(level)) {case Err(_) => io.writeLine("invalid level")case Ok(_) => io.writeLine("accepted")}}
68656c6c6f 68656c6c6f 68656c6c6f invalid level invalid level
Expected result
Expected result
Execution completes. Exit code 0.
68656c6c6f68656c6c6f68656c6c6finvalid levelinvalid level
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 718 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 760 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 799 -
topaz.stdlib.contract.bytes-zstdatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Decode a valid Zstandard RLE block
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("28b52ffd20052b000041"))match (encoded.zstdDecompress()) {case Ok(bytes) => io.writeLine(bytes.toHex())case Err(_) => io.writeLine("rejected")}
4141414141
Expected result
Expected result
Execution completes. Exit code 0.
4141414141
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 718 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 760 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 799 -
topaz.stdlib.contract.bytes-zstdatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Decode short nonfinal Zstandard raw blocks
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("28b52ffd20020800004109000042"))match (encoded.zstdDecompress()) {case Ok(bytes) => io.writeLine(bytes.toHex())case Err(_) => io.writeLine("rejected")}
4142
Expected result
Expected result
Execution completes. Exit code 0.
4142
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 718 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 760 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 799 -
topaz.stdlib.contract.bytes-zstdatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Reject missing block data and trailing bytes
Linkimport std.bytes { Bytes }import std.ioimport std.testfor hex in (["", "28b52ffd20052900006869", "28b52ffd200001000000"]) {match (test.assertOk(Bytes.fromHex(hex)).zstdDecompress()) {case Err(_) => io.writeLine("invalid Zstandard")case Ok(_) => io.writeLine("accepted")}}
invalid Zstandard invalid Zstandard invalid Zstandard
Expected result
Expected result
Execution completes. Exit code 0.
invalid Zstandardinvalid Zstandardinvalid Zstandard
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 718 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 760 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 799 -
topaz.stdlib.contract.bytes-zstdatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Protect data with systematic Reed-Solomon codewords
LinkProtect data with systematic Reed-Solomon codewords
Bytes.reedSolomon255223Protect accepts between 1 and 14614305 input bytes. Empty input and larger input return Err with a string.
Input bytes are partitioned into consecutive 223-byte data chunks. The final chunk is padded with zero bytes to 223 bytes.
Each output codeword contains its 223 data bytes followed by 32 parity bytes. Codewords are concatenated in input order.
The result contains 255 times the ceiling of input length divided by 223 bytes. At most 65535 codewords are produced.
Field arithmetic uses GF256 with primitive polynomial 0x11d and primitive element 2. Generator roots are the powers of that element from 0 through 31.
Treat the first data byte as the highest-degree coefficient. Parity is the 32-byte remainder after multiplying the data polynomial by x to the power 32.
The output contains no original length or additional framing. Callers must retain the input length to distinguish padding from original trailing zero bytes.
The operation generates parity bytes. It does not detect or correct corruption in existing codewords.
The receiver evaluates once and remains unchanged. Input bounds are checked before output allocation and failure exposes no codeword prefix.
Why
A field definition and systematic layout make parity interoperable. Keeping the original length outside the codeword avoids silently guessing which trailing zero bytes belong to the payload.
Source evidence
- docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2935 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 552 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 594 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 622 -
topaz.stdlib.contract.bytes-reed-solomonatworking-tree
Protect a zero byte with zero padding and parity
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(test.assertOk(Bytes.fromArray([0])).reedSolomon255223Protect())io.writeLine("{encoded.toArray().length}")io.writeLine(encoded.slice(0, 4).toHex())io.writeLine(encoded.slice(223, 255).toHex())
255 00000000 0000000000000000000000000000000000000000000000000000000000000000
Expected result
Expected result
Execution completes. Exit code 0.
255000000000000000000000000000000000000000000000000000000000000000000000000
Source evidence
- docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2935 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 552 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 594 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 622 -
topaz.stdlib.contract.bytes-reed-solomonatworking-tree
Reject empty data before creating codewords
Linkimport std.bytes { Bytes }import std.iomatch (Bytes.empty().reedSolomon255223Protect()) {case Err(_) => io.writeLine("empty data rejected")case Ok(_) => io.writeLine("accepted")}
empty data rejected
Expected result
Expected result
Execution completes. Exit code 0.
empty data rejected
Source evidence
- docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2935 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 552 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 594 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 622 -
topaz.stdlib.contract.bytes-reed-solomonatworking-tree
Emit the specified parity for a nonzero payload
Linkimport std.ioimport std.testlet encoded = test.assertOk("hello".encodeUtf8().reedSolomon255223Protect())io.writeLine(encoded.slice(0, 5).toHex())io.writeLine(encoded.slice(223, 255).toHex())
68656c6c6f c7a146d71a5245bf94210961b0acac5f4358ac66cf234be24bcea41117eeb5fd
Expected result
Expected result
Execution completes. Exit code 0.
68656c6c6fc7a146d71a5245bf94210961b0acac5f4358ac66cf234be24bcea41117eeb5fd
Source evidence
- docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2935 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 552 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 594 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 622 -
topaz.stdlib.contract.bytes-reed-solomonatworking-tree