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(); }
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); }
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); } }
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(); }
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(); }
protected override void OnWrite(string value, TProtocolWriter writer) { writer.WriteString(value); }
protected override void OnWrite(byte[] value, TProtocolWriter writer) { writer.WriteBinary(value); }
protected override void OnWrite(byte value, TProtocolWriter writer) { writer.WriteByte(value); }
protected override void OnWrite(Guid value, TProtocolWriter writer) { writer.WriteString(value.ToString()); }
protected override void OnWrite(double value, TProtocolWriter writer) { writer.WriteDouble(value); }
protected abstract void OnWrite(T value, TProtocolWriter writer);
protected override void OnWrite(short value, TProtocolWriter writer) { writer.WriteI16(value); }
protected override void OnWrite(long[] value, TProtocolWriter writer) { writer.WriteI64Array(value); }
protected override void OnWrite(ISet <T> value, TProtocolWriter writer) { writer.WriteSet(_elementCodec, value); }
protected override void OnWrite(IDictionary <K, V> value, TProtocolWriter writer) { writer.WriteMap(_keyCodec, _valueCodec, value); }
protected override void OnWrite(IEnumerable <T> value, TProtocolWriter writer) { writer.WriteList(elementCodec, value.ToList()); }
protected override void OnWrite(int value, TProtocolWriter writer) { writer.WriteI32(value); }
protected override void OnWrite(float[] value, TProtocolWriter writer) { writer.WriteDoubleArray(value.Select(f => (double)f).ToArray()); }
protected override void OnWrite(bool value, TProtocolWriter writer) { writer.WriteBool(value); }