Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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);
        }