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; }
public static bool TryCreate(PropertyInfo property, out IFieldIO io) { if (IsNullable(property)) { io = new NullableFieldIO(property, true); return(true); } io = null; return(false); }
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); }
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)); }
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) { }
public MessageFieldVarint(int tag, IFieldIO fieldIO) : base(tag, fieldIO) { }
public MessageFieldBytes(int tag, IFieldIO fieldIO) : base(tag, fieldIO) { }
public static bool TryCreate(PropertyInfo property, out IFieldIO io) { return(TryCreate(property, add => new RepeatedFieldIO(property, add), out io)); }
public MessageFieldEnum(int tag, IFieldIO fieldIO) : base(tag, fieldIO) { }
public MessageFieldInt16(int tag, IFieldIO fieldIO) : base(tag, fieldIO) { }
public MessageFieldZigZagInt64(int tag, IFieldIO fieldIO) : base(tag, fieldIO) { }
public MessageFieldFixed(int tag, IFieldIO fieldIO, WireType wireType) : base(tag, fieldIO) { _wireType = wireType; }
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 static new bool TryCreate(PropertyInfo property, out IFieldIO io) { return TryCreate(property, add => new PackedFieldIO(property, add), out io); }