protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException { Invocation invocation = (Invocation) request.getData(); TProtocol protocol = newProtocol(channel.getUrl(), buffer); try { 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); } }
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.getId())) { continue; } protocol.writeFieldBegin(new TField(field.getName(), forType(field.getDescriptor().getType()), (short) field.getId())); writeTypedValue(message.get(field.getId()), field.getDescriptor(), protocol); protocol.writeFieldEnd(); } protocol.writeFieldStop(); protocol.writeStructEnd(); }
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException { Invocation invocation = (Invocation) request.getData(); TProtocol protocol = newProtocol(channel.getUrl(), buffer); try { 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); } }
public void write(TProtocol oprot) throws TException { TStruct struct = new TStruct("TApplicationException"); TField field = new TField(); oprot.writeStructBegin(struct); if (getMessage() != null) { field.name = "message"; field.type = TType.STRING; field.id = 1; oprot.writeFieldBegin(field); oprot.writeString(getMessage()); oprot.writeFieldEnd(); } field.name = "type"; field.type = TType.I32; field.id = 2; oprot.writeFieldBegin(field); oprot.writeI32(type_); oprot.writeFieldEnd(); oprot.writeFieldStop(); oprot.writeStructEnd(); }
public TStruct readStructBegin() { BaseArray prevStruct = structStack.peek(); if (prevStruct != null) { BaseArray e = prevStruct.getArray(); structStack.push(e); } else { structStack.push(msgStruct); } return ANONYMOUS_STRUCT; }
@Override public TStruct readStructBegin() throws TException { if (err != null) { throw err; } return new TStruct(); }
@Override public TStruct readStructBegin() throws TException { if (structLevel == 1) { if (topLevelStructToBeRecorded == topLevelStruct) rememberingTransport.startRemeberingReadBytes(); } structLevel++; return super.readStructBegin(); }
public static void main(String[] args) throws TException { TTransport trans = new TSimpleFileTransport("data.comp", false, true); TProtocol proto = new TCompactProtocol(trans); Trade trade = new Trade(); trade.symbol = "F"; trade.price = 13.10; trade.size = 2500; proto.writeStructBegin(new TStruct()); proto.writeFieldBegin(new TField("symbol", TType.STRING, (short) 1)); proto.writeString(trade.symbol); proto.writeFieldEnd(); proto.writeFieldBegin(new TField("price", TType.DOUBLE, (short) 2)); proto.writeDouble(trade.price); proto.writeFieldEnd(); proto.writeFieldBegin(new TField("size", TType.I32, (short) 3)); proto.writeI32(trade.size); proto.writeFieldEnd(); proto.writeFieldStop(); proto.writeStructEnd(); System.out.println("Wrote trade to file"); }
public static void main(String[] args) throws TException { TTransport trans = new TSimpleFileTransport("data", true, false); TProtocol proto = new TBinaryProtocol(trans); Trade trade_read = new Trade(); TField field = new TField(); TStruct struct_obj = proto.readStructBegin(); while(true) { field = proto.readFieldBegin(); if (field.id == TType.STOP) { break; } switch(field.id) { case 1: trade_read.symbol = proto.readString(); break; case 2: trade_read.price = proto.readDouble(); break; case 3: trade_read.size = proto.readI32(); break; default: TProtocolUtil.skip(proto,field.type); break; } proto.readFieldEnd(); } proto.readStructEnd(); System.out.println("Trade: " + trade_read.symbol + " " + trade_read.size + " @ " + trade_read.price); }
private StructConverter(List<TProtocol> events, GroupType parquetSchema, ThriftField field) { this.events = events; this.name = field.getName(); this.tStruct = new TStruct(name); this.thriftType = (StructType)field.getType(); this.schemaSize = parquetSchema.getFieldCount(); this.converters = new Converter[this.schemaSize]; List<ThriftField> thriftChildren = thriftType.getChildren(); for (int i = 0; i < schemaSize; i++) { Type schemaType = parquetSchema.getType(i); String fieldName = schemaType.getName(); ThriftField matchingThrift = null; for (ThriftField childField: thriftChildren) { String thriftChildName = childField.getName(); if (thriftChildName != null && thriftChildName.equalsIgnoreCase(fieldName)) { matchingThrift = childField; break; } } if (matchingThrift == null) { // this means the file did not contain that field // it will never be populated in this instance // other files might populate it continue; } if (schemaType.isPrimitive()) { converters[i] = new PrimitiveFieldHandler(newConverter(events, schemaType, matchingThrift).asPrimitiveConverter(), matchingThrift, events); } else { converters[i] = new GroupFieldhandler(newConverter(events, schemaType, matchingThrift).asGroupConverter(), matchingThrift, events); } } }
private void readOneStruct(TProtocol in, TProtocol out) throws TException { final TStruct struct = in.readStructBegin(); out.writeStructBegin(struct); TField field; while ((field = in.readFieldBegin()).type != TType.STOP) { out.writeFieldBegin(field); readOneValue(in, out, field.type); in.readFieldEnd(); out.writeFieldEnd(); } out.writeFieldStop(); in.readStructEnd(); out.writeStructEnd(); }
public TStruct readStructBegin() throws TException { try { DBObject dbObject = null; Object thriftObject = null; if(!isContextEmpty()) { Context currentContext = peekContext(); if (currentContext instanceof ListContext) { dbObject = (DBObject) ((ListContext) currentContext).next(); thriftObject = ((ListContext) peekContext()).thriftObject; } else if (currentContext instanceof MapContext) { dbObject = (DBObject) ((MapContext) currentContext).next(); thriftObject = ((MapContext) peekContext()).thriftObject; } else { return ANONYMOUS_STRUCT; } } else { thriftObject = threadSafeTBase.get(); dbObject = getDBObject(); } StructContext context = new StructContext(thriftObject.getClass().getSimpleName()); context.setDbObject(dbObject); context.thriftObject = thriftObject; pushContext(context); return ANONYMOUS_STRUCT; } catch (Exception exp) { throw new TException("Unexpected readStructBegin", exp); } }
public void writeStructBegin(TStruct struct) throws TException { writeContext_.write(); trans_.write(LBRACE); pushWriteContext(new StructContext()); }
@Override protected TStruct getTStruct() { return STRUCT_DESC; }
@Override public void writeStructBegin(TStruct tStruct) throws TException { oprot.writeStructBegin(tStruct); }
public void writeStructBegin(TStruct struct) throws TException { this.writeContext_.write(); this.trans_.write(LBRACE); this.pushWriteContext(new TSimpleJSONProtocol.StructContext()); }
public TStruct readStructBegin() { return ANONYMOUS_STRUCT; }
@Override public void writeStructBegin(TStruct struct) throws TException { writeJsonObjectBegin(new StructContext(null)); }
@Override public void writeStructBegin(TStruct struct) throws TException { if (!writeFieldBegin) { protocol.writeStructBegin(struct); } }
@Override public TStruct readStructBegin() throws TException { throw new TException("unsupported operation"); }
public void writeStructBegin(TStruct struct) throws TException { delegate.writeStructBegin(struct); }
public TStruct readStructBegin() throws TException { return delegate.readStructBegin(); }
@Override public TStruct readStructBegin() throws TException { return new TStruct(structName); }
@Override public TStruct readStructBegin() throws TException { return tStruct; }