Example usage for org.apache.thrift.protocol TField TField

List of usage examples for org.apache.thrift.protocol TField TField

Introduction

In this page you can find the example usage for org.apache.thrift.protocol TField TField.

Prototype

public TField(String n, byte t, short i) 

Source Link

Usage

From source file:com.baidu.oped.apm.plugin.thrift.ThriftRequestProperty.java

License:Apache License

public void writeTraceHeader(ThriftHeader headerKey, TProtocol oprot) throws TException {
    Object headerValue = this.thriftHeaders.get(headerKey);
    if (headerValue == null) {
        return;/*from  w w w.j a  v  a 2 s . c om*/
    }
    byte headerType = headerKey.getType();
    TField traceField = new TField(headerKey.name(), headerKey.getType(), headerKey.getId());
    oprot.writeFieldBegin(traceField);
    try {
        if (headerType == TType.STRING) {
            // these will be read as byte buffer although it's probably safe to just use writeString here.
            // see org.apache.thrift.protocol.TProtocolUtil.skip(TProtocol, byte, int)
            oprot.writeBinary(stringToByteBuffer((String) headerValue));
        } else if (headerType == TType.I64) {
            oprot.writeI64((Long) headerValue);
        } else if (headerType == TType.I16) {
            oprot.writeI16((Short) headerValue);
        } else if (headerType == TType.BOOL) {
            oprot.writeBool((Boolean) headerValue);
        } else {
            throw new TProtocolException("Invalid apm header type - " + headerType);
        }
    } finally {
        oprot.writeFieldEnd();
    }
}

From source file:com.ebay.nest.io.sede.dynamic_type.DynamicSerDeFieldList.java

License:Apache License

public void serialize(Object o, ObjectInspector oi, TProtocol oprot)
        throws TException, SerDeException, NoSuchFieldException, IllegalAccessException {
    // Assuming the ObjectInspector represents exactly the same type as this
    // struct.//from   ww  w.  ja  v  a2 s .c om
    // This assumption should be checked during query compile time.
    assert (oi instanceof StructObjectInspector);
    StructObjectInspector soi = (StructObjectInspector) oi;

    boolean writeNulls = oprot instanceof com.ebay.nest.io.sede.thrift.WriteNullsProtocol;

    // For every field
    List<? extends StructField> fields = soi.getAllStructFieldRefs();
    if (fields.size() != ordered_types.length) {
        throw new SerDeException("Trying to serialize " + fields.size() + " fields into a struct with "
                + ordered_types.length + " object=" + o + " objectinspector=" + oi.getTypeName());
    }
    for (int i = 0; i < fields.size(); i++) {
        Object f = soi.getStructFieldData(o, fields.get(i));
        DynamicSerDeTypeBase mt = ordered_types[i];

        if (f == null && !writeNulls) {
            continue;
        }

        if (thrift_mode) {
            field = new TField(mt.name, mt.getType(), (short) mt.fieldid);
            oprot.writeFieldBegin(field);
        }

        if (f == null) {
            ((com.ebay.nest.io.sede.thrift.WriteNullsProtocol) oprot).writeNull();
        } else {
            mt.serialize(f, fields.get(i).getFieldObjectInspector(), oprot);
        }
        if (thrift_mode) {
            oprot.writeFieldEnd();
        }
    }
    if (thrift_mode) {
        oprot.writeFieldStop();
    }
}

From source file:com.ebay.nest.io.sede.thrift.TCTLSeparatedProtocol.java

License:Apache License

@Override
public TField readFieldBegin() throws TException {
    assert (!inner);
    TField f = new TField("", ORDERED_TYPE, (short) -1);
    // slight hack to communicate to DynamicSerDe that the field ids are not
    // being set but things are ordered.
    return f;//from  www.j a  v a 2 s.c o m
}

From source file:com.facebook.nifty.core.TestThriftFrameDecoder.java

License:Apache License

private void writeTestMessages(TBinaryProtocol protocol, int count) throws TException {
    for (int i = 0; i < count; i++) {
        protocol.writeMessageBegin(new TMessage("testmessage" + i, TMessageType.CALL, i));
        {// w  ww  .ja va2  s  . co  m
            protocol.writeStructBegin(new TStruct());
            {
                protocol.writeFieldBegin(new TField("i32field", TType.I32, (short) 1));
                protocol.writeI32(123);
                protocol.writeFieldEnd();
            }
            {
                protocol.writeFieldBegin(new TField("strfield", TType.STRING, (short) 2));
                protocol.writeString("foo");
                protocol.writeFieldEnd();
            }
            {
                protocol.writeFieldBegin(new TField("boolfield", TType.BOOL, (short) 3));
                protocol.writeBool(true);
                protocol.writeFieldEnd();
            }
            protocol.writeFieldStop();
            protocol.writeStructEnd();
        }
        protocol.writeMessageEnd();
        protocol.getTransport().flush();
    }
}

From source file:com.facebook.swift.codec.internal.TProtocolWriter.java

License:Apache License

public <T> void writeField(String name, short id, ThriftCodec<T> codec, T value) throws Exception {
    if (value == null) {
        return;//from   www.  j a  v  a  2 s  . c  om
    }

    protocol.writeFieldBegin(new TField(name, codec.getType().getProtocolType().getType(), id));
    codec.write(value, protocol);
    protocol.writeFieldEnd();
}

From source file:com.facebook.swift.codec.internal.TProtocolWriter.java

License:Apache License

public void writeBinaryField(String name, short id, ByteBuffer buf) throws TException {
    if (buf == null) {
        return;//w ww  . jav a  2s .  c  om
    }
    protocol.writeFieldBegin(new TField(name, TType.STRING, id));
    protocol.writeBinary(buf);
    protocol.writeFieldEnd();
}

From source file:com.facebook.swift.codec.internal.TProtocolWriter.java

License:Apache License

public void writeBoolField(String name, short id, boolean b) throws TException {
    protocol.writeFieldBegin(new TField(name, TType.BOOL, id));
    protocol.writeBool(b);/*from  ww  w . j  a va2 s .c om*/
    protocol.writeFieldEnd();
}

From source file:com.facebook.swift.codec.internal.TProtocolWriter.java

License:Apache License

public void writeByteField(String name, short id, byte b) throws TException {
    protocol.writeFieldBegin(new TField(name, TType.BYTE, id));
    protocol.writeByte(b);/*from w w w.  j  a  v a 2 s.c o  m*/
    protocol.writeFieldEnd();
}

From source file:com.facebook.swift.codec.internal.TProtocolWriter.java

License:Apache License

public void writeDoubleField(String name, short id, double dub) throws TException {
    protocol.writeFieldBegin(new TField(name, TType.DOUBLE, id));
    protocol.writeDouble(dub);//from ww w.  j a  v  a2 s.  c om
    protocol.writeFieldEnd();
}

From source file:com.facebook.swift.codec.internal.TProtocolWriter.java

License:Apache License

public void writeI16Field(String name, short id, short i16) throws TException {
    protocol.writeFieldBegin(new TField(name, TType.I16, id));
    protocol.writeI16(i16);/*from w w w .j a  va 2  s.  c om*/
    protocol.writeFieldEnd();
}