Ejemplo n.º 1
0
 /// <summary>
 ///     第三方数据转换成元数据
 /// </summary>
 /// <param name="proxy">内存段实例</param>
 /// <param name="baseValueMessage">存储属性的实例对象</param>
 /// <exception cref="ArgumentNullException">参数不能为空</exception>
 public void ValueProcessor(IMemorySegmentProxy proxy, BaseValueStored baseValueMessage)
 {
     if (proxy == null)
     {
         throw new ArgumentNullException("proxy");
     }
     if (baseValueMessage == null)
     {
         throw new ArgumentNullException("baseValueMessage");
     }
     string[] value = baseValueMessage.GetValue <string[]>();
     proxy.WriteInt32(value.Length);
     if (value.Length == 0)
     {
         return;
     }
     for (int j = 0; j < value.Length; j++)
     {
         string elementValue = value[j];
         if (string.IsNullOrEmpty(elementValue))
         {
             proxy.WriteUInt16(0);
         }
         else
         {
             byte[] elementData = Encoding.UTF8.GetBytes(elementValue);
             proxy.WriteUInt16((ushort)elementData.Length);
             proxy.WriteMemory(elementData, 0U, (uint)elementData.Length);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     将一个对象字段转换为二进制元数据
        /// </summary>
        /// <param name="metadata">需要转换成元数据的Value字典</param>
        /// <param name="proxy">内存段代理器</param>
        internal unsafe static void ToBytes(ResourceBlock metadata, IMemorySegmentProxy proxy)
        {
            Dictionary <byte, BaseValueStored> valueStoreds = metadata.GetMetaDataDictionary();
            uint           markRangeLength      = (uint)(valueStoreds.Count * 5);
            MemoryPosition wrapperStartPosition = proxy.GetPosition();

            proxy.Skip(4U);
            proxy.WriteUInt16((ushort)(valueStoreds.Count));
            MemoryPosition wrapperMarkRangeStartPosition = proxy.GetPosition();

            proxy.Skip(markRangeLength);
            MemoryPosition wrapperOffsetStartPosition = proxy.GetPosition();
            MarkRange *    markRange = stackalloc MarkRange[valueStoreds.Count];
            int            i         = 0;

            foreach (KeyValuePair <byte, BaseValueStored> valueStored in valueStoreds)
            {
                //转化成二进制数组的形式
                MemoryPosition wrapperCurrentPosition = proxy.GetPosition();
                uint           currentOffset          = (uint)MemoryPosition.CalcLength(proxy.SegmentCount, wrapperOffsetStartPosition, wrapperCurrentPosition);
                (markRange + i)->Id     = valueStored.Key;
                (markRange + i++)->Flag = (uint)((currentOffset << 8) | (int)valueStored.Value.TypeId);
                if (valueStored.Value.IsNull)
                {
                    continue;
                }
                valueStored.Value.ToBytes(proxy);
            }
            MemoryPosition wrapperEndPosition = proxy.GetPosition();

            //回写mark Range
            proxy.WriteBackMemory(wrapperMarkRangeStartPosition, markRange, markRangeLength);
            //回写4bytes总长
            proxy.WriteBackInt32(wrapperStartPosition, MemoryPosition.CalcLength(proxy.SegmentCount, wrapperStartPosition, wrapperEndPosition));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            char value;

            if (!isNullable)
            {
                value = analyseResult.GetValue <char>(target);
            }
            else
            {
                char?nullableValue = analyseResult.GetValue <char?>(target);
                if (nullableValue == null)
                {
                    if (!attribute.IsRequire)
                    {
                        return;
                    }
                    throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id,
                                                                       analyseResult.Property.Name,
                                                                       analyseResult.Property.PropertyType));
                }
                value = (char)nullableValue;
            }
            if (attribute.AllowDefaultNull && value.Equals(DefaultValue.Char) && !isArrayElement)
            {
                return;
            }
            proxy.WriteByte((byte)attribute.Id);
            proxy.WriteChar(value);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   将一个IntellectObject数组转换成byte数组的形式
        /// </summary>
        /// <param name="value">值</param>
        /// <exception cref="UnexpectedValueException">结果错误</exception>
        /// <exception cref="ArgumentNullException">参数不能为空</exception>
        public static byte[] BindIntellectObjectArray(IntellectObject[] value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            MemoryAllotter.Instance.Initialize();
            IMemorySegmentProxy proxy = MemorySegmentProxyFactory.Create();

            proxy.WriteUInt32((uint)value.Length);
            for (int i = 0; i < value.Length; i++)
            {
                IntellectObject elementObj = value[i];
                if (elementObj == null)
                {
                    proxy.WriteUInt16(0);
                }
                else
                {
                    MemoryPosition currentPostion = proxy.GetPosition();
                    proxy.Skip(2U);
                    int length = IntellectObjectEngine.ToBytes(elementObj, proxy);
                    proxy.WriteBackUInt16(currentPostion, (ushort)length);
                }
            }
            return(proxy.GetBytes());
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     将指定类型的实例序列化为二进制数据
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="instance">实例对象</param>
        /// <returns>返回序列化后的二进制数据, 如果instance为null, 则返回null</returns>
        /// <exception cref="ArgumentNullException">type 参数不能为空</exception>
        /// <exception cref="NotSupportedException">不被支持的类型</exception>
        public static byte[] ToBytes(Type type, object instance)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (instance == null)
            {
                return(null);
            }
            MemoryAllotter.Instance.Initialize();
            IMemorySegmentProxy proxy = null;

            try
            {
                proxy = MemorySegmentProxyFactory.Create();
                ToBytes(type, instance, proxy);
                return(proxy.GetBytes());
            }
            catch
            {
                if (proxy != null)
                {
                    proxy.Dispose();
                }
                throw;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     将一个智能对象转换为二进制元数据
        /// </summary>
        /// <param name="obj">智能对象</param>
        /// <returns>返回二进制元数据</returns>
        /// <exception cref="PropertyNullValueException">字段相关的Attribute.IsRequire = true, 并且该字段的值为null</exception>
        /// <exception cref="UnexpectedValueException">不期待的结果异常,通常因为对Blob类型的取值 = null</exception>
        /// <exception cref="NotSupportedException">系统不支持的序列化类型</exception>
        /// <exception cref="DefineNoMeaningException">无意义的智能字段Attribute值</exception>
        /// <exception cref="MethodAccessException">类型权限定义错误</exception>
        /// <exception cref="Exception">内部错误</exception>
        public static byte[] ToBytes(IThriftObject obj)
        {
            if (obj == null)
            {
                return(null);
            }
            IMemorySegmentProxy proxy = null;

            try
            {
                proxy = MemorySegmentProxyFactory.Create();
                ToBytes(obj, proxy);
                //end flag of Thrift protocol object.
                proxy.WriteSByte(0x00);
                return(proxy.GetBytes());
            }
            catch (Exception ex)
            {
                if (proxy != null)
                {
                    proxy.Dispose();
                }
                throw;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 ///     �ӵ������ͻ�����ת��ΪԪ����
 /// </summary>
 /// <param name="proxy">�ڴ�Ƭ�δ�����</param>
 /// <param name="attribute">�ֶ�����</param>
 /// <param name="analyseResult">�������</param>
 /// <param name="target">Ŀ�����ʵ��</param>
 /// <param name="isArrayElement">��ǰд���ֵ�Ƿ�Ϊ����Ԫ�ر�ʾ</param>
 public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
 {
     int value = analyseResult.GetValue<int>(target);
     proxy.WriteSByte((sbyte)attribute.PropertyType);
     proxy.WriteInt16(((short)attribute.Id).ToBigEndian());
     proxy.WriteInt32(value.ToBigEndian());
 }
Ejemplo n.º 8
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            byte[] value = analyseResult.GetValue <byte[]>(target);
            if (value == null)
            {
                if (!attribute.IsRequire)
                {
                    return;
                }
                throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
            }
            //id(1) + total length(4) + rank(4)
            proxy.WriteByte((byte)attribute.Id);
            MemoryPosition position = proxy.GetPosition();

            proxy.Skip(4U);
            proxy.WriteInt32(value.Length);
            if (value.Length == 0)
            {
                proxy.WriteBackInt32(position, 4);
                return;
            }
            unsafe
            {
                fixed(byte *pByte = value) proxy.WriteMemory(pByte, (uint)value.Length * Size.Byte);
            }
            proxy.WriteBackInt32(position, (int)(value.Length * Size.Byte + 4));
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            byte value = analyseResult.GetValue <byte>(target);

            proxy.WriteSByte((sbyte)attribute.PropertyType);
            proxy.WriteInt16(((short)attribute.Id).ToBigEndian());
            proxy.WriteByte(value);
        }
 /// <summary>
 ///     �ӵ������ͻ�����ת��ΪԪ����
 /// </summary>
 /// <param name="proxy">�ڴ�Ƭ�δ�����</param>
 /// <param name="attribute">�ֶ�����</param>
 /// <param name="analyseResult">�������</param>
 /// <param name="target">Ŀ�����ʵ��</param>
 /// <param name="isArrayElement">��ǰд���ֵ�Ƿ�Ϊ����Ԫ�ر�ʾ</param>
 public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
 {
     MessageIdentity value = analyseResult.GetValue<MessageIdentity>(target);
     byte[] data = Encoding.UTF8.GetBytes(value.Command);
     proxy.WriteInt32(value.Version.ToBigEndian());
     proxy.WriteInt32(((int)value.CommandLength).ToBigEndian());
     proxy.WriteMemory(data, 0, (uint)data.Length);
     proxy.WriteInt32(((int)value.SequenceId).ToBigEndian());
 }
        /// <summary>
        ///     从第三方客户数据转换为元数据
        ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
        {
            MessageIdentity identity = (MessageIdentity)target;

            proxy.WriteByte(identity.ProtocolId);
            proxy.WriteByte(identity.ServiceId);
            proxy.WriteByte(identity.DetailsId);
            proxy.WriteInt16(identity.Tid);
        }
Ejemplo n.º 12
0
 /// <summary>
 ///     �ӵ������ͻ�����ת��ΪԪ����
 /// </summary>
 /// <param name="proxy">�ڴ�Ƭ�δ�����</param>
 /// <param name="attribute">�ֶ�����</param>
 /// <param name="analyseResult">�������</param>
 /// <param name="target">Ŀ�����ʵ��</param>
 /// <param name="isArrayElement">��ǰд���ֵ�Ƿ�Ϊ����Ԫ�ر�ʾ</param>
 public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
 {
     string value = analyseResult.GetValue<string>(target);
     proxy.WriteSByte((sbyte)attribute.PropertyType);
     proxy.WriteInt16(((short)attribute.Id).ToBigEndian());
     byte[] data = Encoding.UTF8.GetBytes(value);
     proxy.WriteInt32(data.Length.ToBigEndian());
     proxy.WriteMemory(data, 0, (uint) data.Length);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 从第三方客户数据转换为元数据
        /// <para>
        /// * 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)
        /// </para>
        /// </summary>
        /// <param name="proxy">内存片段代理器</param><param name="target">目标对象实例</param><param name="isArrayElement">当前写入的值是否为数组元素标示</param><param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
        {
            Color value = (Color)target;

            if (value == null)
            {
                return;
            }
            proxy.WriteMemory(value.Data, 0U, (uint)value.Data.Length);
        }
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            MessageIdentity value = analyseResult.GetValue <MessageIdentity>(target);

            byte[] data = Encoding.UTF8.GetBytes(value.Command);
            proxy.WriteInt32(value.Version.ToBigEndian());
            proxy.WriteInt32(((int)value.CommandLength).ToBigEndian());
            proxy.WriteMemory(data, 0, (uint)data.Length);
            proxy.WriteInt32(((int)value.SequenceId).ToBigEndian());
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
        {
            if (string.IsNullOrEmpty((string)target))
            {
                return;
            }
            string value = (string)target;

            proxy.WriteString(value);
        }
Ejemplo n.º 16
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
        {
            if (target == null)
            {
                return;
            }
            BitFlag value = (BitFlag)target;

            proxy.WriteBitFlag(value);
        }
        /// <summary>
        /// 从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param><param name="attribute">字段属性</param><param name="analyseResult">分析结果</param><param name="target">目标对象实例</param><param name="isArrayElement">当前写入的值是否为数组元素标示</param><param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            MessageIdentity identity = analyseResult.GetValue <MessageIdentity>(target);

            proxy.WriteByte((byte)attribute.Id);
            proxy.WriteByte(identity.ProtocolId);
            proxy.WriteByte(identity.ServiceId);
            proxy.WriteByte(identity.DetailsId);
            proxy.WriteInt16(identity.Tid);
        }
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            byte[] value = analyseResult.GetValue<byte[]>(target);
            proxy.WriteSByte((sbyte)attribute.PropertyType);
            proxy.WriteInt16(attribute.Id.ToBigEndian());

            //proxy.WriteByte((byte)PropertyTypes.String);
            proxy.WriteInt32(value.Length.ToBigEndian());
            proxy.WriteMemory(value, 0, (uint) value.Length);
        }
        /// <summary>
        ///     从第三方客户数据转换为元数据
        ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
        {
            if (target == null)
            {
                return;
            }
            IPEndPoint value = (IPEndPoint)target;

            proxy.WriteIPEndPoint(value);
        }
Ejemplo n.º 20
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            string value = analyseResult.GetValue <string>(target);

            proxy.WriteSByte((sbyte)attribute.PropertyType);
            proxy.WriteInt16(((short)attribute.Id).ToBigEndian());
            byte[] data = Encoding.UTF8.GetBytes(value);
            proxy.WriteInt32(data.Length.ToBigEndian());
            proxy.WriteMemory(data, 0, (uint)data.Length);
        }
Ejemplo n.º 21
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            byte[] value = analyseResult.GetValue <byte[]>(target);
            proxy.WriteSByte((sbyte)attribute.PropertyType);
            proxy.WriteInt16(attribute.Id.ToBigEndian());

            //proxy.WriteByte((byte)PropertyTypes.String);
            proxy.WriteInt32(value.Length.ToBigEndian());
            proxy.WriteMemory(value, 0, (uint)value.Length);
        }
 /// <summary>
 ///     第三方数据转换成元数据
 /// </summary>
 /// <param name="proxy">内存段实例</param>
 /// <param name="baseValueMessage">存储属性的实例对象</param>
 /// <exception cref="ArgumentNullException">参数不能为空</exception>
 public unsafe void ValueProcessor(IMemorySegmentProxy proxy, BaseValueStored baseValueMessage)
 {
     if (proxy == null)
     {
         throw new ArgumentNullException("proxy");
     }
     if (baseValueMessage == null)
         throw new ArgumentNullException("baseValueMessage");
     fixed(IntPtr *pByte = baseValueMessage.GetValue <IntPtr[]>())
     proxy.WriteMemory(pByte, (uint)baseValueMessage.GetValue <IntPtr[]>().Length *Size.IntPtr);
 }
Ejemplo n.º 23
0
 /// <summary>
 ///     从第三方客户数据转换为元数据
 ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
 /// </summary>
 /// <param name="proxy">内存片段代理器</param>
 /// <param name="target">目标对象实例</param>
 /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
 /// <param name="isNullable">是否为可空字段标示</param>
 public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
 {
     IPEndPoint[] array = (IPEndPoint[])target;
     if (array == null || array.Length == 0)
     {
         return;
     }
     for (int i = 0; i < array.Length; i++)
     {
         proxy.WriteIPEndPoint(array[i]);
     }
 }
Ejemplo n.º 24
0
 /// <summary>
 ///     第三方数据转换成元数据
 /// </summary>
 /// <param name="proxy">内存段实例</param>
 /// <param name="baseValueMessage">存储属性的实例对象</param>
 /// <exception cref="ArgumentNullException">参数不能为空</exception>
 public void ValueProcessor(IMemorySegmentProxy proxy, BaseValueStored baseValueMessage)
 {
     if (proxy == null)
     {
         throw new ArgumentNullException("proxy");
     }
     if (baseValueMessage == null)
     {
         throw new ArgumentNullException("baseValueMessage");
     }
     proxy.WriteMemory(baseValueMessage.GetValue <byte[]>(), 0, (uint)baseValueMessage.GetValue <byte[]>().Length);
 }
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            string[] value = analyseResult.GetValue<string[]>(target);
            proxy.WriteSByte((sbyte)attribute.PropertyType);
            proxy.WriteInt16(attribute.Id.ToBigEndian());

            proxy.WriteByte((byte)PropertyTypes.String);
            proxy.WriteInt32(value.Length.ToBigEndian());
            foreach (string data in value)
            {
                byte[] bytes = Encoding.UTF8.GetBytes(data);
                proxy.WriteInt32(bytes.Length.ToBigEndian());
                proxy.WriteMemory(bytes, 0, (uint)data.Length);
            }
        }
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            string[] value = analyseResult.GetValue <string[]>(target);
            proxy.WriteSByte((sbyte)attribute.PropertyType);
            proxy.WriteInt16(attribute.Id.ToBigEndian());

            proxy.WriteByte((byte)PropertyTypes.String);
            proxy.WriteInt32(value.Length.ToBigEndian());
            foreach (string data in value)
            {
                byte[] bytes = Encoding.UTF8.GetBytes(data);
                proxy.WriteInt32(bytes.Length.ToBigEndian());
                proxy.WriteMemory(bytes, 0, (uint)data.Length);
            }
        }
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            IPEndPoint value = analyseResult.GetValue <IPEndPoint>(target);

            if (value == null)
            {
                if (!attribute.IsRequire)
                {
                    return;
                }
                throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
            }
            proxy.WriteByte((byte)attribute.Id);
            proxy.WriteIPEndPoint(value);
        }
Ejemplo n.º 28
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
        {
            Blob value = (Blob)target;

            if (value == null)
            {
                return;
            }
            byte[] data = value.Compress();
            if (data == null)
            {
                return;
            }
            proxy.WriteMemory(data, 0U, (uint)data.Length);
        }
Ejemplo n.º 29
0
 /// <summary>
 ///     从第三方客户数据转换为元数据
 ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
 /// </summary>
 /// <param name="proxy">内存片段代理器</param>
 /// <param name="target">目标对象实例</param>
 /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
 /// <param name="isNullable">是否为可空字段标示</param>
 public unsafe override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
 {
     short[] array = (short[])target;
     if (array == null || array.Length == 0)
     {
         return;
     }
     if (array.Length > 10)
         fixed(short *pByte = array) proxy.WriteMemory(pByte, (uint)array.Length * Size.Int16);
     else
     {
         for (int i = 0; i < array.Length; i++)
         {
             proxy.WriteInt16(array[i]);
         }
     }
 }
Ejemplo n.º 30
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
        {
            char value;

            if (!isNullable)
            {
                value = (char)target;
            }
            else
            {
                if (target == null)
                {
                    return;
                }
                value = (char)target;
            }
            proxy.WriteChar(value);
        }
Ejemplo n.º 31
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            Color value = analyseResult.GetValue <Color>(target);

            if (value == null || value.Data == null)
            {
                if (attribute.IsRequire)
                {
                    if (attribute.IsRequire)
                    {
                        throw new Exception(string.Format("#Currently property data is required! Id: {0}", attribute.Id));
                    }
                }
                return;
            }
            proxy.WriteByte((byte)attribute.Id);
            proxy.WriteMemory(value.Data, 0U, (uint)value.Data.Length);
        }
Ejemplo n.º 32
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            string value = isArrayElement ? (string)target : analyseResult.GetValue <string>(target);

            if (value == null)
            {
                if (!attribute.IsRequire || isArrayElement)
                {
                    return;
                }
                throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
            }
            if (!isArrayElement)
            {
                proxy.WriteByte((byte)attribute.Id);
                proxy.WriteInt32(Encoding.UTF8.GetByteCount(value));
            }
            proxy.WriteString(value);
        }
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            Dictionary<string, Cell> value = analyseResult.GetValue<Dictionary<string, Cell>>(target);
            if (value == null) return;
            proxy.WriteSByte((sbyte)attribute.PropertyType);
            proxy.WriteInt16(attribute.Id.ToBigEndian());
            proxy.WriteByte((byte)PropertyTypes.String);
            proxy.WriteByte((byte)PropertyTypes.Struct);
            proxy.WriteInt32((value.Count).ToBigEndian());
            foreach (KeyValuePair<string, Cell> pair in value)
            {
                byte[] data = Encoding.UTF8.GetBytes(pair.Key);
                proxy.WriteInt32(data.Length.ToBigEndian());
                proxy.WriteMemory(data, 0, (uint)data.Length);

                pair.Value.Bind();
                data = pair.Value.Body;
                proxy.WriteMemory(data, 0, (uint)data.Length);
            }
        }
Ejemplo n.º 34
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
        {
            TransactionIdentity identity = (TransactionIdentity)target;

            if (identity == null)
            {
                return;
            }
            if (identity.IdentityType == TransactionIdentityTypes.TCP)
            {
                TCPTransactionIdentity.Serialize(0, IdentitySerializationTypes.IntellectObject, (TCPTransactionIdentity)identity, proxy);
            }
            else if (identity.IdentityType == TransactionIdentityTypes.NamedPipe)
            {
                NamedPipeTransactionIdentity.Serialize(0, IdentitySerializationTypes.IntellectObject, (NamedPipeTransactionIdentity)identity, proxy);
            }
            else
            {
                throw new NotSupportedException(string.Format("#We were not support current type of Transaction-Identity yet! {0}", identity.IdentityType));
            }
        }
Ejemplo n.º 35
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            Blob value = analyseResult.GetValue <Blob>(target);

            if (value == null)
            {
                if (!attribute.IsRequire)
                {
                    return;
                }
                throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
            }
            byte[] data = value.Compress();
            if (data == null)
            {
                throw new UnexpectedValueException(string.Format(ExceptionMessage.EX_UNEXPRECTED_VALUE, attribute.Id, analyseResult.Property.Name));
            }
            proxy.WriteByte((byte)attribute.Id);
            proxy.WriteInt32(data.Length);
            proxy.WriteMemory(data, 0U, (uint)data.Length);
        }
Ejemplo n.º 36
0
        /// <summary>
        /// 从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            TransactionIdentity identity = analyseResult.GetValue <TransactionIdentity>(target);

            if (identity == null)
            {
                return;
            }
            if (identity.IdentityType == TransactionIdentityTypes.TCP)
            {
                TCPTransactionIdentity.Serialize((byte)attribute.Id, IdentitySerializationTypes.IntellectObject, (TCPTransactionIdentity)identity, proxy);
            }
            else if (identity.IdentityType == TransactionIdentityTypes.NamedPipe)
            {
                NamedPipeTransactionIdentity.Serialize((byte)attribute.Id, IdentitySerializationTypes.IntellectObject, (NamedPipeTransactionIdentity)identity, proxy);
            }
            else
            {
                throw new NotSupportedException(string.Format("#We were not support current type of Transaction-Identity yet! {0}", identity.IdentityType));
            }
        }
Ejemplo n.º 37
0
 /// <summary>
 ///     �ӵ������ͻ�����ת��ΪԪ����
 /// </summary>
 /// <param name="proxy">�ڴ�Ƭ�δ�����</param>
 /// <param name="attribute">�ֶ�����</param>
 /// <param name="analyseResult">�������</param>
 /// <param name="target">Ŀ�����ʵ��</param>
 /// <param name="isArrayElement">��ǰд���ֵ�Ƿ�Ϊ����Ԫ�ر�ʾ</param>
 /// <param name="isNullable">�Ƿ�Ϊ�ɿ��ֶα�ʾ</param>
 public abstract void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false);