List of usage examples for org.apache.thrift.protocol TType I64
byte I64
To view the source code for org.apache.thrift.protocol TType I64.
Click Source Link
From source file:cereal.impl.ThriftStructMapping.java
License:Apache License
@Override public List<Field> getFields(E obj) { checkNotNull(obj, "The struct was null"); List<Field> fields; try {/*from ww w. j av a 2 s . c o m*/ @SuppressWarnings("rawtypes") Class<? extends TBase> tbaseClz = obj.getClass(); if (null == getFieldValue) { synchronized (this) { if (null == getFieldValue) { Class<?> fieldsClz = Class.forName(obj.getClass().getName() + "$_Fields"); getFieldValue = tbaseClz.getMethod("getFieldValue", fieldsClz); isSet = tbaseClz.getMethod("isSet", fieldsClz); } } } Map<? extends TFieldIdEnum, FieldMetaData> thriftFields = FieldMetaData.getStructMetaDataMap(tbaseClz); fields = new ArrayList<>(); for (Entry<? extends TFieldIdEnum, FieldMetaData> entry : thriftFields.entrySet()) { TFieldIdEnum field = entry.getKey(); FieldMetaData fMetaData = entry.getValue(); if ((boolean) isSet.invoke(obj, field)) { Object value = getFieldValue.invoke(obj, field); FieldValueMetaData fvMetaData = fMetaData.valueMetaData; switch (fvMetaData.type) { case TType.BOOL: Boolean booleanVal = (Boolean) value; fields.add(new FieldImpl(text(fMetaData.fieldName), getGrouping(fMetaData), getVisibility(fMetaData), value(booleanVal.toString()))); break; case TType.BYTE: Byte byteVal = (Byte) value; fields.add(new FieldImpl(text(fMetaData.fieldName), getGrouping(fMetaData), getVisibility(fMetaData), value(byteVal.toString()))); break; case TType.DOUBLE: Double dblVal = (Double) value; fields.add(new FieldImpl(text(fMetaData.fieldName), getGrouping(fMetaData), getVisibility(fMetaData), value(dblVal.toString()))); break; case TType.I16: Short shortVal = (Short) value; fields.add(new FieldImpl(text(fMetaData.fieldName), getGrouping(fMetaData), getVisibility(fMetaData), value(shortVal.toString()))); break; case TType.I32: Integer intVal = (Integer) value; fields.add(new FieldImpl(text(fMetaData.fieldName), getGrouping(fMetaData), getVisibility(fMetaData), value(intVal.toString()))); break; case TType.I64: Long longVal = (Long) value; fields.add(new FieldImpl(text(fMetaData.fieldName), getGrouping(fMetaData), getVisibility(fMetaData), value(longVal.toString()))); break; case TType.STRING: byte[] bytes; if (fvMetaData.isBinary()) { bytes = (byte[]) value; } else { String strVal = (String) value; bytes = strVal.getBytes(UTF_8); } fields.add(new FieldImpl(text(fMetaData.fieldName), getGrouping(fMetaData), getVisibility(fMetaData), new Value(bytes))); break; default: log.warn("Ignoring field: {}", field.getFieldName()); break; } } } } catch (Exception e) { throw new RuntimeException(e); } return fields; }
From source file:cereal.impl.ThriftStructMapping.java
License:Apache License
@Override public void update(Iterable<Entry<Key, Value>> iter, InstanceOrBuilder<E> instOrBuilder) { checkNotNull(iter, "Iterator is null"); checkNotNull(instOrBuilder, "InstOrBuilder is null"); checkArgument(Type.INSTANCE == instOrBuilder.getType(), "Expected INSTANCE in InstanceOrBuilder"); try {// w ww . j a v a 2 s. com @SuppressWarnings("rawtypes") Class<? extends TBase> tbaseClz = instOrBuilder.getWrappedClass(); if (null == setFieldValue) { synchronized (this) { if (null == setFieldValue) { Class<?> fieldsClz = Class.forName(instOrBuilder.getWrappedClass().getName() + "$_Fields"); setFieldValue = tbaseClz.getMethod("setFieldValue", fieldsClz, Object.class); } } } for (Entry<Key, Value> entry : iter) { String fieldName = entry.getKey().getColumnQualifier().toString(); Map<? extends TFieldIdEnum, FieldMetaData> thriftFields = FieldMetaData .getStructMetaDataMap(tbaseClz); for (Entry<? extends TFieldIdEnum, FieldMetaData> fieldEntry : thriftFields.entrySet()) { TFieldIdEnum fieldId = fieldEntry.getKey(); if (fieldName.equals(fieldId.getFieldName())) { FieldValueMetaData fvMetaData = fieldEntry.getValue().valueMetaData; Value v = entry.getValue(); Object obj = instOrBuilder.get(); switch (fvMetaData.type) { case TType.BOOL: Boolean booleanVal = Boolean.parseBoolean(v.toString()); setFieldValue.invoke(obj, fieldId, booleanVal); break; case TType.BYTE: Byte byteVal = Byte.parseByte(v.toString()); setFieldValue.invoke(obj, fieldId, byteVal); break; case TType.DOUBLE: Double dblVal = Double.parseDouble(v.toString()); setFieldValue.invoke(obj, fieldId, dblVal); break; case TType.I16: Short shortVal = Short.parseShort(v.toString()); setFieldValue.invoke(obj, fieldId, shortVal); break; case TType.I32: Integer intVal = Integer.parseInt(v.toString()); setFieldValue.invoke(obj, fieldId, intVal); break; case TType.I64: Long longVal = Long.parseLong(v.toString()); setFieldValue.invoke(obj, fieldId, longVal); break; case TType.STRING: if (fvMetaData.isBinary()) { setFieldValue.invoke(obj, fieldId, ByteBuffer.wrap(v.get())); } else { String strVal = v.toString(); setFieldValue.invoke(obj, fieldId, strVal); } break; default: log.warn("Ignoring field: {}", fieldName); break; } } } } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.ambiata.poacher.mr.TDeserializerCopy.java
License:Apache License
/** * Deserialize only an i64 field (addressed by recursively using field id) * from a byte record.// ww w .j a v a 2 s . c om * @param bytes The serialized object to read from * @param fieldIdPathFirst First of the FieldId's that define a path to an i64 field * @param fieldIdPathRest The rest FieldId's that define a path to an i64 field * @throws TException */ public Long partialDeserializeI64(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException { return (Long) partialDeserializeField(TType.I64, bytes, fieldIdPathFirst, fieldIdPathRest); }
From source file:com.ambiata.poacher.mr.TDeserializerCopy.java
License:Apache License
private Object partialDeserializeField(byte ttype, byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException { try {// w ww.j a va2 s .co m TField field = locateField(bytes, fieldIdPathFirst, fieldIdPathRest); if (field != null) { // if this point is reached, iprot will be positioned at the start of the field. switch (ttype) { case TType.BOOL: if (field.type == TType.BOOL) { return protocol_.readBool(); } break; case TType.BYTE: if (field.type == TType.BYTE) { return protocol_.readByte(); } break; case TType.DOUBLE: if (field.type == TType.DOUBLE) { return protocol_.readDouble(); } break; case TType.I16: if (field.type == TType.I16) { return protocol_.readI16(); } break; case TType.I32: if (field.type == TType.I32) { return protocol_.readI32(); } break; case TType.I64: if (field.type == TType.I64) { return protocol_.readI64(); } break; case TType.STRING: if (field.type == TType.STRING) { return protocol_.readString(); } break; case 100: // hack to differentiate between string and binary if (field.type == TType.STRING) { return protocol_.readBinary(); } break; } } return null; } catch (Exception e) { throw new TException(e); } finally { trans_.clear(); protocol_.reset(); } }
From source file:com.baidu.oped.apm.plugin.thrift.ThriftRequestProperty.java
License:Apache License
public void setTraceHeader(ThriftHeader headerKey, Object value) throws TException { byte headerType = headerKey.getType(); if (headerType == TType.STRING) { // skipped Strings are read as byte buffer. // see org.apache.thrift.protocol.TProtocolUtil.skip(TProtocol, byte, int) this.thriftHeaders.put(headerKey, byteBufferToString((ByteBuffer) value)); } else if (headerType == TType.I64) { this.thriftHeaders.put(headerKey, (Long) value); } else if (headerType == TType.I16) { this.thriftHeaders.put(headerKey, (Short) value); } else if (headerType == TType.BOOL) { this.thriftHeaders.put(headerKey, (Boolean) value); } else {/*from w w w . j a v a2s . c o m*/ throw new TProtocolException("Invalid apm header type - " + headerType); } }
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;// w w w .j a v a 2 s . co m } 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.bigdata.dastor.thrift.Column.java
License:Apache License
public void read(TProtocol iprot) throws TException { TField field;/*w w w .j a va 2 s . co m*/ iprot.readStructBegin(); while (true) { field = iprot.readFieldBegin(); if (field.type == TType.STOP) { break; } switch (field.id) { case 1: // NAME if (field.type == TType.STRING) { this.name = iprot.readBinary(); } else { TProtocolUtil.skip(iprot, field.type); } break; case 2: // VALUE if (field.type == TType.STRING) { this.value = iprot.readBinary(); } else { TProtocolUtil.skip(iprot, field.type); } break; case 3: // TIMESTAMP if (field.type == TType.I64) { this.timestamp = iprot.readI64(); setTimestampIsSet(true); } else { TProtocolUtil.skip(iprot, field.type); } break; default: TProtocolUtil.skip(iprot, field.type); } iprot.readFieldEnd(); } iprot.readStructEnd(); // check for required fields of primitive type, which can't be checked in the validate method if (!isSetTimestamp()) { throw new TProtocolException( "Required field 'timestamp' was not found in serialized data! Struct: " + toString()); } validate(); }
From source file:com.bigdata.dastor.thrift.Deletion.java
License:Apache License
public void read(TProtocol iprot) throws TException { TField field;/*from w w w . j ava2 s. c o m*/ iprot.readStructBegin(); while (true) { field = iprot.readFieldBegin(); if (field.type == TType.STOP) { break; } switch (field.id) { case 1: // TIMESTAMP if (field.type == TType.I64) { this.timestamp = iprot.readI64(); setTimestampIsSet(true); } else { TProtocolUtil.skip(iprot, field.type); } break; case 2: // SUPER_COLUMN if (field.type == TType.STRING) { this.super_column = iprot.readBinary(); } else { TProtocolUtil.skip(iprot, field.type); } break; case 3: // PREDICATE if (field.type == TType.STRUCT) { this.predicate = new SlicePredicate(); this.predicate.read(iprot); } else { TProtocolUtil.skip(iprot, field.type); } break; default: TProtocolUtil.skip(iprot, field.type); } iprot.readFieldEnd(); } iprot.readStructEnd(); // check for required fields of primitive type, which can't be checked in the validate method if (!isSetTimestamp()) { throw new TProtocolException( "Required field 'timestamp' was not found in serialized data! Struct: " + toString()); } validate(); }
From source file:com.ebay.nest.io.sede.dynamic_type.DynamicSerDeTypei64.java
License:Apache License
@Override public byte getType() { return TType.I64; }
From source file:com.facebook.swift.codec.internal.TProtocolReader.java
License:Apache License
public long readI64Field() throws TException { if (!checkReadState(TType.I64)) { return 0; }//from w w w . jav a2s . c o m currentField = null; long fieldValue = protocol.readI64(); protocol.readFieldEnd(); return fieldValue; }