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
        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();
        }
예제 #3
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();
        }