コード例 #1
0
ファイル: PBSerializer.cs プロジェクト: killgxlin/FPSServer
        public static IExtensible CheckSerialize(IExtensible obj)
        {
            var bytes = Serialize(obj);
            var msg   = deserialize(obj.GetType(), bytes);

            return(msg);
        }
コード例 #2
0
ファイル: TypedPublisher.cs プロジェクト: xuchdong/umundo
        /// <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));
        }
コード例 #3
0
ファイル: TypedPublisher.cs プロジェクト: xuchdong/umundo
        /// <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);
        }
コード例 #4
0
        /// <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);
                        }
                    }
                }
            }
        }
コード例 #5
0
 /// <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 }));
 }
コード例 #6
0
 /// <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 });
 }
コード例 #7
0
        //发送消息
        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);
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        /// <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);
                        }
                    }
                }
            }
        }
コード例 #10
0
ファイル: PBUtil.cs プロジェクト: killgxlin/FPSServer
 public static int MsgId(this IExtensible msg)
 {
     return(msg.GetType().FullName.GetHashCode());
 }
コード例 #11
0
 public static MessageTypes MessageType(IExtensible mumbleProto)
 {
     return Types.First(kvp => kvp.Value == mumbleProto.GetType()).Key;
 }
コード例 #12
0
 public static MessageTypes MessageType(IExtensible mumbleProto)
 {
     return(Types.First(kvp => kvp.Value == mumbleProto.GetType()).Key);
 }
コード例 #13
0
 public IExtensible MakeOut()
 {
     return((IExtensible)Activator.CreateInstance(POutTemplate.GetType()));
 }
コード例 #14
0
 public void RecvMsg(long playerId, IExtensible msg)
 {
     this.Info("RecvMsg playerId:{0}, msg:{1}", playerId, msg.GetType());
     scene.MasterDealMsg(msg);
 }
コード例 #15
0
ファイル: TypedPublisher.cs プロジェクト: 0790486/umundo
 /// <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);
 }