一款简单易用的基础网络通讯组件库。

DmtpMessage 类

Dmtp协议的消息。

|*2*|*2*|**4**|***************n***********|

|dm|ProtocolFlags|Length|Data|

|head|ushort|int32|bytes|

Definition

命名空间: TouchSocket.Dmtp
程序集: TouchSocket.Dmtp (在 TouchSocket.Dmtp.dll 中) 版本:3.0.0+ccaf96084d09f972257496d1dd63b8ba3c1e44f0
C#
public class DmtpMessage : DisposableObject, 
	IFixedHeaderByteBlockRequestInfo, IRequestInfo, IRequestInfoBuilder, IByteBlockBuilder
Inheritance
Object    DisposableObject    DmtpMessage
Implements
IByteBlockBuilder, IFixedHeaderByteBlockRequestInfo, IRequestInfo, IRequestInfoBuilder

构造函数

DmtpMessage Dmtp协议的消息。

|*2*|*2*|**4**|***************n***********|

|Head|ProtocolFlags|Length|Data|

|dm|ushort|int32|bytes|

DmtpMessage(UInt16) Dmtp协议的消息。

|*2*|**4**|***************n***********|

|ProtocolFlags|Length|Data|

|ushort|int32|bytes|

属性

BodyByteBlock 实际使用的Body数据。
DisposedValue 标识该对象是否已被释放
(继承自 DisposableObject。)
MaxLength 构建数据时,指示内存池的申请长度。

建议:该值可以尽可能的设置大一些,这样可以避免内存池扩容。

ProtocolFlags 协议标识

方法

BuildTByteBlock 构建数据到ByteBlock
CreateFrom 从当前内存中解析出一个DmtpMessage

注意:

  1. 本解析只能解析一个完整消息。所以使用该方法时,请确认是否已经接收完成一个完整的DmtpMessage包。
  2. 本解析所得的DmtpMessage消息会脱离生命周期管理,所以需要手动释放。

Dispose 释放资源。内部已经处理了SuppressFinalize(Object)
(继承自 DisposableObject。)
Dispose(Boolean) 处置资源
(重写 DisposableObjectDispose(Boolean))
EqualsDetermines whether the specified object is equal to the current object.
(继承自 Object。)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(继承自 Object。)
GetBodyStringBodyByteBlock的有效数据转换为utf-8的字符串。
GetHashCodeServes as the default hash function.
(继承自 Object。)
GetTypeGets the Type of the current instance.
(继承自 Object。)
MemberwiseCloneCreates a shallow copy of the current Object.
(继承自 Object。)
ThrowIfDisposed 判断当前对象是否已经被释放。 如果已经被释放,则抛出ObjectDisposedException异常。
(继承自 DisposableObject。)
ToStringReturns a string that represents the current object.
(继承自 Object。)

字段

Head Head

扩展方法

Build 扩展方法,用于构建给定的字节块。 该方法通过引用传递字节块,以利用ref参数提高性能,避免不必要的复制。
(由 ByteBlockBuilderExtension 定义。)
BuildAsBytes 将对象构建到字节数组
(由 DataHandlingAdapterExtension 定义。)
Map
(由 Mapper 定义。)
Map
(由 Mapper 定义。)
MapTTarget
(由 Mapper 定义。)
ToJsonString 转换为Json
(由 SerializeConvert 定义。)

显式接口实现

IFixedHeaderByteBlockRequestInfoBodyLength 数据体长度
IFixedHeaderByteBlockRequestInfoOnParsingBody 当收到数据,由框架封送有效载荷数据。

如果返回false,意味着放弃本次解析的所有数据,包括已经解析完成的Header

IFixedHeaderByteBlockRequestInfoOnParsingHeader 当收到数据,由框架封送固定协议头。

您需要在此函数中,解析自己的固定包头,并且对BodyLength赋值后续数据的长度,然后返回True。

如果返回false,则意味着放弃本次解析

参见