public bool Marshal(IBufWriter writer) { //Console.WriteLine("--------------------Marshal------------------------"); var orgin = writer.Position; { writer.WriteInt32(0); writer.WriteUInt32(this.FrameIndex); writer.WriteInt(this.Actions.Count); lock (this.Actions) { while (this.Actions.Count > 0) { var a = this.Actions.Dequeue(); //Console.WriteLine("> " + a.OwnerId + ", " + a.Type + ", " + a.Target + ", " + a.ActorId + ", " + (a.ClsName ?? string.Empty) + ", " + (a.SubTarget ?? string.Empty)); writer.WriteUInt64(a.OwnerId); writer.WriteByte((byte)a.Type); writer.WriteByte((byte)a.Target); writer.WriteUInt64(a.ActorId); writer.WriteString(a.ClsName ?? string.Empty); writer.WriteString(a.SubTarget ?? string.Empty); writer.WriteByte((byte)a.Payload.Length); for (var i = 0; i < a.Payload.Length; ++i) { WriteObject(writer, a.Payload[i]); } } } writer.WriteInt64(this.LocalTimestamp); } var length = writer.Position - orgin; writer.Seek(orgin); writer.WriteInt32(length); return(true); }
public static void WriteObject(IBufWriter writer, object value) { var t = value.GetType(); if (t.IsValueType) { if (t == typeof(bool)) { writer.WriteByte((bool)value ? TRUE : FALSE); } else if (t.IsPrimitive) { if (t == typeof(byte)) { writer.WriteByte(INT8); writer.WriteByte((byte)value); } else if (t == typeof(short)) { writer.WriteByte(INT16); writer.WriteInt16((short)value); } else if (t == typeof(int)) { writer.WriteByte(INT32); writer.WriteInt32((int)value); } else if (t == typeof(long)) { writer.WriteByte(INT64); writer.WriteInt64((long)value); } else if (t == typeof(ushort)) { writer.WriteByte(UINT16); writer.WriteUInt16((ushort)value); } else if (t == typeof(uint)) { writer.WriteByte(UINT32); writer.WriteUInt32((uint)value); } else if (t == typeof(ulong)) { writer.WriteByte(UINT64); writer.WriteUInt64((ulong)value); } else if (t == typeof(float)) { writer.WriteByte(FLOAT32); writer.WriteFloat((float)value); } else if (t == typeof(double)) { writer.WriteByte(FLOAT64); writer.WriteDouble((double)value); } } else if (t.IsEnum) { } else { } } else if (t == typeof(string)) { writer.WriteByte(STR32); writer.WriteString((string)value); } else if (t.IsArray) { writer.WriteByte(ARR32); var arr = value as Array; WriteObject(writer, arr.Length); for (var i = 0; i < arr.Length; ++i) { WriteObject(writer, arr.GetValue(i)); } } else if (value is IDictionary) { writer.WriteByte(MAP32); var map = value as IDictionary; WriteObject(writer, map.Count); var it = map.GetEnumerator(); while (it.MoveNext()) { WriteObject(writer, it.Key); WriteObject(writer, it.Value); } } else { } }