本文整理汇总了C#中System.ByteBuffer.appendUshort方法的典型用法代码示例。如果您正苦于以下问题:C# ByteBuffer.appendUshort方法的具体用法?C# ByteBuffer.appendUshort怎么用?C# ByteBuffer.appendUshort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.appendUshort方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: append
private static void append(object field, ref ByteBuffer buff)
{
Type type = field.GetType();
switch (type.FullName)
{
case "System.Int16":
buff.appendShort((short)field);
break;
case "System.Int32":
buff.appendInt((int)field);
break;
case "System.Int64":
buff.appendLong((long)field);
break;
case "System.UInt16":
buff.appendUshort((ushort)field);
break;
case "System.UInt32":
buff.appendUint((uint)field);
break;
//case "System.UInt64":
// buff.appendUlong((ulong)field);
// break;
case "System.Byte":
buff.appendByte((byte)field);
break;
case "System.Boolean":
buff.appendBool((bool)field);
break;
case "System.Single":
buff.appendFloat((float)field);
break;
case "System.Double":
buff.appendDouble((double)field);
break;
case "System.String":
buff.appendString((string)field);
break;
default:
throw new Exception("协议包含不可解析类型:" + type.FullName);
}
}
示例2: appendArray
private static void appendArray(Array array, ref ByteBuffer buff)
{
buff.appendUshort((ushort)(array.Length));
for (int i = 0, len = array.Length; i < len; i++)
{
appendField(array.GetValue(i), ref buff);
}
}
示例3: packet
/// <summary>
/// 封包,时间戳 + 协议号 + 内容长度 + 内容
/// </summary>
/// <param name="protocol"></param>
/// <param name="data"></param>
/// <returns></returns>
private ByteBuffer packet(int protocol, object data)
{
ByteBuffer buff = PackageUtil.clrObjectToByteBuffer(data as CLRSharp_Instance);
Package package = new Package();
package.timeStamp = TimeUtil.getTimeStamp();
package.protocol = protocol;
package.len = (ushort)buff.length;
package.data = data;
Debug.Log("[发送] " + package.toString());
ByteBuffer buffer = new ByteBuffer();
buffer.appendInt(package.timeStamp);
buffer.appendInt(package.protocol);
buffer.appendUshort(package.len);
buffer.appendBuffer(buff);
return buffer;
}