public static IExtensible CheckSerialize(IExtensible obj) { var bytes = Serialize(obj); var msg = deserialize(obj.GetType(), bytes); return(msg); }
/// <summary> /// Retrieves a message from the given extensible that can be sent over umundo. /// The name is automatically determined. /// </summary> /// <param name="extensible">the object to send</param> /// <returns></returns> public Message PrepareMessage(IExtensible extensible) { byte[] buffer = Serialize(extensible); string type = extensible.GetType().Name; return(PrepareMessage(type, buffer)); }
/// <summary> /// Sends the protobuf serializable object autmatically determine the name. /// </summary> /// <param name="type">type of the object to send</param> public void SendObject(IExtensible o) { byte[] buffer = Serialize(o); string type = o.GetType().Name; Message message = PrepareMessage(type, buffer); send(message); }
/// <summary> /// Serializes extension information on an extensible object. /// </summary> /// <param name="extensible">The extensible object that may contain extensions.</param> /// <param name="serializeAttributes">If true, attributes extensions will be serialized, otherwise they'll be skipped.</param> /// <param name="serializeChildren">If true, element extensions will be serialized, otherwise they'll be skipped.</param> private void SerializeExtensions(IExtensible extensible, bool serializeAttributes, bool serializeChildren) { if (this.settings.IncludeExtensions && (extensible != null)) { foreach (IExtension extension in extensible.Extensions) { if (serializeAttributes && extension.HasAttributes) { if (extensible.SupportsAttributeExtensions) { this.SerializeExtensionAttributes(extension); } else { string message; message = string.Format( Properties.Resources.XliffWriter_ExtensionTypeNotSupported_Format, extensible.GetType().Name, "Attribute"); throw new NotSupportedException(message); } } if (serializeChildren && extension.HasChildren) { if (extensible.SupportsElementExtensions) { this.SerializeExtensionChildren(extension); } else { string message; message = string.Format( Properties.Resources.XliffWriter_ExtensionTypeNotSupported_Format, extensible.GetType().Name, "Element"); throw new NotSupportedException(message); } } } } }
/// <summary> /// All this does is call GetExtendedValuesTyped with the correct type for "instance"; /// this ensures that we don't get issues with subclasses declaring conflicting types - /// the caller must respect the fields defined for the type they pass in. /// </summary> internal static IEnumerable <TValue> GetExtendedValues <TValue>(IExtensible instance, int tag, DataFormat format, bool singleton, bool allowDefinedTag) { if (instance == null) { throw new ArgumentNullException("instance"); } return((IEnumerable <TValue>) typeof(ExtensibleUtil) .GetMethod("GetExtendedValuesTyped", BindingFlags.Public | BindingFlags.Static) .MakeGenericMethod(instance.GetType(), typeof(TValue)) .Invoke(null, new object[] { instance, tag, format, singleton, allowDefinedTag })); }
/// <summary> /// All this does is call AppendExtendValueTyped with the correct type for "instance"; /// this ensures that we don't get issues with subclasses declaring conflicting types - /// the caller must respect the fields defined for the type they pass in. /// </summary> internal static void AppendExtendValue <TValue>(IExtensible instance, int tag, DataFormat format, object value) { if (instance == null) { throw new ArgumentNullException("instance"); } typeof(ExtensibleUtil) .GetMethod("AppendExtendValueTyped", BindingFlags.Public | BindingFlags.Static) .MakeGenericMethod(instance.GetType(), typeof(TValue)) .Invoke(null, new object[] { instance, tag, format, value }); }
//发送消息 public void SendMsg(IExtensible msg) { //序列化Protobuf byte[] bytemsg = ProtobufUntil.Serialize(msg); byte[] data = MakeData(bytemsg, msg.GetType()); lock (m_SendMessageQueue) { //消息进入队列 m_SendMessageQueue.Enqueue(data); //开始发送消息 m_ClientSendMessageCallBack.BeginInvoke(null, null); } }
private void SendMessage(int messageType, int messageId, IExtensible message) { var messageName = message.GetType().FullName; var nameSize = messageName.Length; byte[] messageByteArray; using (var stream = new MemoryStream()) { Serializer.NonGeneric.Serialize(stream, message); messageByteArray = stream.ToArray(); } var messageSize = messageByteArray.Length; var output = new ArraySegmentOutput(); var messageNameBytes = Encoding.UTF8.GetBytes(messageName); output.WriteInt(messageId); output.WriteByte(messageType); output.WriteByte(nameSize); output.WriteInt(messageSize); output.WriteBytes(messageNameBytes, 0, messageNameBytes.Length); output.WriteBytes(messageByteArray, 0, messageByteArray.Length); bcpSession.Send(output.Buffers); }
public static int MsgId(this IExtensible msg) { return(msg.GetType().FullName.GetHashCode()); }
public static MessageTypes MessageType(IExtensible mumbleProto) { return Types.First(kvp => kvp.Value == mumbleProto.GetType()).Key; }
public static MessageTypes MessageType(IExtensible mumbleProto) { return(Types.First(kvp => kvp.Value == mumbleProto.GetType()).Key); }
public IExtensible MakeOut() { return((IExtensible)Activator.CreateInstance(POutTemplate.GetType())); }
public void RecvMsg(long playerId, IExtensible msg) { this.Info("RecvMsg playerId:{0}, msg:{1}", playerId, msg.GetType()); scene.MasterDealMsg(msg); }