Skip to content

Runtime Control & Objects

C# Preview 4 APIs freeze the runtime-control and object-reference surface that managed packages must implement for NNRP/1. The managed names below intentionally match the Rust metadata semantics while using C# casing and ReadOnlySpan<byte> for hot paths.

Import

csharp
using Nnrp.Core;
using Nnrp.Runtime;

NnrpRuntimeControl.Encode

Encodes one Preview 4 control metadata object.

ParameterTypeRequiredDescription
messageTypeMessageTypeYesOne of the Preview 4 control message types.
metadataRuntime control metadataYesMetadata object matching messageType.
tailReadOnlySpan<byte>NoExtension bytes, diagnostic bytes, progress body, or partial-result body declared by metadata.
Returns
byte[]
csharp
var payload = NnrpRuntimeControl.Encode(
    MessageType.Progress,
    new ProgressMetadata(
        OperationId: 42,
        ProgressSequence: 1,
        StageCode: 2,
        PercentX100: 2500,
        ObjectId: 0,
        BodyBytes: 0));

NnrpRuntimeControl.Decode

Decodes one control metadata payload.

ParameterTypeRequiredDescription
messageTypeMessageTypeYesMessage type that selected the metadata layout.
payloadReadOnlySpan<byte>YesMetadata bytes plus the declared tail.
Returns
DecodedRuntimeControlMetadata

NnrpRuntimeObject.Encode

Encodes object, object-reference, object-delta, cache-reference, and cache-miss metadata.

ParameterTypeRequiredDescription
messageTypeMessageTypeYesOne of ObjectDeclare, ObjectRef, ObjectRelease, ObjectPatch, ObjectDelta, CacheReference, or CacheMiss.
metadataRuntime object metadataYesMetadata object matching messageType.
tailReadOnlySpan<byte>NoExtension bytes, diagnostics, or delta payload declared by metadata.
Returns
byte[]

NnrpRuntimeObject.Decode

Decodes one runtime object or cache metadata payload.

ParameterTypeRequiredDescription
messageTypeMessageTypeYesMessage type that selected the metadata layout.
payloadReadOnlySpan<byte>YesMetadata bytes plus the declared tail.
Returns
DecodedRuntimeObjectMetadata

NnrpWebSocketFrameCodec.Encode

Builds the binary frame used by the WebSocket transport.

ParameterTypeRequiredDescription
headerRuntimeFrameHeaderYesHeader fields except metadata/body lengths; the helper derives both lengths from the buffers.
metadataReadOnlySpan<byte>NoMetadata payload.
bodyReadOnlySpan<byte>NoBody payload.
Returns
byte[]

NnrpWebSocketFrameCodec.Decode

Splits one WebSocket binary frame into header, metadata slice, and body slice.

ParameterTypeRequiredDescription
frameReadOnlySpan<byte>YesOne complete WebSocket binary message.
Returns
DecodedRuntimeFrame

NnrpWebSocketFrameCodec.DecodeBatch

Decodes concatenated binary frames from local buffers and conformance fixtures.

ParameterTypeRequiredDescription
batchReadOnlySpan<byte>YesConcatenated frames.
limitintNoMaximum decoded frames; 0 means no limit.
Returns
IReadOnlyList<DecodedRuntimeFrame>

Runtime Control Metadata

TypeMessage typesFrozen properties
ControlRequestMetadataCancel, AbortOperationId, ControlSequence, ReasonCode, SourceRole, Flags, DiagnosticBytes
SchedulingMetadataPriorityUpdate, Deadline, ExpireAtOperationId, ControlSequence, PriorityClass, PriorityDelta, DeadlineUnixMs, Flags
SupersedeMetadataSupersedeOldOperationId, NewOperationId, ControlSequence, DropReasonCode, Flags, DiagnosticBytes
BudgetMetadataBudgetUpdateOperationId, ComputeBudgetUnits, MemoryBudgetBytes, BandwidthBudgetBytes, TokenBudget, Flags
ProgressMetadataProgressOperationId, ProgressSequence, StageCode, PercentX100, ObjectId, BodyBytes
PartialResultMetadataPartialResultOperationId, ResultSequence, ObjectId, DeltaSequence, BodyBytes, Flags
PressureMetadataBackpressure, CreditUpdateScopeId, CreditWindow, PressureLevel, PressureReason, RetryAfterMs, Flags
CapabilityMetadataCapabilityNegotiation, DegradeProfileProfileId, CapabilityCount, CostModelId, PreferenceRank, LimitBytes, LimitUnits, BodyBytes, Flags
RouteHintMetadataRouteHint, ExecutionHintOperationId, RouteId, ExecutorClass, AffinityClass, DeadlineUnixMs, BodyBytes, Flags
TraceContextMetadataTraceContextTraceId, SpanId, ParentSpanId, StageCode, Flags, BodyBytes
ResultDropReasonMetadataResultDropReasonOperationId, ResultSequence, DropReasonCode, SourceRole, Flags, DiagnosticBytes
RecoverableErrorMetadataErrorRecoverableErrorCode, ErrorScope, RecoveryAction, SourceRole, Flags, RetryAfterMs, RelatedSessionId, RelatedFrameId, RelatedViewId, DiagnosticBytes
RetryAfterMetadataRetryAfterScopeId, ControlSequence, RetryAfterMs, JitterMs, ReasonCode, SourceRole, Flags, DiagnosticBytes

Runtime Object Metadata

TypeMessage typesFrozen properties
ObjectDescriptorMetadataObjectDeclareObjectId, ObjectKind, ProducerRole, ConsumerRole, SessionId, ByteSize, ComputeCostUnits, MemoryLocationHint, OwnershipHint, LifetimeHintMs, MetadataBytes
ObjectReferenceMetadataObjectRefObjectId, OperationId, ObjectVersion, Offset, Length, Flags, MetadataBytes
ObjectReleaseMetadataObjectReleaseObjectId, OperationId, ReleaseReason, SourceRole, Flags, DiagnosticBytes
ObjectDeltaMetadataObjectPatch, ObjectDeltaObjectId, DeltaSequence, RegionOffset, RegionBytes, DeltaBytes, Flags, MetadataBytes
CacheReferenceMetadataCacheReferenceCacheKeyHi, CacheKeyLo, ProfileId, ReuseScope, LeaseId, ProducerTraceId, ExpirationHintMs, MetadataBytes, Flags
CacheMissMetadataCacheMissCacheKeyHi, CacheKeyLo, MissReason, ProfileId, DiagnosticBytes

Runtime Enums

EnumMembers
RuntimeObjectKindUnspecified, Tensor, TokenBlock, ImageTile, FeatureMap, ToolResult, TraceSegment, OpaqueBytes, DocumentChunk, AudioChunk, VideoChunk, RoutePlan, CacheManifest
RuntimeRoleUnspecified, Client, Server, Runtime, Subagent, Tool, Scheduler, ConformanceRunner
MemoryLocationHintUnspecified, HostMemory, DeviceMemory, SharedMemory, RemoteMemory, MmapFile, ObjectStore
OwnershipHintUnspecified, ProducerOwned, ConsumerOwned, SessionOwned, Borrowed, TransferOnRef, ReleaseOnDrop
ObjectReleaseReasonCompleted, Cancelled, Expired, Replaced, Invalidated, OwnerClosed, LeaseExpired, ConformanceInjection
CacheReuseScopeOperation, Session, Connection, Global, Tenant, Profile
CacheMissReasonUnknown, NotFound, Expired, Invalidated, SchemaMismatch, ProducerUnavailable, LeaseRequired, PermissionDenied

RuntimeFrameHeader

PropertyTypeDescription
MessageTypeMessageTypeFrame message type.
FlagsHeaderFlagsHeader flags.
SessionIduintSession id.
GenerationuintSession generation.
FrameIduintFrame id.

NNRP Documentation