Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Library · std.bytes

    Bytes.reedSolomon255223Protect

    Applies Reed-Solomon 255/223 protection to this byte sequence.

    reedSolomon255223Protect() -> Result<Bytes, string>
    Module
    std.bytes
    Receiver
    Bytes
    Minimum arity
    0
    Maximum arity
    0

    Declaration and parameters

    Link

    Availability

    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

    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.

    Result

    The declared result type is Result<Bytes, string>.

    Effects

    Failures

    Result and effects

    Link

    Protect nonempty data with systematic 255-byte codewords containing 223 data bytes and 32 parity bytes. At most 65535 codewords are produced.

    Resolved contracts

    Link

    Related entries

    Link

    std.bytes

    Protect data with systematic Reed-Solomon codewords

    Link
    Ruletopaz.stdlib.contract.bytes-reed-solomon.rule

    Protect 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

    Protect a zero byte with zero padding and parity

    Link
    main.tpzProtect a zero byte with zero padding and parityOpen in Playground
    1. import std.bytes { Bytes }
    2. import std.io
    3. import std.test
    4. let encoded = test.assertOk(test.assertOk(Bytes.fromArray([0])).reedSolomon255223Protect())
    5. io.writeLine("{encoded.toArray().length}")
    6. io.writeLine(encoded.slice(0, 4).toHex())
    7. io.writeLine(encoded.slice(223, 255).toHex())
    Expected outputexit 0
    255
    00000000
    0000000000000000000000000000000000000000000000000000000000000000
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 255
    2. 00000000
    3. 0000000000000000000000000000000000000000000000000000000000000000
    Source evidence

    Reject empty data before creating codewords

    Link
    main.tpzReject empty data before creating codewordsOpen in Playground
    1. import std.bytes { Bytes }
    2. import std.io
    3. match (Bytes.empty().reedSolomon255223Protect()) {
    4. case Err(_) => io.writeLine("empty data rejected")
    5. case Ok(_) => io.writeLine("accepted")
    6. }
    Expected outputexit 0
    empty data rejected
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. empty data rejected
    Source evidence

    Emit the specified parity for a nonzero payload

    Link
    main.tpzEmit the specified parity for a nonzero payloadOpen in Playground
    1. import std.io
    2. import std.test
    3. let encoded = test.assertOk("hello".encodeUtf8().reedSolomon255223Protect())
    4. io.writeLine(encoded.slice(0, 5).toHex())
    5. io.writeLine(encoded.slice(223, 255).toHex())
    Expected outputexit 0
    68656c6c6f
    c7a146d71a5245bf94210961b0acac5f4358ac66cf234be24bcea41117eeb5fd
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 68656c6c6f
    2. c7a146d71a5245bf94210961b0acac5f4358ac66cf234be24bcea41117eeb5fd
    Source evidence

    Menu

    Download