Exemple #1
0
 /// <summary>
 /// Creates an expression checking whether the specified IDs are equal, and throwing if they aren't.
 /// </summary>
 private static Expression CreateTypeIdAssert(ThriftTypeId expected, Expression actual)
 {
     return(Expression.IfThen(
                Expression.NotEqual(
                    Expression.Constant(expected),
                    actual
                    ),
                Expression.Throw(
                    Expression.Call(
                        Methods.ThriftSerializationException_TypeIdMismatch,
                        Expression.Constant(expected),
                        actual
                        )
                    )
                ));
 }
Exemple #2
0
        /// <summary>
        /// Skips the specified ID from the specified protocol.
        /// </summary>
        /// <remarks>
        /// This method is only called from generated expressions.
        /// </remarks>
        public static void Skip(ThriftTypeId thriftTypeId, IThriftProtocol protocol)
        {
            switch (thriftTypeId)
            {
            case ThriftTypeId.Boolean:
                protocol.ReadBoolean();
                return;

            case ThriftTypeId.SByte:
                protocol.ReadSByte();
                return;

            case ThriftTypeId.Double:
                protocol.ReadDouble();
                return;

            case ThriftTypeId.Int16:
                protocol.ReadInt16();
                return;

            case ThriftTypeId.Int32:
                protocol.ReadInt32();
                return;

            case ThriftTypeId.Int64:
                protocol.ReadInt64();
                return;

            case ThriftTypeId.Binary:
                protocol.ReadBinary();
                return;

            case ThriftTypeId.List:
                var listHeader = protocol.ReadListHeader();
                for (int n = 0; n < listHeader.Count; n++)
                {
                    Skip(listHeader.ElementTypeId, protocol);
                }
                protocol.ReadListEnd();
                return;

            case ThriftTypeId.Set:
                var setHeader = protocol.ReadSetHeader();
                for (int n = 0; n < setHeader.Count; n++)
                {
                    Skip(setHeader.ElementTypeId, protocol);
                }
                protocol.ReadSetEnd();
                return;

            case ThriftTypeId.Map:
                var mapHeader = protocol.ReadMapHeader();
                for (int n = 0; n < mapHeader.Count; n++)
                {
                    Skip(mapHeader.KeyTypeId, protocol);
                    Skip(mapHeader.ValueTypeId, protocol);
                }
                protocol.ReadMapEnd();
                return;

            default:
                protocol.ReadStructHeader();
                while (true)
                {
                    var fieldHeader = protocol.ReadFieldHeader();
                    if (fieldHeader.TypeId == ThriftTypeId.Empty)
                    {
                        break;
                    }
                    Skip(fieldHeader.TypeId, protocol);
                    protocol.ReadFieldEnd();
                }
                protocol.ReadStructEnd();
                return;
            }
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the ThriftCollectionHeader class with the specified values.
 /// </summary>
 /// <param name="count">The number of elements.</param>
 /// <param name="elementTypeId">The elements' type ID.</param>
 public ThriftCollectionHeader(int count, ThriftTypeId elementTypeId)
 {
     Count         = count;
     ElementTypeId = elementTypeId;
 }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the ThriftFieldHeader class with the specified values.
 /// </summary>
 /// <param name="id">The field's ID.</param>
 /// <param name="name">The field's name.</param>
 /// <param name="typeId">The field's type ID.</param>
 public ThriftFieldHeader(short id, string name, ThriftTypeId typeId)
 {
     Id     = id;
     Name   = name;
     TypeId = typeId;
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the ThriftMapHeader class with the specified values.
 /// </summary>
 /// <param name="count">The number of elements.</param>
 /// <param name="keyTypeId">The keys' type ID.</param>
 /// <param name="valueTypeId">The values' type ID.</param>
 public ThriftMapHeader(int count, ThriftTypeId keyTypeId, ThriftTypeId valueTypeId)
 {
     Count       = count;
     KeyTypeId   = keyTypeId;
     ValueTypeId = valueTypeId;
 }
 internal static ThriftSerializationException TypeIdMismatch(ThriftTypeId expectedId, ThriftTypeId actualId)
 {
     return(new ThriftSerializationException($"Expected type {expectedId}, but type {actualId} was read."));
 }