List of usage examples for org.apache.thrift TFieldIdEnum getThriftFieldId
public short getThriftFieldId();
From source file:backtype.storm.generated.ComponentObject.java
License:Apache License
@Override public int hashCode() { HashCodeBuilder hcb = new HashCodeBuilder(); hcb.append(this.getClass().getName()); org.apache.thrift.TFieldIdEnum setField = getSetField(); if (setField != null) { hcb.append(setField.getThriftFieldId()); Object value = getFieldValue(); if (value instanceof org.apache.thrift.TEnum) { hcb.append(((org.apache.thrift.TEnum) getFieldValue()).getValue()); } else {//from w w w . ja v a2 s . c o m hcb.append(value); } } return hcb.toHashCode(); }
From source file:backtype.storm.generated.HBMessageData.java
License:Apache License
@Override public int hashCode() { List<Object> list = new ArrayList<Object>(); list.add(this.getClass().getName()); org.apache.thrift.TFieldIdEnum setField = getSetField(); if (setField != null) { list.add(setField.getThriftFieldId()); Object value = getFieldValue(); if (value instanceof org.apache.thrift.TEnum) { list.add(((org.apache.thrift.TEnum) getFieldValue()).getValue()); } else {//from ww w .j a va2s. c om list.add(value); } } return list.hashCode(); }
From source file:com.mycompany.mavenpails2.PropertyStructure.java
public PropertyStructure(Class prop) { try {/*from w ww .j av a 2 s .co m*/ Map<TFieldIdEnum, FieldMetaData> propMeta = getMetadataMap(prop); Class valClass = Class.forName(prop.getName() + "Value"); valueId = getIdForClass(propMeta, valClass); fieldIdEnum = getTFieldIdEnumForClass(propMeta, valClass); validIds = new HashSet<Short>(); Map<TFieldIdEnum, FieldMetaData> valMeta = getMetadataMap(valClass); for (TFieldIdEnum valId : valMeta.keySet()) { validIds.add(valId.getThriftFieldId()); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.mycompany.mavenpails2.PropertyStructure.java
private static short getIdForClass(Map<TFieldIdEnum, FieldMetaData> meta, Class toFind) { for (TFieldIdEnum k : meta.keySet()) { FieldValueMetaData md = meta.get(k).valueMetaData; if (md instanceof StructMetaData) { if (toFind.equals(((StructMetaData) md).structClass)) { return k.getThriftFieldId(); }/*from w w w .ja va2s. c o m*/ } } throw new RuntimeException("Could not find " + toFind.toString() + " in " + meta.toString()); }
From source file:com.twitter.common.thrift.text.StructContext.java
License:Apache License
/** * Compute a new field name map for the current thrift message * we are parsing./*from w w w. j a v a 2s .c o m*/ */ private Map<String, TField> computeFieldNameMap() { Map<String, TField> map = new HashMap<String, TField>(); Class<? extends TBase> clazz = getCurrentThriftMessageClass(); // Get the metaDataMap for this Thrift class Map<? extends TFieldIdEnum, FieldMetaData> metaDataMap = FieldMetaData.getStructMetaDataMap(clazz); for (TFieldIdEnum key : metaDataMap.keySet()) { final String fieldName = key.getFieldName(); final FieldMetaData metaData = metaDataMap.get(key); // Workaround a bug in the generated thrift message read() // method by mapping the ENUM type to the INT32 type // The thrift generated parsing code requires that, when expecting // a value of enum, we actually parse a value of type int32. The // generated read() method then looks up the enum value in a map. byte type = (TType.ENUM == metaData.valueMetaData.type) ? TType.I32 : metaData.valueMetaData.type; map.put(fieldName, new TField(fieldName, type, key.getThriftFieldId())); } return map; }
From source file:org.apache.hadoop.hive.serde2.objectinspector.ThriftUnionObjectInspector.java
License:Apache License
@Override public byte getTag(final Object o) { if (o == null) { return -1; }//from ww w.j a v a 2 s . com final TFieldIdEnum setField = ((TUnion<? extends TUnion<?, ?>, ? extends TFieldIdEnum>) o).getSetField(); return UnsignedBytes.checkedCast((setField.getThriftFieldId() - 1)); }
From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONProtocol.java
License:Apache License
public void setFieldIdsFilter(TBase<?, ?> base, TFieldIdEnum[] fieldIds) { base.getClass();//w ww .j ava2 s .com List<Short> filteredFields = new ArrayList<>(); for (TFieldIdEnum tFieldIdEnum : fieldIds) { filteredFields.add(tFieldIdEnum.getThriftFieldId()); } Map<Class<?>, List<Short>> filter = new HashMap<>(); filter.put(base.getClass(), filteredFields); threadSafeFieldIds.set(filter); }
From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java
License:Apache License
public void setFieldIdsFilter(TBase<?, ?> base, TFieldIdEnum[] fieldIds) { base.getClass();//from w w w .ja v a 2s . c o m List<Short> filteredFields = new ArrayList<>(); for (TFieldIdEnum tFieldIdEnum : fieldIds) { filteredFields.add(tFieldIdEnum.getThriftFieldId()); } Map<Class<?>, List<Short>> filter = new HashMap<>(); filter.put(base.getClass(), filteredFields); threadSafeFieldIdsFilter.set(filter); }
From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java
License:Apache License
private Map<Short, ThriftFieldMetadata> getTBaseFields(Class<? extends TBase> tbase) throws TException { try {// w w w . ja v a2 s .c o m // First read if the ThriftFieldMetadata was not already readed Map<Class<?>, Map<Short, ThriftFieldMetadata>> thriftFields = threadSafeTFields.get(); if (thriftFields == null) { thriftFields = new HashMap<>(); } Map<Short, ThriftFieldMetadata> thriftStructFields = thriftFields.get(tbase); // Finded return it if (thriftStructFields != null) { return thriftStructFields; } // Load it thriftStructFields = new HashMap<>(); Field metafaField = tbase.getField("metaDataMap"); Map<?, FieldMetaData> fields = (Map<?, org.apache.thrift.meta_data.FieldMetaData>) metafaField .get(tbase); // list all fields for (Map.Entry<?, FieldMetaData> entry : fields.entrySet()) { TFieldIdEnum field = (TFieldIdEnum) entry.getKey(); ThriftFieldMetadata tfieldMetadata = new ThriftFieldMetadata(); // An enum type is deserialized as an I32 byte type = entry.getValue().valueMetaData.type; if (TType.ENUM == type) { type = TType.I32; } TBSONSecuredWrapper.ThriftSecuredField securedField = tbsonSecuredWrapper.getField(tbase, field.getThriftFieldId()); tfieldMetadata.tfield = new TField(field.getFieldName(), type, field.getThriftFieldId()); tfieldMetadata.fieldMetaData = entry.getValue(); tfieldMetadata.tbaseClass = tbase; tfieldMetadata.securedFieldMetaData = securedField; thriftStructFields.put(field.getThriftFieldId(), tfieldMetadata); } //store it thriftFields.put(tbase, thriftStructFields); threadSafeTFields.set(thriftFields); return thriftStructFields; } catch (Exception exp) { throw new TException(exp); } }
From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java
License:Apache License
private void pushWriteField(Class<? extends TBase> tbase, String fieldName) throws TException { //get the field ID by name org.apache.thrift.TFieldIdEnum tfieldIdEnum = getFieldId(tbase, fieldName); if (tfieldIdEnum != null) { //pushWriteField(tfieldIdEnum.getThriftFieldId()); Stack<ThriftFieldMetadata> writeStack = threadSafeFieldsStack.get(); // First push if (writeStack == null) { writeStack = new Stack<>(); }/*from w w w. j a v a2s. c om*/ // Take the tbase class at the top of the stack ThriftFieldMetadata thriftFieldMetadata = getTBaseFields(tbase).get(tfieldIdEnum.getThriftFieldId()); writeStack.push(thriftFieldMetadata); threadSafeFieldsStack.set(writeStack); } }