I am part of a team that use Protostuff to read/write data.
This is the mergeFrom
method of a class extends from a Schema
class:
@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");
}
}
}
My current task is now to skipp reading the data, where the schema of that data is already deleted. I am looking at handleUnknownField method of Input
interface.
Is there any one had already experienced with this?