コード例 #1
0
        public override void Write(T value, TProtocol protocol)
        {
            TProtocolWriter writer = new TProtocolWriter(protocol);

            writer.WriteStructBegin(_metadata.StructName);
            foreach (ThriftFieldMetadata fieldMetadata in _metadata.GetFields(FieldKind.ThriftField))
            {
                // is the field readable?
                if (fieldMetadata.WriteOnly)
                {
                    continue;
                }

                // get the field value
                Object fieldValue = this.GetFieldValue(value, fieldMetadata);

                // write the field
                if (fieldValue != null)
                {
                    IThriftCodec codec;
                    if (!_fields.TryGetValue(fieldMetadata.Id, out codec))
                    {
                        throw new ThriftyException("IThriftCodec was not found.");
                    }
                    writer.WriteField(fieldMetadata.Name, fieldMetadata.Id, codec, fieldValue);
                }
            }
            writer.WriteStructEnd();
        }
コード例 #2
0
        protected override void OnWrite(DateTime value, TProtocolWriter writer)
        {
            //if (value.Kind != DateTimeKind.Utc)
            //{
            //    throw new ArgumentException("datetime thrift field invalid, only the utc datetime type are supported.");
            //}
            long longValue = ToLongValue(value);

            writer.WriteI64(longValue);
        }
コード例 #3
0
 protected override void OnWrite(DateTime[] value, TProtocolWriter writer)
 {
     if (value == null)
     {
         writer.WriteI64Array(null);
     }
     else
     {
         long[] result = new long[value.Length];
         for (var i = 0; i < value.Length; i++)
         {
             result[i] = DateTimeThriftCodec.ToLongValue(value[i]);
         }
         writer.WriteI64Array(result);
     }
 }
コード例 #4
0
        private void WriteResponse(TProtocol outProtocol,
                                   int sequenceId,
                                   TMessageType responseType,
                                   String responseFieldName,
                                   short responseFieldId,
                                   IThriftCodec responseCodec,
                                   Object result)
        {
            outProtocol.WriteMessageBegin(new TMessage(this.QualifiedName, responseType, sequenceId));

            TProtocolWriter writer = new TProtocolWriter(outProtocol);

            writer.WriteStructBegin(_resultStructName);
            writer.WriteField(responseFieldName, (short)responseFieldId, responseCodec, result);
            writer.WriteStructEnd();

            outProtocol.WriteMessageEnd();
            outProtocol.Transport.Flush();
        }
コード例 #5
0
        private void WriteArguments(TProtocol outProtocol, int sequenceId, Object[] args)
        {
            // Note that though setting message type to ONEWAY can be helpful when looking at packet
            // captures, some clients always send CALL and so servers are forced to rely on the "oneway"
            // attribute on thrift method in the interface definition, rather than checking the message
            // type.
            outProtocol.WriteMessageBegin(new TMessage(this.QualifiedName, _oneway ? TMessageType.Oneway : TMessageType.Call, sequenceId));

            // write the parameters
            TProtocolWriter writer = new TProtocolWriter(outProtocol);

            writer.WriteStructBegin(this.Name + "_args");
            for (int i = 0; i < args.Length; i++)
            {
                Object           value     = args[i];
                ParameterHandler parameter = _parameterCodecs[i];
                writer.WriteField(parameter.Name, parameter.Id, parameter.Codec, value);
            }
            writer.WriteStructEnd();

            outProtocol.WriteMessageEnd();
            outProtocol.Transport.Flush();
        }
コード例 #6
0
 protected override void OnWrite(string value, TProtocolWriter writer)
 {
     writer.WriteString(value);
 }
コード例 #7
0
 protected override void OnWrite(byte[] value, TProtocolWriter writer)
 {
     writer.WriteBinary(value);
 }
コード例 #8
0
ファイル: ByteThriftCodec.cs プロジェクト: ysj123688/Thrifty
 protected override void OnWrite(byte value, TProtocolWriter writer)
 {
     writer.WriteByte(value);
 }
コード例 #9
0
ファイル: GuidThriftCodec.cs プロジェクト: ysj123688/Thrifty
 protected override void OnWrite(Guid value, TProtocolWriter writer)
 {
     writer.WriteString(value.ToString());
 }
コード例 #10
0
 protected override void OnWrite(double value, TProtocolWriter writer)
 {
     writer.WriteDouble(value);
 }
コード例 #11
0
 protected abstract void OnWrite(T value, TProtocolWriter writer);
コード例 #12
0
ファイル: ShortThriftCodec.cs プロジェクト: ysj123688/Thrifty
 protected override void OnWrite(short value, TProtocolWriter writer)
 {
     writer.WriteI16(value);
 }
コード例 #13
0
 protected override void OnWrite(long[] value, TProtocolWriter writer)
 {
     writer.WriteI64Array(value);
 }
コード例 #14
0
 protected override void OnWrite(ISet <T> value, TProtocolWriter writer)
 {
     writer.WriteSet(_elementCodec, value);
 }
コード例 #15
0
 protected override void OnWrite(IDictionary <K, V> value, TProtocolWriter writer)
 {
     writer.WriteMap(_keyCodec, _valueCodec, value);
 }
コード例 #16
0
 protected override void OnWrite(IEnumerable <T> value, TProtocolWriter writer)
 {
     writer.WriteList(elementCodec, value.ToList());
 }
コード例 #17
0
 protected override void OnWrite(int value, TProtocolWriter writer)
 {
     writer.WriteI32(value);
 }
コード例 #18
0
 protected override void OnWrite(float[] value, TProtocolWriter writer)
 {
     writer.WriteDoubleArray(value.Select(f => (double)f).ToArray());
 }
コード例 #19
0
 protected override void OnWrite(bool value, TProtocolWriter writer)
 {
     writer.WriteBool(value);
 }