Exemplo n.º 1
0
        public DynamicItem(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var valueType = value.GetType();
            var code      = Type.GetTypeCode(valueType);

            if (code != TypeCode.Object)
            {
                TypeName = valueType.FullName;
            }
            else
            {
                TypeName = valueType.AssemblyQualifiedName;
            }

            if (valueType == UtilityType.JObjectType)
            {
                Content = SerializerUtilitys.Serialize(value.ToString());
            }
            else
            {
                Content = SerializerUtilitys.Serialize(value);
            }
        }
Exemplo n.º 2
0
        public DynamicItem(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var valueType = value.GetType();
            var code      = Type.GetTypeCode(valueType);

            if (code != TypeCode.Object && valueType.BaseType != typeof(Enum))
            {
                TypeName = valueType.FullName;
            }
            else
            {
                TypeName = valueType.AssemblyQualifiedName;
            }

            if (valueType == TypeHelper.JObjectType || valueType == TypeHelper.JArrayType)
            {
                Content = SerializerUtilitys.Serialize(value.ToString());
            }
            else if (valueType != typeof(CancellationToken))
            {
                Content = SerializerUtilitys.Serialize(value);
            }
        }
Exemplo n.º 3
0
        public byte[] Serialize()
        {
            Checkbit = 0x1F;
            Length   = 4 * 3;
            var bodyArray = SerializerUtilitys.Serialize(Body);

            Length += bodyArray.Length;
            return(bodyArray);
        }
        public byte[] Encode(TransportMessage message)
        {
            var transportMessage = new MessagePackTransportMessage(message)
            {
                Id          = message.Id,
                ContentType = message.ContentType
            };

            return(SerializerUtilitys.Serialize(transportMessage));
        }
Exemplo n.º 5
0
        public ProtoBufTransportMessage(TransportMessage transportMessage)
        {
            Id          = transportMessage.Id;
            ContentType = transportMessage.ContentType;
            if (transportMessage.IsInvokeMessage())
            {
                Content = SerializerUtilitys.Serialize(
                    new ProtoBufRemoteInvokeMessage(transportMessage.GetContent <RemoteInvokeMessage>()));
            }

            if (transportMessage.IsResultMessage())
            {
                Content = SerializerUtilitys.Serialize(
                    new ProtoBufRemoteResultMessage(transportMessage.GetContent <RemoteResultMessage>()));
            }
        }
Exemplo n.º 6
0
        public MessagePackDynamicItem(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var valueType = value.GetType();
            var code      = Type.GetTypeCode(valueType);

            if (code != TypeCode.Object && valueType.BaseType != typeof(Enum))
            {
                TypeName = valueType.FullName;
            }
            else
            {
                TypeName = valueType.AssemblyQualifiedName;
            }

            Content = SerializerUtilitys.Serialize(value);
        }
Exemplo n.º 7
0
        public ProtoBufferTransportMessage(TransportMessage transportMessage)
        {
            Id          = transportMessage.Id;
            ContentType = transportMessage.ContentType;

            object contentObject;

            if (transportMessage.IsInvokeMessage())
            {
                contentObject = new ProtoBufferRemoteInvokeMessage(transportMessage.GetContent <RemoteInvokeMessage>());
            }
            else if (transportMessage.IsInvokeResultMessage())
            {
                contentObject = new ProtoBufferRemoteInvokeResultMessage(transportMessage.GetContent <RemoteInvokeResultMessage>());
            }
            else
            {
                throw new NotSupportedException($"无法支持的消息类型:{ContentType}!");
            }

            Content = SerializerUtilitys.Serialize(contentObject);
        }
Exemplo n.º 8
0
        public ProtoBufferDynamicItem(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var valueType = value.GetType();
            var code      = Type.GetTypeCode(valueType);

            //如果是简单类型则取短名称,否则取长名称。
            if (code != TypeCode.Object)
            {
                TypeName = valueType.FullName;
            }
            else
            {
                TypeName = valueType.AssemblyQualifiedName;
            }

            Content = SerializerUtilitys.Serialize(value);
        }