本文整理汇总了Java中org.apache.thrift.protocol.TField类的典型用法代码示例。如果您正苦于以下问题:Java TField类的具体用法?Java TField怎么用?Java TField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TField类属于org.apache.thrift.protocol包,在下文中一共展示了TField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newField
import org.apache.thrift.protocol.TField; //导入依赖的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;
}
示例2: read
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
/**
* 读取操作
*/
@Override
public void read(TProtocol iprot) throws TException {
if (!"org.apache.thrift.scheme.StandardScheme".equals(iprot.getScheme().getName()))
throw new TApplicationException("Service scheme must be 'org.apache.thrift.scheme.StandardScheme' !");
TField schemeField;
iprot.readStructBegin();
while (Boolean.TRUE) {
schemeField = iprot.readFieldBegin();
if (schemeField.type == TType.STOP)
break;
if (schemeField.type == TType.STRING)
str = iprot.readString();
else
throw new TApplicationException("field type must be 'String' !");
iprot.readFieldEnd();
}
iprot.readStructEnd();
}
示例3: writeMessage
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
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();
}
示例4: partialDeserializeSetFieldIdInUnion
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
/**
* Deserialize only the id of the field set in a TUnion (addressed by recursively using field id)
* from a byte record.
* @param bytes The serialized object to read from
* @param fieldIdPathFirst First of the FieldId's that define a path to a TUnion
* @param fieldIdPathRest The rest FieldId's that define a path to a TUnion
* @throws TException
*/
public Short partialDeserializeSetFieldIdInUnion(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum ... fieldIdPathRest) throws TException {
try {
TField field = locateField(bytes, fieldIdPathFirst, fieldIdPathRest);
if (field != null){
protocol_.readStructBegin(); // The Union
return protocol_.readFieldBegin().id; // The field set in the union
}
return null;
} catch (Exception e) {
throw new TException(e);
} finally {
trans_.clear();
protocol_.reset();
}
}
示例5: read
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
@Override
public void read(TProtocol iprot, TUnion struct) throws TException {
struct.setField_ = null;
struct.value_ = null;
iprot.readStructBegin();
TField field = iprot.readFieldBegin();
struct.value_ = struct.standardSchemeReadValue(iprot, field);
if (struct.value_ != null) {
struct.setField_ = struct.enumForId(field.id);
}
iprot.readFieldEnd();
// this is so that we will eat the stop byte. we could put a check here to
// make sure that it actually *is* the stop byte, but it's faster to do it
// this way.
iprot.readFieldBegin();
iprot.readStructEnd();
}
示例6: readFieldBegin
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
@Override
public TField readFieldBegin() throws TException {
if (!getCurrentContext().hasMoreChildren()) {
return new TField("", UNUSED_TYPE, (short) 0);
}
getCurrentContext().read();
JsonNode jsonName = getCurrentContext().getCurrentChild();
if (!jsonName.isTextual()) {
throw new RuntimeException("Expected String for a field name");
}
String fieldName = jsonName.asText();
currentFieldClass.push(getCurrentContext().getClassByFieldName(fieldName));
return getCurrentContext().getTFieldByName(fieldName);
}
示例7: writeFieldBegin
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
@Override
public void writeFieldBegin(TField field) throws TException {
if (field.type == TType.STOP) {
return;
}
try {
currentType = thriftFieldIdToParquetField[field.id];
if (currentType == null) {
throw new ParquetEncodingException("field " + field.id + " was not found in " + thriftType + " and " + schema.getType());
}
final int index = currentType.getIndex();
recordConsumer.startField(currentType.getName(), index);
currentProtocol = children[index];
} catch (ArrayIndexOutOfBoundsException e) {
throw new ParquetEncodingException("field " + field.id + " was not found in " + thriftType + " and " + schema.getType());
}
}
示例8: handleUnrecognizedField
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
private void handleUnrecognizedField(TField field, StructType type, TProtocol in) throws TException {
switch (type.getStructOrUnionType()) {
case STRUCT:
// this is an unrecognized field in a struct, not a union
notifyIgnoredFieldsOfRecord(field);
//read the value and ignore it, NullProtocol will do nothing
new ProtocolReadToWrite().readOneValue(in, new NullProtocol(), field.type);
break;
case UNION:
// this is a union with an unrecognized member -- this is fatal for this record
// in the write path, because it will be unreadable in the read path.
// throwing here means we will either skip this record entirely, or fail completely.
throw new DecodingSchemaMismatchException("Unrecognized union member with id: "
+ field.id + " for struct:\n" + type);
case UNKNOWN:
throw unknownStructOrUnion(type);
default:
throw unrecognizedStructOrUnion(type.getStructOrUnionType());
}
}
示例9: TestExtraFieldWhenFieldIndexIsNotStartFromZero
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
@Test
public void TestExtraFieldWhenFieldIndexIsNotStartFromZero() throws Exception {
CountingErrorHandler countingHandler = new CountingErrorHandler() {
@Override
public void handleFieldIgnored(TField field) {
assertEquals(3, field.id);
fieldIgnoredCount++;
}
};
BufferedProtocolReadToWrite structForRead = new BufferedProtocolReadToWrite(ThriftSchemaConverter.toStructType(StructWithIndexStartsFrom4.class), countingHandler);
//Data has an extra field of type struct
final ByteArrayOutputStream in = new ByteArrayOutputStream();
StructWithExtraField dataWithNewExtraField = new StructWithExtraField(new Phone("111", "222"), new Phone("333", "444"));
dataWithNewExtraField.write(protocol(in));
//read using the schema that doesn't have the extra field
final ByteArrayOutputStream out = new ByteArrayOutputStream();
structForRead.readOne(protocol(new ByteArrayInputStream(in.toByteArray())), protocol(out));
assertEquals(1, countingHandler.recordCountOfMissingFields);
assertEquals(1, countingHandler.fieldIgnoredCount);
}
示例10: after
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args, result, throwable);
}
if (!validate(target)) {
return;
}
final boolean shouldTrace = ((ServerMarkerFlagFieldAccessor)target)._$PINPOINT$_getServerMarkerFlag();
if (shouldTrace) {
InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
Object attachment = currentTransaction.getAttachment();
if (attachment instanceof ThriftClientCallContext) {
ThriftClientCallContext clientCallContext = (ThriftClientCallContext)attachment;
if (result instanceof TField) {
handleClientRequest((TField)result, clientCallContext);
}
}
}
}
示例11: writeTraceHeader
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
public void writeTraceHeader(ThriftHeader headerKey, TProtocol oprot) throws TException {
Object headerValue = this.thriftHeaders.get(headerKey);
if (headerValue == null) {
return;
}
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 pinpoint header type - " + headerType);
}
} finally {
oprot.writeFieldEnd();
}
}
示例12: getTField
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
private TField getTField(Object thriftObject, String fieldName) throws TException {
try {
Map<String, ThriftField> classFields = getClassFields(thriftObject);
ThriftField thriftField = classFields.get(fieldName);
if(thriftField==null) {
// Empty field -> skip
return new TField();
}
byte type = thriftField.fieldMetaData.valueMetaData.type;
short id = thriftField.tfieldIdEnum.getThriftFieldId();
// An enum type is deserialized as an I32
if (TType.ENUM == type) {
type = TType.I32;
}
return new TField("", type, id);
} catch (Exception exp) {
throw new TException("Unexpected getTField fieldName=" + fieldName, exp);
}
}
示例13: write
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
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();
}
示例14: read
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
public void read(TProtocol iprot, TUnion struct) throws TException {
struct.setField_ = null;
struct.value_ = null;
iprot.readStructBegin();
TField field = iprot.readFieldBegin();
struct.value_ = struct.standardSchemeReadValue(iprot, field);
if (struct.value_ != null) {
struct.setField_ = struct.enumForId(field.id);
}
iprot.readFieldEnd();
// this is so that we will eat the stop byte. we could put a check here to
// make sure that it actually *is* the stop byte, but it's faster to do it
// this way.
iprot.readFieldBegin();
iprot.readStructEnd();
}
示例15: write
import org.apache.thrift.protocol.TField; //导入依赖的package包/类
/**
* 写入操作
*/
@Override
public void write(TProtocol oprot) throws TException {
if (!"org.apache.thrift.scheme.StandardScheme".equals(oprot.getScheme().getName()))
throw new TApplicationException("Service scheme must be 'org.apache.thrift.scheme.StandardScheme' !");
oprot.writeStructBegin(getTStruct());
if (str != null) {
oprot.writeFieldBegin(new TField("value", TType.STRING, (short) 0));
oprot.writeString(str);
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}