List of usage examples for org.apache.thrift.protocol TStruct TStruct
public TStruct(String n)
From source file:com.ebay.nest.io.sede.dynamic_type.DynamicSerDeStructBase.java
License:Apache License
/** * serialize/*from w w w . j a va2 s .co m*/ * * The way to serialize a Thrift "table" which in thrift land is really a * function and thus this class's name. * * @param o * - this list should be in the order of the function's params for * now. If we wanted to remove this requirement, we'd need to make it * a List<Pair<String, Object>> with the String being the field name. * */ @Override public void serialize(Object o, ObjectInspector oi, TProtocol oprot) throws TException, SerDeException, NoSuchFieldException, IllegalAccessException { if (thrift_mode) { oprot.writeStructBegin(new TStruct(name)); } fieldList.serialize(o, oi, oprot); if (thrift_mode) { oprot.writeStructEnd(); } }
From source file:com.facebook.swift.codec.internal.TProtocolWriter.java
License:Apache License
public void writeStructBegin(String name) throws TException { protocol.writeStructBegin(new TStruct(name)); }
From source file:com.ning.metrics.serialization.thrift.hadoop.TBoolean.java
License:Apache License
public void write(TProtocol oprot) throws TException { TStruct struct = new TStruct("TBoolean"); oprot.writeStructBegin(struct);/* w ww . j a v a 2 s. c o m*/ TField field = new TField("value", TType.BOOL, (short) 1); oprot.writeFieldBegin(field); oprot.writeBool(this.value); oprot.writeFieldEnd(); oprot.writeFieldStop(); oprot.writeStructEnd(); }
From source file:com.ning.metrics.serialization.thrift.ThriftEnvelopeSerializer.java
License:Apache License
public void serialize(ThriftEnvelope thriftEnvelope) throws IOException { try {/*w w w .j av a2 s. co m*/ protocol.writeStructBegin(new TStruct("EventEnvelope")); protocol.writeFieldBegin(TYPE_NAME_FIELD); protocol.writeString(thriftEnvelope.getTypeName()); protocol.writeFieldEnd(); if (!thriftEnvelope.getTypeName().equals(thriftEnvelope.getName())) { protocol.writeFieldBegin(NAME_FIELD); protocol.writeString(thriftEnvelope.getName()); protocol.writeFieldEnd(); } byte[] payload = payloadSerializer.createPayload(thriftEnvelope.getPayload()); protocol.writeFieldBegin(PAYLOAD_FIELD); protocol.writeBinary(ByteBuffer.wrap(payload)); protocol.writeFieldEnd(); protocol.writeFieldStop(); protocol.writeStructEnd(); } catch (TException e) { throw new IOException("error serializing Thrift" + thriftEnvelope, e); } }
From source file:com.ning.metrics.serialization.thrift.ThriftFieldListSerializer.java
License:Apache License
public void serialize(TProtocol protocol, List<ThriftField> thriftFieldList) throws TException { protocol.writeStructBegin(new TStruct("ThriftFieldList")); for (ThriftField serializer : thriftFieldList) { serializer.write(protocol);//from w ww .j a v a 2 s. c o m } protocol.writeFieldStop(); protocol.writeStructEnd(); }
From source file:mt.swift.MapSerializer.java
License:Apache License
public void serialize(Map<String, ?> map, String structName, TProtocol protocol) throws TException { StructureType structure = structures.get(structName); protocol.writeStructBegin(new TStruct(structName)); for (Field field : structure.getFields()) { Object value = map.get(field.getName()); if (value == null) { if (field.isRequired()) { throw new MissingFieldException(structure, field, map); }//from w w w .j a va2 s.co m continue; } protocol.writeFieldBegin(new TField(field.getName(), field.getType().getTType(), field.getId())); write(protocol, value, field.getType(), field); protocol.writeFieldEnd(); } protocol.writeFieldStop(); protocol.writeStructEnd(); }
From source file:mt.swift.TestUtil.java
License:Apache License
public static TStruct toTStruct(StructureType type) { return new TStruct(type.getName()); }
From source file:net.morimekta.providence.thrift.TProtocolSerializer.java
License:Apache License
private void writeMessage(PMessage<?, ?> message, TProtocol protocol) throws TException, SerializerException { PMessageDescriptor<?, ?> type = message.descriptor(); protocol.writeStructBegin(new TStruct(message.descriptor().getQualifiedName())); for (PField field : type.getFields()) { if (!message.has(field.getKey())) { continue; }/* w ww. j av a 2 s.c om*/ protocol.writeFieldBegin( new TField(field.getName(), getFieldType(field.getDescriptor()), (short) field.getKey())); writeTypedValue(message.get(field.getKey()), field.getDescriptor(), protocol); protocol.writeFieldEnd(); } protocol.writeFieldStop(); protocol.writeStructEnd(); }
From source file:org.apache.dubbo.rpc.protocol.thrift.ThriftNativeCodec.java
License:Apache License
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException { Invocation invocation = (Invocation) request.getData(); TProtocol protocol = newProtocol(channel.getUrl(), buffer); try {/*from w ww.jav a2 s. c om*/ protocol.writeMessageBegin( new TMessage(invocation.getMethodName(), TMessageType.CALL, thriftSeq.getAndIncrement())); protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args")); for (int i = 0; i < invocation.getParameterTypes().length; i++) { Class<?> type = invocation.getParameterTypes()[i]; } } catch (TException e) { throw new IOException(e.getMessage(), e); } }