Skip to content

Rust — Core Types

nnrp-core is the canonical Rust source for NNRP/1 Preview4 protocol semantics. It owns wire constants, fixed-layout metadata, profile registries, runtime-control frames, object/cache metadata, validation, and reusable lifecycle state machines.

Dependency

toml
[dependencies]
nnrp-core = "1.0.0-preview.4.17"

Boundary

nnrp-core does not open sockets or spawn async tasks. It defines and validates the protocol model that nnrp-runtime, transport providers, FFI bindings, WASM helpers, and conformance suites reuse.

Baseline Metadata Codecs

The frozen baseline metadata types used by Preview 4 role APIs and public Conformance cases expose the same Rust codec shape: Type::to_bytes() encodes the exact-width value and Type::parse() decodes and validates it. This includes ClientHelloMetadata, SessionPatchAckMetadata, FlowUpdateMetadata, ResultHintMetadata, FrameSubmitMetadata, ResultPushMetadata, CachePutMetadata, CacheAckMetadata, CacheInvalidateMetadata, TransportProbeMetadata, TransportProbeAckMetadata, and ObjectReferenceBlock.

Parsing rejects incorrect widths, non-zero reserved fields, invalid enum values, and invalid flag combinations. Conformance and downstream bindings reuse these codecs instead of maintaining a second wire implementation.

Main Type Families

FamilyExamplesUsed by
Protocol header and message idscommon header, message type, header flags, protocol versionall wire codecs
Session lifecycleSessionOpenMetadata, SessionCloseMetadata, patch/migrate metadataclient/server runtime
Submit/resultFrameSubmitMetadata, ResultPushMetadata, result-drop metadatarequest/result flow
Flow and schedulingcredit, backpressure, priority, deadline, expire-at metadataruntime control
Runtime controlcancel/abort, progress, partial result, capability, route hint, trace contextPreview4 control profiles
Runtime objectobject declare/ref/release/delta metadataheavy transport and orchestration paths
Cache referencecache reference/miss/invalidate metadatacache-aware profiles and runtimes
Registryprofile ids, schema ids, payload families, object kindsconformance and SDK validation

FrameSubmitMetadata

Field GroupDescription
Profile and schemaSelects which standard or application profile interprets the body.
Operation identityoperation_id: u64 is non-zero and independent from the common-header frame_id: u32.
Priority and deadlineProvides scheduling hints without forcing JSON/protobuf control envelopes.
Object/cache hintsAllows transports and runtimes to coordinate large payload references.

The canonical 72-byte offsets are frozen in Data Plane and Operation Identity. Rust must encode tile_index_bytes at offset 32 and operation_id at offset 40.

ResultPushMetadata

Field GroupDescription
CorrelationTies result bytes back to a submitted frame.
Status and timingCarries completion state and timing hints.
Payload interpretationPoints to the profile/schema used for the result body.

Runtime-Control Metadata

The Rust metadata names mirror the wire profiles documented under Runtime Control Profiles.

Control familyPurpose
Cancel / abortStop expired or obsolete work.
Priority / deadline / expire-atUpdate scheduler decisions after submit.
Progress / partial resultStream meaningful intermediate output.
Backpressure / creditCoordinate producer and consumer pressure.
Capability / route hintExchange costs, preferences, limits, and execution hints.
Trace context / result-drop reasonMake end-to-end timing and dropped work explainable.

Object And Cache Metadata

FamilyPurpose
Object declareIntroduces a runtime object with kind, size, version, and lifetime hints.
Object refRefers to an existing object instead of resending bytes.
Object releaseReleases ownership or lease state.
Object deltaSends compact updates for an existing object.
Cache referenceReports a reusable cached object.
Cache missReports that a requested cache key is unavailable.
Cache invalidateInvalidates stale object/cache state.

Every Rust cache type uses the same CacheObjectId identity:

rust
pub struct CacheObjectId {
    pub cache_namespace: u32,
    pub cache_key_hi: u64,
    pub cache_key_lo: u64,
    pub object_kind: CacheObjectKind,
}

CachePutMetadata, CacheAckMetadata, CacheInvalidateMetadata, CacheReferenceMetadata, CacheMissMetadata, and ObjectReferenceBlock expose the same cache_namespace: u32, cache_key_hi: u64, and cache_key_lo: u64 fields. The fixed layouts are frozen in Cache Capabilities and Leases and Runtime Object and Cache Metadata.

CacheLease

CacheLease is the validated local lease value. It is not a wire payload or an FFI handle.

Rust fieldTypeProtocol field
object_idCacheObjectIdobject_id
object_versionu64object_version
lease_idu64lease_id
owner_scopeCacheLeaseOwnerScopeowner_scope
owner_idu64owner_id
granted_at_msu64granted_at_ms
ttl_msu32ttl_ms

CacheLeaseOwnerScope is Connection = 0, Session = 1, or Operation = 2. Use expires_at_ms, validate_live_at, and validate_version instead of duplicating lease arithmetic in an application.

Common Pitfalls

WARNING

  1. Do not reassign numeric message, profile, schema, object-kind, or error values in SDK-local code.
  2. Do not put transport behavior in nnrp-core; use nnrp-runtime and provider crates.
  3. Do not tunnel Preview4 control semantics through ad hoc JSON when a compact control frame already exists.

NNRP Documentation