Class CellFraming
分帧线材(§3.1——Cell 拥有:纯 span 线格式,零 IO,容器/宿主两侧共用单一事实源)。
★ 帧形态 = [长度 4B 大端][帧体];帧体 = [Tag 1B][字段声明序](WireMessage 族编码)。
★ 帧长上限校验在这里一次做完:超限=FrameTooLarge 非静默丢(§3.4)。
public static class CellFraming
- Inheritance
-
CellFraming
- Inherited Members
Methods
TryReadFrame(ReadOnlySequence<byte>, int, out ReadOnlySequence<byte>, out long)
从缓冲读取一帧体(无跨帧——单帧一次取足的调用形态)。
false=数据不足或超限(consumed 返回可安全消费的前缀字节数)。
public static bool TryReadFrame(ReadOnlySequence<byte> buffer, int maxLength, out ReadOnlySequence<byte> frameBody, out long consumed)
Parameters
bufferReadOnlySequence<byte>maxLengthintframeBodyReadOnlySequence<byte>consumedlong
Returns
TryReadPrefix(ReadOnlySpan<byte>, int, out int)
读帧长前缀(大端 4B)。false=帧长缺失或超上限(调用方按协议错误报告,绝不静默跳过)。
public static bool TryReadPrefix(ReadOnlySpan<byte> prefix, int maxLength, out int bodyLength)
Parameters
prefixReadOnlySpan<byte>maxLengthintbodyLengthint
Returns
WireLength(int)
帧线长(前缀+帧体——发送侧缓冲预算口)。
public static int WireLength(int bodyLength)
Parameters
bodyLengthint
Returns
WritePrefix(Span<byte>, int, int)
写帧长前缀(大端 4B——bodyLength 超 maxLength 即抛,发送侧防御)。
public static void WritePrefix(Span<byte> destination, int bodyLength, int maxLength)