Skip to content

C# — Enums & Constants

Enums are defined in the Nnrp.Core namespace and shared across all other namespaces.

Import

csharp
using Nnrp.Core;

Wire Format

WireFormat

MemberValueDescription
Current0Only supported wire format (NNRP/1)

Message Types

MessageType

MemberValueDirectionDescription
ClientHello0x01C→SConnection setup
ServerHelloAck0x02S→CHandshake acknowledgement
SessionPatch0x03C→SSession parameter update request
SessionPatchAck0x04S→CSession parameter update result
Close0x05BothGraceful close
Error0x06BothProtocol error notification
FrameSubmit0x10C→SSubmit a frame
FrameCancel0x11C→SCancel a frame
ResultPush0x12S→CPush inference result
ResultDrop0x13S→CNotify result dropped
CachePut0x14C→SStore a cache object
CacheAck0x15S→CCache store result
CacheInvalidate0x16C→SInvalidate cache
FlowUpdate0x17BothFlow control window update
ResultHint0x18S→CServer hint
TransportProbe0x19BothTransport path probe
TransportProbeAck0x1ABothPath probe acknowledgement
SessionMigrate0x1BS→CSession migration notification
SessionMigrateAck0x1CC→SSession migration confirmation
Ping0x20BothKeep-alive probe
Pong0x21BothKeep-alive response

Header Flags

HeaderFlags ([Flags])

MemberMaskDescription
None0x00No flags
AckRequired0x01Receiver must acknowledge
CanDrop0x02May be dropped under backpressure
Stale0x04Data is stale
Eos0x08End of stream
Retransmit0x10Retransmitted packet
Keyframe0x20Keyframe

Frame Classification

FrameClass

MemberValueDescription
Keyframe0Complete keyframe
Delta1Delta frame
Retransmit2Retransmit frame
Discardable3May be skipped

Error Codes

ErrorCode

MemberValueDescription
UnsupportedVersion0x0001Unsupported protocol version
AuthFailed0x0002Authentication failed
InvalidState0x0003Operation not allowed in current state
MalformedHeader0x0004Malformed header
MalformedBody0x0005Malformed body
UnsupportedCapability0x0006Unsupported capability
LimitExceeded0x0007Limit exceeded
FrameExpired0x0008Frame expired
FrameCancelled0x0009Frame cancelled by client
CacheMiss0x000ACache object not found
ServerBusy0x000BServer temporarily unable to process
InternalError0x000CServer internal error

Transport & Connection

TransportId

MemberValueDescription
Unspecified0Unspecified
Quic1QUIC transport
Tcp2TCP transport

TransportPolicy

MemberValueDescription
Auto0Automatic selection
PreferQuic1Prefer QUIC
PreferTcp2Prefer TCP
ForceQuic3Force QUIC
ForceTcp4Force TCP

LossTolerance

MemberValueDescription
Strict0No packet loss allowed
BestEffort1Best effort
LowLatency2Low latency preferred, minor loss tolerated
FireAndForget3High loss tolerance

Data-plane Enums

InputProfile

MemberValueDescription
Unspecified0Unspecified
ChangedTilesLuma1Luma data for changed tiles only
DenseLumaFrame2Full-frame luma data

TileIndexMode

MemberValueDescription
DenseRange0Dense contiguous range
RawU161Raw uint16 list
DeltaU162Delta-encoded uint16
Bitset3Bitset encoding

DTypeId

MemberValueDescription
Fp160Half-precision float
Fp321Single-precision float
Fp8E4M32FP8 E4M3
Fp8E5M23FP8 E5M2
Int84Signed 8-bit integer
Uint85Unsigned 8-bit integer
Int166Signed 16-bit integer
Uint167Unsigned 16-bit integer

SubmitMode

MemberValueDescription
Inline0All objects inlined in body
Reference1Objects referenced via cache keys
Mixed2Mix of inline and reference

BudgetPolicy ([Flags])

MemberMaskDescription
None0x00Strict; no degradation
AllowPartial0x01Allow partial results
AllowStaleReuse0x02Allow stale cache reuse
AllowDegraded0x04Allow quality degradation
AllowDrop0x08Allow dropping the frame

ResultClass

MemberValueDescription
Complete0Complete result
Partial1Partial result
StaleReuse2Reused stale cached result
Degraded3Quality-degraded result

ResultFlags ([Flags])

MemberMaskDescription
None0x0000No flags
Stale0x0001Stale result
Fallback0x0002Fallback path used
Partial0x0004Incomplete result

Cache Enums

CacheObjectKind

MemberValueDescription
CameraBlock0x0001Camera parameter block
TileIndexBlock0x0002Tile index block
TensorSectionTable0x0003Tensor section table
CodecTable0x0004Codec auxiliary table
ReusableResultObject0x0005Reusable result
PayloadLayoutTemplate0x0006Payload layout template
PromptSegment0x0007Prompt segment (LLM)
ToolSchema0x0008Tool schema
StructuredEventSchema0x0009Structured event schema

CacheAckStatus

MemberValueDescription
Stored0Successfully stored
Rejected1Rejected (capacity or policy)
Duplicate2Duplicate (already exists)

CacheInvalidateScope

MemberValueDescription
Single0Single object by key
ByKind1All objects of specified kind
All2All objects in session

CachePutFlags ([Flags])

MemberMaskDescription
None0x00Default
Pinned0x01Pinned; exempt from LRU eviction
Reusable0x02Cross-frame reusable

Session Patch Enums

SessionPatchField ([Flags])

MemberMaskDescription
TargetCadence0x0001Target frame rate
QualityTier0x0002Quality tier
ActiveLaneMask0x0004Active view mask
PreferredCodec0x0008Preferred codec
PreferredCompression0x0010Preferred compression level

SessionPatchAckStatus

MemberValueDescription
Applied0Patch applied successfully
PartiallyApplied1Partially applied
Rejected2Patch rejected

SessionPatchRejectReason

MemberValueDescription
None0No rejection
InvalidValue1Invalid value
UnsupportedField2Unsupported field
StateConflict3Conflicts with current state

Flow Control Enums

FlowUpdateScopeKind

MemberValueDescription
Connection0Connection level
Session1Session level
Operation2Operation level

FlowUpdateReason

MemberValueDescription
Grant0Grant more credit
Reduce1Reduce credit
Pause2Pause
Resume3Resume
Congestion4Congestion notification

FlowUpdateBackpressureLevel

MemberValueDescription
None0No backpressure
Soft1Soft (advisory)
Hard2Hard (mandatory)

FlowUpdateFlags ([Flags])

MemberMaskDescription
None0x00None
CreditValid0x01Credit field is valid
RetryAfterValid0x02RetryAfterMs is valid
BackgroundOnly0x04Applies only to background ops
DrainInFlightOnly0x08Takes effect after in-flight ops drain

Use-Case Guide

Connecting and Negotiating Transport

csharp
var profile = new NnrpClientProfile
{
    TransportPolicy = TransportPolicy.PreferQuic,
    LossTolerance   = LossTolerance.LowLatency,
};

Pitfalls

  • ForceQuic hard-fails in TCP-only firewalls. Use PreferQuic in production.
  • LossTolerance.FireAndForget does not guarantee ordering; do not use it on the main frame path.

Submitting Frames with Budget Policy

csharp
var req = new NnrpSubmitRequest
{
    FrameId           = frameId,
    TileIds           = changedTiles,
    Sections          = new[] { tensorSection },
    InputProfile      = InputProfile.ChangedTilesLuma,
    SubmitMode        = SubmitMode.Inline,
    BudgetPolicy      = BudgetPolicy.AllowPartial | BudgetPolicy.AllowStaleReuse,
    InferenceBudgetMs = 8,
};

Pitfalls

  • BudgetPolicy is a bitmask. Combine values with |.
  • SubmitMode.Reference requires a prior PutCacheAsync() call.

Result Handling

csharp
switch (result.ResultClass)
{
    case ResultClass.Complete:   ApplyFull(result);   break;
    case ResultClass.Partial:    ApplyPartial(result); break;
    case ResultClass.StaleReuse: break;
    case ResultClass.Degraded:
        Log.Warn("Degraded: {0}", result.AppliedBudgetPolicy);
        break;
}

Error Handling

csharp
catch (NnrpProtocolException ex)
{
    if (ex.ErrorScope == ErrorScope.Connection)
    {
        await session.DisposeAsync();
        session = await client.OpenSessionAsync();
    }
    else if (ex.ErrorCode == ErrorCode.FrameExpired)
    {
        // Frame-level; skip and continue
    }
}

Pitfalls

  • ErrorScope.Connection errors are fatal. Do not retry on the same session.

NNRP Documentation