Skip to content

C# - 枚举与常量

C# SDK 使用 NNRP/1 Preview4 冻结的名称和数值。公共角色 API 暴露 typed enum;调用者不得向协议 字段传入任意整数。

csharp
using Nnrp.Core;
using Nnrp.Runtime;

消息类型

MessageType : byte 按线路职责分组。

分组成员与数值
连接/会话ClientHello=0x01, ServerHelloAck=0x02, SessionPatch=0x03, SessionPatchAck=0x04, Close=0x05, Error=0x06, SessionOpen=0x07, SessionOpenAck=0x08, SessionClose=0x09, SessionCloseAck=0x0A
数据/缓存/流控FrameSubmit=0x10, FrameCancel=0x11, ResultPush=0x12, ResultDrop=0x13, CachePut=0x14, CacheAck=0x15, CacheInvalidate=0x16, FlowUpdate=0x17, ResultHint=0x18, TransportProbe=0x19, TransportProbeAck=0x1A, SessionMigrate=0x1B, SessionMigrateAck=0x1C
保活Ping=0x20, Pong=0x21
运行时控制Cancel=0x30, Abort=0x31, PriorityUpdate=0x32, Deadline=0x33, ExpireAt=0x34, Supersede=0x35, BudgetUpdate=0x36, Progress=0x37, PartialResult=0x38, Backpressure=0x39, CreditUpdate=0x3A, CapabilityNegotiation=0x3B, DegradeProfile=0x3C, RouteHint=0x3D, ExecutionHint=0x3E, TraceContext=0x3F, ResultDropReason=0x40
运行时对象/缓存ObjectDeclare=0x41, ObjectRef=0x42, ObjectRelease=0x43, ObjectPatch=0x44, ObjectDelta=0x45, CacheReference=0x46, CacheMiss=0x47, ErrorRecoverable=0x48, RetryAfter=0x49

公共帧头

HeaderFlags : uint 是位掩码。

成员数值
None0x00000000
AckRequired0x00000001
CanDrop0x00000002
Stale0x00000004
Eos0x00000008
Retransmit0x00000010
Keyframe0x00000020

Wire format 本身使用 NnrpHeader.CurrentWireFormatbyte 数值;SDK 不暴露独立的 WireFormat 枚举。

会话生命周期

枚举成员
SessionPriorityClass : byteInteractive=0, Balanced=1, Background=2
SessionFlags : byteNone=0, AllowResume=0x01, AllowBackgroundResults=0x02, AllowCacheLeases=0x04, AllowSchemaOverride=0x08
SessionStatus : byteOpened=0, Rejected=1, RetryLater=2, Resumed=3
SessionAckFlags : uintNone=0, ResumeEnabled=0x01, BackgroundResultsEnabled=0x02, CacheLeasesEnabled=0x04, SchemaOverrideEnabled=0x08, PriorityDowngraded=0x10
SessionCloseReason : ushortNormal=0, ClientShutdown=1, ServerShutdown=2, IdleTimeout=3, ProtocolError=4, AuthRevoked=5
InFlightPolicy : byteDrain=0, Abort=1
SessionCloseStatus : byteAcknowledged=0, Draining=1, Closed=2, Rejected=3
NnrpSessionState : byteInit=0, Negotiating=1, Active=2, Draining=3, Closed=4

SessionErrorCode : uintCacheErrorCode : uintSchemaErrorCode : uint 保留协议命名空间 数值。完整 code registry 见协议标准

传输选择

枚举成员
TransportId : uintUnspecified=0, Quic=1, Tcp=2, Ipc=3, WebSocket=4
TransportPolicy : byteAuto=0, PreferQuic=1, PreferTcp=2, PreferIpc=3, PreferWebSocket=4, ForceQuic=5, ForceTcp=6, ForceIpc=7, ForceWebSocket=8
LossTolerance : byteStrict=0, BestEffort=1, LowLatency=2, FireAndForget=3

Auto 探测所有已安装 provider,并应用传输 API 定义的确定性比较器。Force 策略 绝不会静默选择其他 provider。

数据与结果

枚举成员
FrameClass : byteKeyframe=0, Delta=1, Retransmit=2, Discardable=3
InputProfile : byteUnspecified=0, ChangedTilesLuma=1, DenseLumaFrame=2
TileIndexMode : byteDenseRange=0, RawUInt16=1, DeltaUInt16=2, Bitset=3
CodecId : byteRaw=0, Lz4=1
DTypeId : byteFloat16=0, Float32=1, Float8E4M3=2, Float8E5M2=3, Int8=4, UInt8=5, Int16=6, UInt16=7
TensorLayoutId : byteNhwc=0, Nchw=1
ScalePolicy : byteNone=0, PerTensor=1, PerTile=2, PerChannel=3
SubmitMode : byteInline=0, Reference=1, Mixed=2
ResultClass : byteComplete=0, Partial=1, StaleReuse=2, Degraded=3

BudgetPolicy : byteResultFlags : ushortPayloadKind : uint 都是位掩码。使用 | 合并 命名值,不要将其数值相加。

缓存

枚举成员
CacheObjectKind : uintCameraBlock=0x0001, TileIndexTemplate=0x0002, TensorSectionTable=0x0003, CodecTable=0x0004, ReusableResultObject=0x0005, PayloadLayoutTemplate=0x0006, PromptSegment=0x0007, ToolSchema=0x0008, StructuredEventSchema=0x0009
CacheAckStatus : uintAccepted=0, Rejected=1, Replaced=2
CacheInvalidateScope : uintWholeSession=0, Namespace=1, ObjectKind=2, ObjectKey=3
CachePutFlags : uintNone=0, Pinned=0x01, Reusable=0x02
CacheLeaseOwnerScope : byteConnection=0, Session=1, Operation=2
CacheValidationFailureNone=0, Miss=1, LeaseExpired=2, VersionMismatch=3, DependencyInvalid=4, SchemaMismatch=5

底层缓存枚举中的 alias member 表示相同线路值;角色 API 使用上表列出的规范成员名。

运行时控制与对象

枚举成员
RuntimeRole : byteUnspecified=0, Client=1, Server=2, Runtime=3, Subagent=4, Tool=5, Scheduler=6, ConformanceRunner=7
RuntimeObjectKind : ushortUnspecified=0, Tensor=1, TokenBlock=2, ImageTile=3, FeatureMap=4, ToolResult=5, TraceSegment=6, OpaqueBytes=7, DocumentChunk=8, AudioChunk=9, VideoChunk=10, RoutePlan=11, CacheManifest=12
MemoryLocationHint : ushortUnspecified=0, HostMemory=1, DeviceMemory=2, SharedMemory=3, RemoteMemory=4, MmapFile=5, ObjectStore=6
OwnershipHint : ushortUnspecified=0, ProducerOwned=1, ConsumerOwned=2, SessionOwned=3, Borrowed=4, TransferOnRef=5, ReleaseOnDrop=6
ObjectReleaseReason : ushortCompleted=0, Cancelled=1, Expired=2, Replaced=3, Invalidated=4, OwnerClosed=5, LeaseExpired=6, ConformanceInjection=7
CacheReuseScope : ushortOperation=0, Session=1, Connection=2, Global=3, Tenant=4, Profile=5
CacheMissReason : ushortUnknown=0, NotFound=1, Expired=2, Invalidated=3, SchemaMismatch=4, ProducerUnavailable=5, LeaseRequired=6, PermissionDenied=7

运行时 reason、stage、priority、pressure、executor、affinity 和 result-drop code 字段使用 运行时 API 定义的 Preview4 typed code wrapper。保留区和私有区保持原值;未知值仍可观测, 不会被折叠为泛化错误。

NNRP Documentation