All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.thrift.protocol.TProtocolSupport Maven / Gradle / Ivy

The newest version!
package org.apache.thrift.protocol;

import static com.gitee.l0km.xthrift.reflection.FieldSupport.fieldValueOf;
import static com.gitee.l0km.xthrift.reflection.FieldSupport.setValueOfField;

import com.facebook.swift.codec.internal.TProtocolReader;

/**
 * @author guyadong
 * @since 1.3.2
 *
 */
public class TProtocolSupport {
	private static final String F_CURRENT_FIELD= "currentField";
	/**
	 * 反射方式获取{@code TProtocolReader#currentField}的name字段
	 * @param reader
	 */
	public static String getFieldName(TProtocolReader reader) {
		TField field = fieldValueOf(reader,F_CURRENT_FIELD);
		return field.name;
	}

	/**
	 * 反射方式修改{@code TProtocolReader#currentField}的type字段
	 * @param reader
	 * @param type
	 */
	public static void setTypeOfField(TProtocolReader reader, byte type) {
		TField field = fieldValueOf(reader,F_CURRENT_FIELD);
		setValueOfField(field,"type",type);
	}

	/**
	 * 反射方式修改{@link TProtocolReader#currentField}字段
	 * 
	 * @param reader
	 * @param value
	 */
	public static void setCurrentField(TProtocolReader reader, TField value) {
		setValueOfField(reader,F_CURRENT_FIELD,value);
	}

	static 

P fetchInstance(TProtocol protocol,Class

clazz) { if(clazz.isInstance(protocol)) { return clazz.cast(protocol); } if(protocol instanceof BufferedProtocol) { return fetchInstance(((BufferedProtocol)protocol).delegate,clazz); } return null; } static boolean isInstanceOf(TProtocol protocol,Classclazz) { return fetchInstance(protocol, clazz) != null; } public static TJSONProtocolXthrift fetchJSONXthrift(TProtocol protocol) { return fetchInstance(protocol,TJSONProtocolXthrift.class); } public static boolean isJSONXthrift(TProtocol protocol) { return isInstanceOf(protocol,TJSONProtocolXthrift.class); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy