Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Библиотека · std.bytes

    Bytes.reedSolomon255223Protect

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

    reedSolomon255223Protect() -> Result<Bytes, string>
    Модуль
    std.bytes →
    Получатель
    Bytes
    Минимальное число аргументов
    0
    Максимальное число аргументов
    0

    Declaration and parameters

    Ссылка

    Доступность

    Включено по умолчанию · Не определено

    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.

    Получатель

    Bytes

    Ограничения параметров

    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.

    Результат

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

    Эффекты

    Ошибки

    Result and effects

    Ссылка

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

    Resolved contracts

    Ссылка

    Related entries

    Ссылка

    std.bytes →

    Protect data with systematic Reed-Solomon codewords

    Ссылка
    Правилоtopaz.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.

    Причина

    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.

    Protect a zero byte with zero padding and parity

    Ссылка
    main.tpzProtect a zero byte with zero padding and parityОткрыть песочницу →
    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())
    Ожидаемый выводКод завершения 0
    255
    00000000
    0000000000000000000000000000000000000000000000000000000000000000
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 255
    2. 00000000
    3. 0000000000000000000000000000000000000000000000000000000000000000

    Reject empty data before creating codewords

    Ссылка
    main.tpzReject empty data before creating codewordsОткрыть песочницу →
    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. }
    Ожидаемый выводКод завершения 0
    empty data rejected
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. empty data rejected

    Emit the specified parity for a nonzero payload

    Ссылка
    main.tpzEmit the specified parity for a nonzero payloadОткрыть песочницу →
    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())
    Ожидаемый выводКод завершения 0
    68656c6c6f
    c7a146d71a5245bf94210961b0acac5f4358ac66cf234be24bcea41117eeb5fd
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 68656c6c6f
    2. c7a146d71a5245bf94210961b0acac5f4358ac66cf234be24bcea41117eeb5fd

    Меню

    Загрузка →