本文整理匯總了C#中System.ByteBuffer.appendInt方法的典型用法代碼示例。如果您正苦於以下問題:C# ByteBuffer.appendInt方法的具體用法?C# ByteBuffer.appendInt怎麽用?C# ByteBuffer.appendInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.appendInt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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;
}