public void UnMarshal(MMStream stream) { srvType = stream.ReadByte(); entityID = stream.ReadUInt64(); methodName = stream.ReadString(); args = stream.ReadBytes(); }
internal static MMStream Get(int size = 65536) { if (size <= MaxSize) { for (int i = 0; i < sizes.Length; i++) { if (size <= sizes[i]) { var obj = pools[i].Get(); if (obj != null) { if (obj.Buf == null) { obj.Reset(new byte[sizes[i]]); } } else { obj = new MMStream(new byte[sizes[i]]); } return(obj); } } } return(new MMStream(new byte[size])); }
public void UnMarshal(MMStream stream) { Source = stream.ReadByte(); UID = stream.ReadUInt64(); SourceID = stream.ReadUInt64(); Type = stream.ReadByte(); }
public void Marshal(MMStream stream) { stream.WriteByte(Source); stream.WriteUInt64(UID); stream.WriteUInt64(SourceID); stream.WriteByte(Type); }
public void Marshal(MMStream stream) { stream.WriteByte(srvType); stream.WriteUInt64(entityID); stream.WriteString(methodName); stream.WriteBytes(args); }
/// <summary> /// 解包Proto /// </summary> /// <param name="stream">流</param> /// <param name="protoBinaryReserved">是否以二进制形式解决</param> /// <param name="msg">消息包</param> /// <returns>是否根据规定方案解包</returns> private static bool UnpackProto(MMStream stream, bool protoBinaryReserved, out object msg) { var fullname = (string)stream.ReadString(); var msgBuf = stream.ReadBytes(); //var msgId = (int)stream.ReadUInt16(); //var msgInfo = MsgService.Instance.GetMsgById(msgId); //if (protoBinaryReserved) //{ // //if (msgInfo == null) // //{ // // msg = msgBuf; // // return false; // //} // msg = new RawProto { name = msgInfo.Name, rawData = msgBuf }; // return true; //} var ProtocolType = Type.GetType(fullname); var pstream = new System.IO.MemoryStream(msgBuf, 0, msgBuf.Length); pstream.SetLength(msgBuf.Length); msg = ProtoBuf.Meta.RuntimeTypeModel.Default.Deserialize(pstream, null, ProtocolType); //msg = PacketPolicy.Unpacked(msgInfo, new ArraySegment<byte>(msgBuf, 0, msgBuf.Length)); return(true); }
public void UnMarshal(MMStream stream) { spaceID = stream.ReadUInt64(); mapName = stream.ReadString(); entityID = stream.ReadUInt64(); outAddr = stream.ReadString(); timeStamp = stream.ReadUInt32(); }
public void Marshal(MMStream stream) { stream.WriteUInt64(spaceID); stream.WriteString(mapName); stream.WriteUInt64(entityID); stream.WriteString(outAddr); stream.WriteUInt32(timeStamp); }
public void UnMarshal(MMStream stream) { entityId = stream.ReadUInt64(); adjustCount = stream.ReadUInt32(); stream.ReadFixByteArray(ref stateData); //data = stream.ReadBytes(); }
internal static MMStream GetTmp() { var obj = pool.Get(); if (obj == null) { obj = new MMStream(); } return(obj); }
public void UnMarshal(MMStream stream) { id = stream.ReadUInt64(); int len = stream.ReadUInt16(); var marbytearr = statdata.getArray(); stream.ReadBytes(ref marbytearr, len); //data = stream.ReadBytes(); }
public void UnMarshal(MMStream stream) { entityID = stream.ReadUInt64(); num = stream.ReadUInt32(); //data = stream.ReadBytes(); if (num > 1024) { throw new ArgumentNullException("PropSyncClient UnMarshal"); } stream.ReadFixByteArray(ref data); }
public void UnMarshal(MMStream stream) { num = stream.ReadInt32(); if (num < aoi_data.totalLength) { aoi_data.SetUsedLength(num); for (int i = 0; i < num; i++) { var aoiarr = aoi_data.getArray()[i]; stream.ReadFixByteArray(ref aoiarr); } } }
internal static void Put(MMStream obj) { var size = obj.Buf.Length; if (size < MaxSize) { for (int i = 0; i < sizes.Length; i++) { if (size == sizes[i]) { pools[i].Put(obj); } } } }
public void UnMarshal(MMStream stream) { entityID = stream.ReadUInt64(); entityType = stream.ReadString(); state = stream.ReadBytes(); propNum = stream.ReadUInt16(); properties = stream.ReadBytes(); var len = stream.ReadUInt16(); if (len == 0) { baseProps = null; } else { baseProps = new EntityBaseProps(); baseProps.UnMarshal(stream); } }
public void UnMarshal(MMStream stream) { id = stream.ReadUInt64(); linkTarget = stream.ReadUInt64(); var linkLength = stream.ReadByte(); if (linkLength <= linkers.totalLength) { linkers.Clear(); } else { linkers = new FixedLengthArray <ulong>(linkLength); } for (int i = 0; i < linkLength; i++) { linkers.Add(stream.ReadUInt64()); } commTarget = stream.ReadUInt64(); var commLength = stream.ReadByte(); if (commLength <= commers.totalLength) { commers.Clear(); } else { commers = new FixedLengthArray <ulong>(commLength); } for (int i = 0; i < commLength; i++) { commers.Add(stream.ReadUInt64()); } }
public void UnMarshal(MMStream stream) { num = stream.ReadUInt32(); eids.Clear(); eds.SetUsedLength((int)num); for (int i = 0; i < num; i++) { eids.Add(stream.ReadUInt64()); //int blen = stream.ReadUInt16(); var edsbytearr = eds.getArray()[i]; if (edsbytearr == null) { eds.getArray()[i] = new FixedLengthArray <byte>(2048); edsbytearr = eds.getArray()[i]; } stream.ReadFixByteArray(ref edsbytearr); } }
public void Marshal(MMStream stream) { stream.WriteByte(Source); stream.WriteUInt64(UID); stream.WriteBytes(Token); }
public void UnMarshal(MMStream stream) { timeStamp = stream.ReadUInt32(); }
private static void doPack(MMStream stream, object arg) { if (arg == null) { return; } //Debug.Log("doPack arg.GetType():" + arg.GetType() + " arg.GetType().IsValueType:" + arg.GetType().IsValueType + " arg.GetType().IsArray:" + arg.GetType().IsArray); if (arg is byte) { stream.WriteByte((byte)arg); } else if (arg is sbyte) { stream.WriteByte((byte)arg); } else if (arg is ushort) { stream.WriteUInt16((ushort)arg); } else if (arg is uint) { stream.WriteUInt32((uint)arg); } else if (arg is ulong) { stream.WriteUInt64((ulong)arg); } else if (arg is short) { stream.WriteInt16((short)arg); } else if (arg is int) { stream.WriteInt32((int)arg); } else if (arg is long) { stream.WriteInt64((long)arg); } else if (arg is float) { stream.WriteFloat((float)arg); } else if (arg is double) { stream.WriteDouble((double)arg); } else if (arg is string) { stream.WriteString((string)arg); } else if (arg.GetType() == typeof(byte[])) { stream.WriteBytes((byte[])arg); } else if (arg.GetType() == typeof(sbyte[])) { var buff = new byte[((sbyte[])arg).Length]; Array.Copy((sbyte[])arg, buff, buff.Length); stream.WriteBytes(buff); } else if (arg is bool) { stream.WriteBool((bool)arg); } else if (arg is global::ProtoBuf.IExtensible) { //stream.WriteString(arg.GetType().FullName); // +2 是由于WriteBuf存在Length的长度 var segment = new ArraySegment <byte>(stream.Buf, stream.WPos + 2, stream.Capicity - stream.WPos - 2); var pstream = new System.IO.MemoryStream(segment.Array, segment.Offset, segment.Count); ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(pstream, arg); stream.WriteUInt16((ushort)pstream.Position); stream.WPos += (int)pstream.Position; //var buf = new byte[stream.WPos]; //Buffer.BlockCopy(stream.Buf, 0, buf, 0, stream.WPos); //stream.WriteBytes(buf); } else if (arg is IDictionary) { var dict = (arg as IDictionary); stream.WriteUInt16((ushort)dict.Count); var enumer = dict.GetEnumerator(); while (enumer.MoveNext()) { var item = enumer.Current; var itemKey = item.GetType().GetProperty("Key").GetValue(item, null); var itemValue = item.GetType().GetProperty("Value").GetValue(item, null); doPack(stream, itemKey); doPack(stream, itemValue); } //var buf = new byte[stream.WPos]; //Buffer.BlockCopy(stream.Buf, 0, buf, 0, stream.WPos); //stream.WriteBytes(buf); } else if (arg is IList) { var list = (arg as IList); stream.WriteUInt16((ushort)list.Count); for (var i = 0; i < list.Count; i++) { var listitem = list[i]; doPack(stream, listitem); } //var buf = new byte[stream.WPos]; //Buffer.BlockCopy(newstream.Buf, 0, buf, 0, newstream.WPos); //stream.WriteBytes(buf); } else if (arg.GetType().IsArray) { var fields = arg.GetType().GetFields(); stream.WriteUInt16((ushort)fields.Length); for (var i = 0; i < fields.Length; i++) { var field = fields[i]; //var index = arg.GetType().IsArray ? new object[] { i } : null; doPack(stream, field.GetValue(arg)); } } else if (arg.GetType().IsEnum) { var fields = arg.GetType().GetFields(); var field = fields[0]; //var index = arg.GetType().IsArray ? new object[] { i } : null; doPack(stream, field.GetValue(arg)); } else if (arg.GetType().IsValueType || arg.GetType().IsClass) { //if (arg.GetType().IsArray) //{ // //array //} //else //{ // //struct // var props = arg.GetType().GetProperties(); // for (var i = 0; i < props.Length; i++) // { // var prop = props[i]; // stream.WriteBytes(doPack(prop.GetValue(arg, null))); // } //} var fields = arg.GetType().GetFields(); for (var i = 0; i < fields.Length; i++) { var field = fields[i]; //var index = arg.GetType().IsArray ? new object[] { i } : null; doPack(stream, field.GetValue(arg)); } //var buf = new byte[newstream.WPos]; //Buffer.BlockCopy(newstream.Buf, 0, buf, 0, newstream.WPos); //stream.WriteBytes(buf); } else { throw new NotSupportedException("Unknow rpc method param type: [" + arg.GetType().Name + "]"); } }
public void Marshal(MMStream stream) { stream.WriteUInt64(id); stream.WriteBuf(statdata.getArray(), statdata.usedLength); }
private static object doUnpack(MMStream stream, Type type) { //if (stream.IsEOF()) // return null; //Debug.Log("doUnpack type:" + type + " type.IsValueType:" + type.IsValueType + " type.IsArray:" + type.IsArray); if (!stream.IsEOF()) { if (type == typeof(byte)) { return(stream.ReadByte()); } else if (type == typeof(sbyte)) { return((sbyte)stream.ReadByte()); } else if (type == typeof(ushort)) { return(stream.ReadUInt16()); } else if (type == typeof(uint)) { return(stream.ReadUInt32()); } else if (type == typeof(ulong)) { return(stream.ReadUInt64()); } else if (type == typeof(short)) { return(stream.ReadInt16()); } else if (type == typeof(int)) { return(stream.ReadInt32()); } else if (type == typeof(long)) { return(stream.ReadInt64()); } else if (type == typeof(float)) { return(stream.ReadFloat()); } else if (type == typeof(double)) { return(stream.ReadDouble()); } else if (type == typeof(string)) { return(stream.ReadString()); } else if (type == typeof(byte[])) { return(stream.ReadBytes()); } else if (type == typeof(sbyte[])) { var buff = stream.ReadBytes(); var sbuff = new sbyte[buff.Length]; Array.Copy(buff, sbuff, buff.Length); return(sbuff); } else if (type == typeof(bool)) { return(stream.ReadBoolean()); } else if (type.IsArray) { var count = stream.ReadUInt16(); object newobj = Array.CreateInstance(type.GetElementType(), count); for (var i = 0; i < count; i++) { var val = doUnpack(stream, type.GetElementType()); newobj.GetType().GetMethod("SetValue", new Type[2] { typeof(object), typeof(int) }).Invoke(newobj, new object[] { val, i }); } return(newobj); } else if (typeof(IDictionary).IsAssignableFrom(type)) { var count = stream.ReadUInt16(); var eletypes = type.GetGenericArguments(); var newdict = Activator.CreateInstance(type) as IDictionary; for (var i = 0; i < count; i++) { var key = doUnpack(stream, eletypes[0]); var val = doUnpack(stream, eletypes[1]); newdict[key] = val; } return(newdict); } else if (typeof(IList).IsAssignableFrom(type)) { var count = stream.ReadUInt16(); var newlist = Activator.CreateInstance(type) as IList; var eletype = type.GetGenericArguments()[0];//.GetElementType(); for (var i = 0; i < count; i++) { newlist.Add(doUnpack(stream, eletype)); } return(newlist); } } if (typeof(ProtoBuf.IExtensible).IsAssignableFrom(type)) { System.IO.MemoryStream pstream = null; if (stream.IsEOF()) { pstream = new System.IO.MemoryStream(); } else { var msgBuf = stream.ReadBytes(); pstream = new System.IO.MemoryStream(msgBuf, 0, msgBuf.Length); pstream.SetLength(msgBuf.Length); } return(ProtoBuf.Meta.RuntimeTypeModel.Default.Deserialize(pstream, null, type)); } else if (type.IsEnum) { object newobj = Activator.CreateInstance(type); if (!stream.IsEOF()) { var fields = newobj.GetType().GetFields(); var field = fields[0]; var val = doUnpack(stream, field.FieldType); //var index = type.IsArray ? new object[] { i } : null; field.SetValue(newobj, val); } return(newobj); } else if (type.IsValueType || type.IsClass) { object newobj = Activator.CreateInstance(type); if (!stream.IsEOF()) { var fields = newobj.GetType().GetFields(); for (var i = 0; i < fields.Length; i++) { var field = fields[i]; var val = doUnpack(stream, field.FieldType); //var index = type.IsArray ? new object[] { i } : null; field.SetValue(newobj, val); } } return(newobj); } else { throw new NotSupportedException("Unknow rpc method param type: [" + type.Name + "]"); } }
public void UnMarshal(MMStream stream) { num = stream.ReadInt32(); data = stream.ReadBytes(); }
public void UnMarshal(MMStream stream) { }
public void UnMarshal(MMStream stream) { Source = stream.ReadByte(); UID = stream.ReadUInt64(); Token = stream.ReadBytes(Token.Length); }
public void Marshal(MMStream stream) { stream.WriteUInt64(UID); stream.WriteUInt64(SpaceID); }
internal static void PutTmp(MMStream obj) { obj.Reset(null); pool.Put(obj); }
public void Marshal(MMStream stream) { stream.WriteBytes(data); }
public void Marshal(MMStream stream) { stream.WriteUInt64(entityID); stream.WriteUInt32(adjustCount); }
public void UnMarshal(MMStream stream) { entityID = stream.ReadUInt64(); propNum = stream.ReadUInt32(); properties = stream.ReadBytes(); }