/// <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> /// 从第三方客户数据转换为元数据 /// </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> /// 从第三方客户数据转换为元数据 /// </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) { int value; if (!isNullable) { value = analyseResult.GetValue <int>(target); } else { int?nullableValue = analyseResult.GetValue <int?>(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 = (int)nullableValue; } if (attribute.AllowDefaultNull && value.Equals(DefaultValue.Int32) && !isArrayElement) { return; } proxy.WriteByte((byte)attribute.Id); proxy.WriteInt32(value); }
/// <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); } } }
/// <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()); }
/// <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)); }
/// <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()); }
/// <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); }
/// <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="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); }
/// <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="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); } }
/// <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, string> value = analyseResult.GetValue <Dictionary <string, string> >(target); if (value == null) { return; } proxy.WriteSByte((sbyte)attribute.PropertyType); proxy.WriteInt16(attribute.Id.ToBigEndian()); proxy.WriteByte((byte)PropertyTypes.String); proxy.WriteByte((byte)PropertyTypes.String); proxy.WriteInt32((value.Count).ToBigEndian()); foreach (KeyValuePair <string, string> pair in value) { byte[] data = Encoding.UTF8.GetBytes(pair.Key); proxy.WriteInt32(data.Length.ToBigEndian()); proxy.WriteMemory(data, 0, (uint)data.Length); data = Encoding.UTF8.GetBytes(pair.Value); proxy.WriteInt32(data.Length.ToBigEndian()); proxy.WriteMemory(data, 0, (uint)data.Length); } }
/// <summary> /// 序列化当前事务唯一标示 /// </summary> /// <param name="id">如果是以智能对象的方式进行序列化,则此ID为标签ID</param> /// <param name="serializationType">序列化方式</param> /// <param name="identity">被序列化的事务唯一标示</param> /// <param name="proxy">内存片段代理器</param> public static void Serialize(byte id, IdentitySerializationTypes serializationType, TCPTransactionIdentity identity, IMemorySegmentProxy proxy) { if (serializationType == IdentitySerializationTypes.IntellectObject) { //writes attribute id. proxy.WriteByte(id); //writes TCP transaction identity total length. proxy.WriteInt32(19); } proxy.WriteByte((byte)identity.IdentityType); proxy.WriteByte((byte)(identity.IsRequest ? 1 : 0)); proxy.WriteByte((byte)(identity.IsOneway ? 1 : 0)); proxy.WriteIPEndPoint((IPEndPoint)identity.EndPoint); proxy.WriteUInt32(identity.MessageId); }
/// <summary> /// 序列化当前事务唯一标示 /// </summary> /// <param name="id">如果是以智能对象的方式进行序列化,则此ID为标签ID</param> /// <param name="serializationType">序列化方式</param> /// <param name="identity">被序列化的事务唯一标示</param> /// <param name="proxy">内存片段代理器</param> public static void Serialize(byte id, IdentitySerializationTypes serializationType, NamedPipeTransactionIdentity identity, IMemorySegmentProxy proxy) { if (serializationType == IdentitySerializationTypes.IntellectObject) { //writes attribute id. proxy.WriteByte(id); //writes NamedPipe transaction identity total length. proxy.WriteInt32(15); } proxy.WriteByte((byte)identity.IdentityType); proxy.WriteByte((byte)(identity.IsRequest ? 1 : 0)); proxy.WriteByte((byte)(identity.IsOneway ? 1 : 0)); proxy.WriteUInt64(((NamedPipeEndPoint)identity.EndPoint).GetPipeCodeId()); proxy.WriteUInt32(identity.MessageId); }
/// <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) { int[] array = (int[])target; if (array == null || array.Length == 0) { return; } if (array.Length > 10) fixed(int *pByte = array) proxy.WriteMemory(pByte, (uint)array.Length * Size.Int32); else { for (int i = 0; i < array.Length; i++) { proxy.WriteInt32(array[i]); } } }
/// <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) { int value; if (!isNullable) { value = (int)target; } else { if (target == null) { return; } value = (int)target; } proxy.WriteInt32(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, 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, 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); }
/// <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 = analyseResult.GetValue <string[]>(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; } for (int i = 0; i < value.Length; i++) { string elementValue = value[i]; 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); } } MemoryPosition endPosition = proxy.GetPosition(); proxy.WriteBackInt32(position, MemoryPosition.CalcLength(proxy.SegmentCount, position, endPosition) - 4); }