WriterExtensionWriteStringTWriter(TWriter, String, FixedHeaderType) 方法
将字符串以指定的固定包头类型写入到字节写入器中。
命名空间: TouchSocket.Core程序集: TouchSocket.Core (在 TouchSocket.Core.dll 中) 版本:4.0.0-beta.143+5fcca7a4e70968794985dc3793adc50531308be6
public static void WriteString<TWriter>(
this TWriter writer,
string value,
FixedHeaderType headerType = FixedHeaderType.Int
)
where TWriter : class, IBytesWriter
<ExtensionAttribute>
Public Shared Sub WriteString(Of TWriter As {Class, IBytesWriter}) (
writer As TWriter,
value As String,
Optional headerType As FixedHeaderType = FixedHeaderType.Int
)
[<ExtensionAttribute>]
static member WriteString :
writer : 'TWriter *
value : string *
?headerType : FixedHeaderType
(* Defaults:
let _headerType = defaultArg headerType FixedHeaderType.Int
*)
-> unit when 'TWriter : not struct and IBytesWriter
- writer TWriter
- 字节写入器实例。
- value String
- 要写入的字符串。
- headerType FixedHeaderType (Optional)
- 固定包头类型,默认为Int。
- TWriter
- 字节写入器类型,必须继承自IBytesWriter。
在 Visual Basic 和 C# 中,这个方法可以当成为类型
TWriter 的实例方法来调用。在采用实例方法语法调用这个方法时,请省略第一个参数。请参考
扩展方法 (Visual Basic) 或
扩展方法 (C# 编程指南) 获取更多信息。
根据
headerType写入不同大小的长度前缀,然后写入UTF-8编码的字符串数据。
- 对于字符串,写入相应类型的最大值作为标记。
- 对于空字符串,写入长度0。
- 对于普通字符串,写入实际字节长度后跟随数据。