コード例 #1
0
        /// <summary>
        /// Writes the specified method call on the specified protocol.
        /// </summary>
        public static void Write(ThriftMethod method, object[] args, IThriftProtocol protocol)
        {
            if (!_knownWriters.ContainsKey(method))
            {
                _knownWriters.TryAdd(method, CreateWriterForMethod(method).Compile());
            }

            _knownWriters[method](args, protocol);
        }
コード例 #2
0
        /// <summary>
        /// Reads a ThriftMessage returned by the specified method on the specified protocol.
        /// </summary>
        public static T Read <T>(ThriftMethod method, IThriftProtocol protocol)
        {
            if (!_knownReaders.ContainsKey(method))
            {
                _knownReaders.TryAdd(method, CreateReaderForMethod(method).Compile());
            }

            return(((Func <IThriftProtocol, T>)_knownReaders[method])(protocol));
        }
コード例 #3
0
        /// <summary>
        /// Reads the specified struct from the specified protocol.
        /// </summary>
        /// <remarks>
        /// This method is only called from generated expressions.
        /// </remarks>
        public static T Read <T>(IThriftProtocol protocol)
        {
            var thriftStruct = ThriftAttributesParser.ParseStruct(typeof(T).GetTypeInfo());

            if (!_knownReaders.ContainsKey(thriftStruct))
            {
                _knownReaders.TryAdd(thriftStruct, CreateReaderForStruct(thriftStruct).Compile());
            }

            return(((Func <IThriftProtocol, T>)_knownReaders[thriftStruct])(protocol));
        }
コード例 #4
0
        /// <summary>
        /// Writes the specified value to the specified protocol.
        /// </summary>
        /// <remarks>
        /// This method is only called from compiled expressions.
        /// </remarks>
        public static void Write <T>(T value, IThriftProtocol protocol)
        {
            var thriftStruct = ThriftAttributesParser.ParseStruct(typeof(T).GetTypeInfo());

            if (!_knownWriters.ContainsKey(thriftStruct))
            {
                _knownWriters.TryAdd(thriftStruct, CreateWriterForStruct(thriftStruct).Compile());
            }

            ((Action <T, IThriftProtocol>)_knownWriters[thriftStruct])(value, protocol);
        }
コード例 #5
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;
            }
        }