本文整理汇总了C#中PayloadData.ToBytes方法的典型用法代码示例。如果您正苦于以下问题:C# PayloadData.ToBytes方法的具体用法?C# PayloadData.ToBytes怎么用?C# PayloadData.ToBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayloadData
的用法示例。
在下文中一共展示了PayloadData.ToBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloseEventArgs
public CloseEventArgs(PayloadData data)
: base(Opcode.CLOSE, data)
{
_code = (ushort)CloseStatusCode.NO_STATUS_CODE;
_reason = String.Empty;
_wasClean = false;
if (data.Length >= 2)
_code = Ext.To<ushort>(Ext.SubArray(data.ToBytes(), 0, 2), ByteOrder.BIG);
if (data.Length > 2)
{
var buffer = Ext.SubArray(data.ToBytes(), 2, (int)(data.Length - 2));
_reason = Encoding.UTF8.GetString(buffer);
}
}
示例2: getReasonFrom
private string getReasonFrom(PayloadData data)
{
if (data.Length <= 2)
return String.Empty;
var buffer = data.ToBytes().SubArray(2, (int)(data.Length - 2));
return Encoding.UTF8.GetString(buffer);
}
示例3: canSendAsCloseFrame
private bool canSendAsCloseFrame(PayloadData data)
{
if (data.Length >= 2)
{
var code = Ext.To<ushort>(Ext.SubArray(data.ToBytes(), 0, 2), ByteOrder.BIG);
if (code == (ushort)CloseStatusCode.NO_STATUS_CODE ||
code == (ushort)CloseStatusCode.ABNORMAL ||
code == (ushort)CloseStatusCode.HANDSHAKE_FAILURE)
return false;
}
return true;
}
示例4: getCodeFrom
private ushort getCodeFrom(PayloadData data)
{
return data.Length >= 2
? data.ToBytes().SubArray(0, 2).To<ushort>(ByteOrder.BIG)
: (ushort)CloseStatusCode.NO_STATUS_CODE;
}