示例#1
0
        private static MessageField Create(TagAttribute attr, IFieldIO io)
        {
            int tag = attr.Number;

            if (attr.Fixed)
            {
                return(CreateFixed(tag, io));
            }

            if (attr.ZigZag)
            {
                return(CreateZigZag(tag, io));
            }

            Type type = io.FieldType;

            if (type.EqualsAny(typeof(int), typeof(long),
                               typeof(bool), typeof(uint), typeof(ulong)))
            {
                return(new MessageFieldVarint(tag, io));
            }

            if (type == typeof(string))
            {
                return(new MessageFieldString(tag, io));
            }

            if (type == typeof(byte[]))
            {
                return(new MessageFieldBytes(tag, io));
            }

            if (type == typeof(float))
            {
                return(new MessageFieldFixed(tag, io, WireType.Fixed32));
            }

            if (type == typeof(double))
            {
                return(new MessageFieldFixed(tag, io, WireType.Fixed64));
            }

            if (type.IsEnum)
            {
                return(new MessageFieldEnum(tag, io));
            }

            if (type == typeof(DateTime) || type == typeof(Decimal))
            {
                return(new MessageField(tag, io));
            }

            if (type == typeof(short) || type == typeof(ushort))
            {
                return(new MessageFieldInt16(tag, io));
            }

            return(new MessageFieldObject(tag, io));
        }
		public static bool TryCreate(PropertyInfo property, out IFieldIO io)
		{
			if (IsNullable(property))
			{
				io = new NullableFieldIO(property, true);
				return true;
			}
			io = null;
			return false;
		}
示例#3
0
 public static bool TryCreate(PropertyInfo property, out IFieldIO io)
 {
     if (IsNullable(property))
     {
         io = new NullableFieldIO(property, true);
         return(true);
     }
     io = null;
     return(false);
 }
示例#4
0
 protected static bool TryCreate(PropertyInfo property, Func<MethodInfo, IFieldIO> create, out IFieldIO io)
 {
     var add = property.PropertyType.GetMethod("Add");
     var getEnumerator = property.PropertyType.GetMethod("GetEnumerator");
     if (add == null || getEnumerator == null)
     {
         io = null;
         return false;
     }
     io = create(add);
     return true;
 }
        protected static bool TryCreate(PropertyInfo property,
                                        Func <MethodInfo, IFieldIO> creator, out IFieldIO io)
        {
            MethodInfo add           = property.PropertyType.GetMethod("Add");
            MethodInfo getEnumerator = property.PropertyType.GetMethod("GetEnumerator");

            if (add == null || getEnumerator == null)
            {
                io = null;
                return(false);
            }
            io = creator(add);
            return(true);
        }
示例#6
0
        private static MessageField CreateFixed(int tag, IFieldIO io)
        {
            Type type = io.FieldType;

            if (type == typeof(int) || type == typeof(uint))
            {
                return(new MessageFieldFixed(tag, io, WireType.Fixed32));
            }

            if (type == typeof(long) || type == typeof(ulong))
            {
                return(new MessageFieldFixed(tag, io, WireType.Fixed64));
            }

            throw new NotSupportedException(String.Format("Unsupported field type \"{0}\"", type));
        }
示例#7
0
        private static MessageField CreateZigZag(int tag, IFieldIO io)
        {
            Type type = io.FieldType;

            if (type == typeof(int))
            {
                return(new MessageFieldZigZagInt32(tag, io));
            }

            if (type == typeof(long))
            {
                return(new MessageFieldZigZagInt64(tag, io));
            }

            if (type == typeof(short))
            {
                return(new MessageFieldZigZagInt16(tag, io));
            }

            throw new NotSupportedException(String.Format("Unsupported field type \"{0}\"", type));
        }
 public MessageFieldZigZagInt32(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
示例#9
0
 public MessageFieldVarint(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
示例#10
0
 public MessageFieldBytes(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
示例#11
0
 public static bool TryCreate(PropertyInfo property, out IFieldIO io)
 {
     return(TryCreate(property, add => new RepeatedFieldIO(property, add), out io));
 }
示例#12
0
 public MessageFieldEnum(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
 public MessageFieldInt16(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
 public MessageFieldBytes(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
 public MessageFieldEnum(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
 public MessageFieldZigZagInt64(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
示例#17
0
 public MessageFieldFixed(int tag, IFieldIO fieldIO, WireType wireType)
     : base(tag, fieldIO)
 {
     _wireType = wireType;
 }
示例#18
0
 public MessageFieldVarint(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
示例#19
0
 protected MessageField(int tag, IFieldIO fieldIO)
 {
     _tag     = tag;
     _fieldIO = fieldIO;
 }
 public MessageFieldObject(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
 public MessageFieldString(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
		public MessageFieldObject(int tag, IFieldIO fieldIO)
			: base(tag, fieldIO)
		{
		}
		public static new bool TryCreate(PropertyInfo property, out IFieldIO io)
		{
			return TryCreate(property, add => new PackedFieldIO(property, add), out io);
		}
		public MessageFieldFixed(int tag, IFieldIO fieldIO, WireType wireType)
			: base(tag, fieldIO)
		{
			_wireType = wireType;
		}
示例#25
0
 public MessageFieldString(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }
示例#26
0
 public MessageFieldInt16(int tag, IFieldIO fieldIO)
     : base(tag, fieldIO)
 {
 }