reed Solomon255223 Protect() - > Result<Bytes, string>- Module
- std.
bytes - Receiver
- Bytes
- Minimum arity
- 0
- Maximum arity
- 0
Declaration and parameters
LinkAvailability
Included by default: Pending
Import 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.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1272 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 52 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1272 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 519 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1296 - compiler/crates/topaz_value/src/value/members.rs at
b48527d0a174· 237
Receiver
Bytes
Parameter constraints
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.
Related rule: Protect data with systematic Reed-Solomon codewordsResult
The declared result type is Result<Bytes, string>.
Effects
Failures
Result and effects
LinkProtect nonempty data with systematic 255-byte codewords containing 223 data bytes and 32 parity bytes. At most 65535 codewords are produced.
Resolved contracts
LinkRelated entries
LinkProtect 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