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
| Type | Kind | Description |
|---|---|---|
Algorithm | record | Checksum metadata and a factory for independent state. |
Checksum | interface | Owned incremental checksum state with non-consuming numeric reads. |
Functions
| Function | Kind | Description |
|---|---|---|
algorithm | function | Requires a checksum algorithm descriptor. |
algorithms | function | Lists available canonical checksum names in ascending order. |
create | function | Creates independent owned checksum state. |
lookup | function | Finds a checksum algorithm without creating incremental state. |
value | function | Computes 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
endChecksum metadata and a factory for independent state.
Methods
create#
Creates independent owned state for incremental updates and snapshots.
Arguments
| Name | Type | Description |
|---|---|---|
self | any |
Returns
| Type | Description |
|---|---|
Checksum |
Fields
Checksuminterface#
affine interface Checksum is nupp.Closeable
terminal close: 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
endOwned incremental checksum state with non-consuming numeric reads.
Methods
close#
Consumes this context and releases its provider state without suspension.
Arguments
| Name | Type | Description |
|---|---|---|
takes self | Checksum |
Returns
| Type | Description |
|---|---|
nil |
algorithm#
Returns the canonical algorithm name.
Arguments
| Name | Type | Description |
|---|---|---|
self | Checksum |
Returns
| Type | Description |
|---|---|
string |
width#
width: function(self: Checksum): integerReturns the number of meaningful bits in each snapshot.
Arguments
| Name | Type | Description |
|---|---|---|
self | Checksum |
Returns
| Type | Description |
|---|---|
integer |
update#
Processes raw bytes while retaining no input views.
Arguments
| Name | Type | Description |
|---|---|---|
exclusive self | Checksum | |
bytes | string |
Returns
| Type | Description |
|---|---|
nil |
Functions#
algorithmfunction#
Requires a checksum algorithm descriptor.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | the canonical checksum algorithm name |
Returns
| Type | Description |
|---|---|
Algorithm | the selected descriptor |
Raises
when the algorithm is unavailable
algorithmsfunction#
function algorithms(): {string}Lists available canonical checksum names in ascending order.
Returns
| Type | Description |
|---|---|
{string} | the available names |
createfunction#
Creates independent owned checksum state.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | the canonical checksum algorithm name |
Returns
| Type | Description |
|---|---|
Checksum | an unfinished checksum context |
lookupfunction#
Finds a checksum algorithm without creating incremental state.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | the canonical checksum algorithm name |
Returns
| Type | Description |
|---|---|
Algorithm? | the descriptor, or nil when unavailable |
valuefunction#
Computes a checksum; its bit width belongs to the algorithm descriptor.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | the canonical checksum algorithm name |
bytes | string | the message bytes |
Returns
| Type | Description |
|---|---|
uint64 | the unsigned checksum value |