本文整理汇总了Java中org.apache.thrift.TFieldIdEnum类的典型用法代码示例。如果您正苦于以下问题:Java TFieldIdEnum类的具体用法?Java TFieldIdEnum怎么用?Java TFieldIdEnum使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TFieldIdEnum类属于org.apache.thrift包,在下文中一共展示了TFieldIdEnum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printTbase
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
/**
* Prints a TBase.
*
* @param t The object to print.
* @param depth The print nesting level.
* @return The pretty-printed version of the TBase.
*/
private static String printTbase(TBase t, int depth) {
List<String> fields = Lists.newArrayList();
for (Map.Entry<? extends TFieldIdEnum, FieldMetaData> entry :
FieldMetaData.getStructMetaDataMap(t.getClass()).entrySet()) {
@SuppressWarnings("unchecked")
boolean fieldSet = t.isSet(entry.getKey());
String strValue;
if (fieldSet) {
@SuppressWarnings("unchecked")
Object value = t.getFieldValue(entry.getKey());
strValue = printValue(value, depth);
} else {
strValue = "not set";
}
fields.add(tabs(depth) + entry.getValue().fieldName + ": " + strValue);
}
return Joiner.on("\n").join(fields);
}
示例2: newField
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
/**
* Struct use only.
*
* @return
*/
public TField newField() {
if (createIndex < obj.length()) {
Map.Entry<TFieldIdEnum, FieldMetaData> entry = null;
if (addStep == 2) {
String fieldName = obj.getString(createIndex << 1);
entry = elementMetas.get(fieldName);
createIndex++;
} else {
int i = createIndex;
Object o;
while (i < obj.length() && ((o = obj.get(i)) == null || o == JSONObject.NULL)) {
currentIndex();// array index: +1
i++;
}
entry = elementMetaArr[i];
createIndex = i + 1;
}
FieldMetaData fm = entry.getValue();
prevFieldMetaData = fm;
return new TField(fm.fieldName, fm.valueMetaData.type, entry.getKey().getThriftFieldId());
}
return null;
}
示例3: thriftToMap
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
public static Map<String, Object> thriftToMap(
org.apache.thrift.TBase thriftObj) {
Map<String, Object> ret = new HashMap<String, Object>();
int i = 1;
TFieldIdEnum field = thriftObj.fieldForId(i);
while(field != null) {
if (thriftObj.isSet(field)) {
Object obj = thriftObj.getFieldValue(field);
ret.put(field.getFieldName(), thriftToObject(obj));
}
field = thriftObj.fieldForId(++i);
}
return ret;
}
示例4: toRpcRequest
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
private static RpcRequest toRpcRequest(Class<?> serviceType, String method, TBase<?, ?> thriftArgs) {
requireNonNull(thriftArgs, "thriftArgs");
// NB: The map returned by FieldMetaData.getStructMetaDataMap() is an EnumMap,
// so the parameter ordering is preserved correctly during iteration.
final Set<? extends TFieldIdEnum> fields =
FieldMetaData.getStructMetaDataMap(thriftArgs.getClass()).keySet();
// Handle the case where the number of arguments is 0 or 1.
final int numFields = fields.size();
switch (numFields) {
case 0:
return RpcRequest.of(serviceType, method);
case 1:
return RpcRequest.of(serviceType, method,
ThriftFieldAccess.get(thriftArgs, fields.iterator().next()));
}
// Handle the case where the number of arguments is greater than 1.
final List<Object> list = new ArrayList<>(numFields);
for (TFieldIdEnum field : fields) {
list.add(ThriftFieldAccess.get(thriftArgs, field));
}
return RpcRequest.of(serviceType, method, list);
}
示例5: getResult
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
/**
* Converts the specified {@code result} into a Java object.
*/
public Object getResult(TBase<?, ?> result) throws TException {
for (TFieldIdEnum fieldIdEnum : exceptionFields()) {
if (ThriftFieldAccess.isSet(result, fieldIdEnum)) {
throw (TException) ThriftFieldAccess.get(result, fieldIdEnum);
}
}
final TFieldIdEnum successField = successField();
if (successField == null) { //void method
return null;
} else if (ThriftFieldAccess.isSet(result, successField)) {
return ThriftFieldAccess.get(result, successField);
} else {
throw new TApplicationException(
TApplicationException.MISSING_RESULT,
result.getClass().getName() + '.' + successField.getFieldName());
}
}
示例6: listOf
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
/**
* To consume a list of elements
* @param c the type of the list content
* @param consumer the consumer that will receive the list
* @return a ListConsumer that can be passed to the DelegatingFieldConsumer
*/
public static <T extends TBase<T,? extends TFieldIdEnum>> ListConsumer listOf(Class<T> c, final Consumer<List<T>> consumer) {
class ListConsumer implements Consumer<T> {
List<T> list;
@Override
public void consume(T t) {
list.add(t);
}
}
final ListConsumer co = new ListConsumer();
return new DelegatingListElementsConsumer(struct(c, co)) {
@Override
public void consumeList(TProtocol protocol,
EventBasedThriftReader reader, TList tList) throws TException {
co.list = new ArrayList<T>();
super.consumeList(protocol, reader, tList);
consumer.consume(co.list);
}
};
}
示例7: ThriftRecordReader
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
public ThriftRecordReader(File dataFile, Schema schema, ThriftRecordReaderConfig recordReaderConfig) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
this._schema = schema;
this._dataFile = dataFile;
this._recordReaderConfig = recordReaderConfig;
this._thriftClass = initThriftInstanceCreator();
this._bufferIn = RecordReaderUtils.getFileBufferStream(dataFile);
this._binaryIn = new TBinaryProtocol(new TIOStreamTransport(_bufferIn));
this._fieldNameToIndexMap = new HashMap();
TBase t = this._thriftClass.newInstance();
int index = 1;
TFieldIdEnum fieldIdEnum = null;
do {
fieldIdEnum = t.fieldForId(index);
if (fieldIdEnum != null) {
_fieldNameToIndexMap.put(fieldIdEnum.getFieldName(), index);
}
index = index + 1;
} while (fieldIdEnum != null);
}
示例8: pushWriteField
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
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<>();
}
// Take the tbase class at the top of the stack
ThriftFieldMetadata thriftFieldMetadata = getTBaseFields(tbase).get(tfieldIdEnum.getThriftFieldId());
writeStack.push(thriftFieldMetadata);
threadSafeFieldsStack.set(writeStack);
}
}
示例9: thriftToMap
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
public static Map<String, Object> thriftToMap(
org.apache.thrift.TBase thriftObj) {
Map<String, Object> ret = new HashMap<>();
int i = 1;
TFieldIdEnum field = thriftObj.fieldForId(i);
while (field != null) {
if (thriftObj.isSet(field)) {
Object obj = thriftObj.getFieldValue(field);
ret.put(field.getFieldName(), thriftToObject(obj));
}
field = thriftObj.fieldForId(++i);
}
return ret;
}
示例10: createUnion
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
private static TUnion<?, ?> createUnion(
Class<?> unionType,
TFieldIdEnum setField,
Object fieldValue) throws IllegalAccessException, InstantiationException {
TUnion union = (TUnion) unionType.newInstance();
union.setFieldValue(setField, fieldValue);
return union;
}
示例11: getMetadataMap
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
private static Map<TFieldIdEnum, FieldMetaData>
getMetadataMap(Class c)
{
try {
Object o = c.newInstance();
return (Map) c.getField("metaDataMap").get(o);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例12: getIdForClass
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
private static TFieldIdEnum 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;
}
}
}
throw new RuntimeException("Could not find " + toFind.toString() +
" in " + meta.toString());
}
示例13: PropertyStructure
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
public PropertyStructure(Class prop) {
try {
Map<TFieldIdEnum, FieldMetaData> propMeta = getMetadataMap(prop);
Class valClass = Class.forName(prop.getName() + "Value");
valueId = getIdForClass(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);
}
}
示例14: setException
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
/**
* Sets the exception field of the specified {@code result} to the specified {@code cause}.
*/
public boolean setException(TBase<?, ?> result, Throwable cause) {
Class<?> causeType = cause.getClass();
for (Entry<Class<Throwable>, TFieldIdEnum> e : exceptionFields.entrySet()) {
if (e.getKey().isAssignableFrom(causeType)) {
ThriftFieldAccess.set(result, e.getValue(), cause);
return true;
}
}
return false;
}
示例15: getArgFields0
import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
private static TFieldIdEnum[] getArgFields0(Type type, Class<?> funcClass, String methodName) {
final String fieldIdEnumTypeName = typeName(type, funcClass, methodName, methodName + "_args$_Fields");
try {
Class<?> fieldIdEnumType = Class.forName(fieldIdEnumTypeName, false, funcClass.getClassLoader());
return (TFieldIdEnum[]) requireNonNull(fieldIdEnumType.getEnumConstants(),
"field enum may not be empty");
} catch (Exception e) {
throw new IllegalStateException("cannot determine the arg fields of method: " + methodName, e);
}
}