nupp.checksum

Incremental numeric checksums for accidental corruption detection. The canonical CRC variants are crc32-ieee, crc32c and crc64-ecma (ECMA-182, non-reflected, zero initialization and zero final xor). Adler-32 is adler32. value() is a non-consuming snapshot; protocol code chooses byte order when serializing the number. These algorithms provide no authentication.

Setup selects a typed catalog through nupp.runtime.services.checksum before this module loads. Initialization validates and retains algorithm descriptors. An explicit selection overrides matching built-ins and may add names; unselected built-ins remain available. Lookup and context operations use the retained catalog without SPI resolution. Provider names identify implementations, independently of the algorithm names in their catalogs.

Module contents

Types

TypeKindDescription
AlgorithmrecordChecksum metadata and a factory for independent state.
ChecksuminterfaceOwned incremental checksum state with non-consuming numeric reads.

Functions

FunctionKindDescription
algorithmfunctionRequires a checksum algorithm descriptor.
algorithmsfunctionLists available canonical checksum names in ascending order.
createfunctionCreates independent owned checksum state.
lookupfunctionFinds a checksum algorithm without creating incremental state.
valuefunctionComputes a checksum; its bit width belongs to the algorithm descriptor.

Types#

Algorithmrecord#

record Algorithm
    readonly name: string
    readonly width: integer
    function create(self): Checksum end
end

Checksum metadata and a factory for independent state.

Methods

create#
create: function create(self): Checksum

Creates independent owned state for incremental updates and snapshots.

Arguments
NameTypeDescription
selfany
Returns
TypeDescription
Checksum

Fields

name#
name: string

Canonical algorithm name.

width#
width: integer

Number of meaningful checksum bits, from one through 64.

Checksuminterface#

affine interface Checksum is nupp.Closeable
    terminal close: nosuspend function(takes self: Checksum): nil
    algorithm: function(self: Checksum): string
    width: function(self: Checksum): integer
    update: function(exclusive self: Checksum, bytes: string): nil
    updateSpan: function(exclusive self: Checksum, borrows bytes: span.ByteSpan): nil
    value: function(self: Checksum): uint64
end

Owned incremental checksum state with non-consuming numeric reads.

Methods

close#
close: nosuspend function(takes self: Checksum): nil

Consumes this context and releases its provider state without suspension.

Arguments
NameTypeDescription
takes selfChecksum
Returns
TypeDescription
nil
algorithm#
algorithm: function(self: Checksum): string

Returns the canonical algorithm name.

Arguments
NameTypeDescription
selfChecksum
Returns
TypeDescription
string
width#
width: function(self: Checksum): integer

Returns the number of meaningful bits in each snapshot.

Arguments
NameTypeDescription
selfChecksum
Returns
TypeDescription
integer
update#
update: function(exclusive self: Checksum, bytes: string): nil

Processes raw bytes while retaining no input views.

Arguments
NameTypeDescription
exclusive selfChecksum
bytesstring
Returns
TypeDescription
nil
updateSpan#
updateSpan: function(exclusive self: Checksum, borrows bytes: span.ByteSpan): nil

Processes a borrowed byte view without retaining it.

Arguments
NameTypeDescription
exclusive selfChecksum
borrows bytesspan.ByteSpan
Returns
TypeDescription
nil
value#
value: function(self: Checksum): uint64

Returns an unsigned snapshot without consuming this context.

Arguments
NameTypeDescription
selfChecksum
Returns
TypeDescription
uint64

Functions#

algorithmfunction#

function algorithm(name: string): Algorithm

Requires a checksum algorithm descriptor.

Arguments

NameTypeDescription
namestring

the canonical checksum algorithm name

Returns

TypeDescription
Algorithm

the selected descriptor

Raises

  • when the algorithm is unavailable

algorithmsfunction#

function algorithms(): {string}

Lists available canonical checksum names in ascending order.

Returns

TypeDescription
{string}

the available names

createfunction#

function create(name: string): Checksum

Creates independent owned checksum state.

Arguments

NameTypeDescription
namestring

the canonical checksum algorithm name

Returns

TypeDescription
Checksum

an unfinished checksum context

lookupfunction#

function lookup(name: string): Algorithm?

Finds a checksum algorithm without creating incremental state.

Arguments

NameTypeDescription
namestring

the canonical checksum algorithm name

Returns

TypeDescription
Algorithm?

the descriptor, or nil when unavailable

valuefunction#

function value(name: string, bytes: string): uint64

Computes a checksum; its bit width belongs to the algorithm descriptor.

Arguments

NameTypeDescription
namestring

the canonical checksum algorithm name

bytesstring

the message bytes

Returns

TypeDescription
uint64

the unsigned checksum value