private static void appendField(object field, ref ByteBuffer buff) { if (field is CLRSharp_Instance) { buff.appendBuffer(clrObjectToByteBuffer(field as CLRSharp_Instance)); } else { Type type = field.GetType(); if (type.BaseType != null && type.BaseType.FullName == "System.Array") { appendArray(field as Array, ref buff); } else { append(field, ref buff); } } }
/// <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; }