我是使用 Protostuff 读取/写入数据的团队的一员。这是mergeFrom
从类扩展的Schema
类的方法:
@Override
public void mergeFrom(Input input, Entity entity) throws IOException {
for(int number = input.readFieldNumber(this); ; number = input.readFieldNumber(this))
{
if ( number == 0 ) {
break;
} else if ( number == FIELD_DEFINITION_ID ) {
Schema idmSchema = entity.getSchema();
// Definition id
int definitionId = input.readUInt32();
NodeDefinition defn = idmSchema.getById(definitionId);
if ( defn == null ) {
throw new ProtostuffException("Invalid definition id "+definitionId);
}
Node<?> node = defn.createNode();
entity.add(node);
// Node
readAndCheckFieldNumber(input, FIELD_NODE);
input.mergeObject(node, getSchema(node.getClass()));
} else if ( number == FIELD_CHILD_NODE_STATE ){
//Node state
int intState = input.readInt32();
State state = State.parseState(intState);
readAndCheckFieldNumber(input, FIELD_CHILD_DEFINITION_ID);
int childDefnId = input.readInt32();
Schema schema = entity.getSchema();
NodeDefinition childDefn = schema.getById(childDefnId);
entity.childStates.put(childDefn.getName(), state);
} else {
throw new ProtostuffException("Unexpected field number");
}
}
}
我现在的任务是跳过读取数据,该数据的模式已经被删除。我正在查看接口的handleUnknownField方法Input
。
有没有人已经经历过这个?