コード例 #1
0
        public override IData GetMessageData(IList <Message> messages)
        {
            Beetle.Express.IData data = null;
            byte[] buffer;
            long   index = 0;

            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                foreach (Message message in messages)
                {
                    stream.Write(new byte[4], 0, 4);
                    short typevalue = TypeMapper.GetValue(message.Type);
                    if (typevalue == 0)
                    {
                        "{0} type value not registed".ThrowError <Exception>(message.Type);
                    }
                    byte[] typedata = BitConverter.GetBytes(typevalue);
                    stream.Write(typedata, 0, typedata.Length);
                    if (message.Value != null)
                    {
                        var serializer = SerializationContext.Default.GetSerializer(message.Type);
                        serializer.Pack(stream, message.Value);
                    }
                    buffer = stream.GetBuffer();
                    BitConverter.GetBytes((int)stream.Length - 4 - (int)index).CopyTo(buffer, index);
                    index = stream.Position;
                }
                byte[] array = stream.ToArray();
                data     = new Data(array, array.Length);
                data.Tag = messages;
            }
            return(data);
        }
コード例 #2
0
        public override IData GetMessageData(IList <Message> messages)
        {
            Beetle.Express.IData data = null;
            byte[] buffer;
            long   index = 0;

            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                foreach (Message message in messages)
                {
                    stream.Write(new byte[4], 0, 4);
                    byte[] typedata = MessageCenter.GetMessageTypeData(message.Type);
                    stream.Write(typedata, 0, typedata.Length);
                    if (message.Value != null)
                    {
                        ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, message.Value);
                    }
                    buffer = stream.GetBuffer();
                    BitConverter.GetBytes((int)stream.Length - 4 - (int)index).CopyTo(buffer, index);
                    index = stream.Position;
                }

                data     = new Data(stream.GetBuffer(), (int)stream.Length);
                data.Tag = messages;
            }
            return(data);
        }
コード例 #3
0
        public override Beetle.Express.IData GetMessageData(object message)
        {
            Beetle.Express.IData data = null;
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                stream.Write(new byte[4], 0, 4);
                byte[] typedata = MessageCenter.GetMessageTypeData(message.GetType());
                stream.Write(typedata, 0, typedata.Length);


                ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, message);

                data     = new Data(stream.GetBuffer(), (int)stream.Length);
                data.Tag = message;
                BitConverter.GetBytes((int)stream.Length - 4).CopyTo(data.Array, 0);
            }

            return(data);
        }
コード例 #4
0
        public override Beetle.Express.IData GetMessageData(object message)
        {
            Beetle.Express.IData data = null;
            Type type = message.GetType();

            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                stream.Write(new byte[4], 0, 4);
                byte[] typedata = MessageCenter.GetMessageTypeData(type);
                stream.Write(typedata, 0, typedata.Length);
                var serializer = SerializationContext.Default.GetSerializer(type);
                serializer.Pack(stream, message);

                data     = new Data(stream.GetBuffer(), (int)stream.Length);
                data.Tag = message;
                BitConverter.GetBytes((int)stream.Length - 4).CopyTo(data.Array, 0);
            }
            return(data);
        }
コード例 #5
0
ファイル: ProtobufPacket.cs プロジェクト: zhyzhy782/ec
        public override Beetle.Express.IData GetMessageData(object message)
        {
            Beetle.Express.IData data = null;
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                stream.Write(new byte[4], 0, 4);
                short typevalue = TypeMapper.GetValue(message);
                if (typevalue == 0)
                {
                    "{0} type value not registed".ThrowError <Exception>(message.GetType());
                }
                byte[] typedata = BitConverter.GetBytes(typevalue);
                stream.Write(typedata, 0, typedata.Length);
                ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, message);
                byte[] array = stream.ToArray();
                data = new Data(array, array.Length);
                BitConverter.GetBytes(array.Length - 4).CopyTo(array, 0);
            }

            return(data);
        }