public <T> void handleUnknownField(int fieldNumber, Schema<T> schema) throws IOException { final String name = parser.getLocalName(); while(true) { switch(next()) { case END_ELEMENT: if(name.equals(parser.getLocalName())) { // we can skip this unknown scalar field. nextTag(); return; } throw new XmlInputException("Unknown field: " + name + " on message " + schema.messageFullName()); case END_DOCUMENT: // malformed xml. case START_ELEMENT: // message field // we do not know how deep this message is throw new XmlInputException("Unknown field: " + name + " on message " + schema.messageFullName()); } } }
protected Input begin(Pipe.Schema<?> pipeSchema) throws IOException { if(parser.nextToken() != JsonToken.START_OBJECT) { throw new JsonInputException("Expected token: { but was " + parser.getCurrentToken() + " on message " + pipeSchema.wrappedSchema.messageFullName()); } return jsonInput; }
schema.messageFullName()); case END_DOCUMENT: schema.messageFullName());
/** * Returns the serialized size of the entity being modified. */ <T> int casAndIndexCollect(byte[] data, int offset, int len, EntityMetadata<T> em, CAS cas) { final CASAndIndexCollectOutput output = casAndIndexCollectOutput.init(em, cas, data, offset, len); try { em.pipeSchema.writeTo(output, output.pipe); } catch (IOException e) { throw new RuntimeException("Serializing to a LinkedBuffer threw an IOException " + "(should never happen).", e); } // TODO comment out? // this is handled by OverflowHandler final int size = output.getSize(); if(size == -1) { throw DSRuntimeExceptions.invalidArg("Entity too large: " + em.pipeSchema.wrappedSchema.messageFullName()); } return size; }
public <T> void handleUnknownField(int fieldNumber, Schema<T> schema) throws IOException { if(parser.getCurrentToken().isScalarValue()) { // numeric json // we can skip this unknown field if(lastRepeated) { lastRepeated = false; // skip the scalar elements while(parser.nextToken() != END_ARRAY); } return; } throw new JsonInputException("Unknown field: " + (numeric ? fieldNumber : lastName) + " on message " + schema.messageFullName()); }
protected void end(Pipe.Schema<?> pipeSchema, Input input, boolean cleanupOnly) throws IOException { if(cleanupOnly) { parser.close(); return; } assert input == jsonInput; final JsonToken token = parser.getCurrentToken(); parser.close(); if(token != JsonToken.END_OBJECT) { throw new JsonInputException("Expected token: } but was " + token + " on message " + pipeSchema.wrappedSchema.messageFullName()); } } };
/** * Merges the {@code message} from the JsonParser using the given {@code schema}. */ public static <T> void mergeFrom(JsonParser parser, T message, Schema<T> schema, boolean numeric) throws IOException { if(parser.nextToken() != JsonToken.START_OBJECT) { throw new JsonInputException("Expected token: { but was " + parser.getCurrentToken() + " on message " + schema.messageFullName()); } schema.mergeFrom(new JsonInput(parser, numeric), message); if(parser.getCurrentToken() != JsonToken.END_OBJECT) { throw new JsonInputException("Expected token: } but was " + parser.getCurrentToken() + " on message " + schema.messageFullName()); } }
/** * Returns the serialized size of the message. */ private static <T> int serTo(ProtostuffOutput output, T message, Schema<T> schema) { try { schema.writeTo(output, message); if(DSUtils.isBufferOverflow(output)) { throw DSRuntimeExceptions.invalidArg("Entity too large: " + schema.messageFullName()); } return output.getSize(); } catch (IOException e) { throw new RuntimeException("Serializing to a LinkedBuffer threw an IOException " + "(should never happen).", e); } finally { output.clear(); } }
schema.messageFullName()); schema.messageFullName()); schema.messageFullName());
em.pipeSchema.wrappedSchema.messageFullName());
em.pipeSchema.wrappedSchema.messageFullName());
schema.messageFullName()); schema.messageFullName());
parser.getCurrentToken() + " on message " + schema.messageFullName()); schema.messageFullName()); schema.messageFullName());
em.pipeSchema.wrappedSchema.messageFullName());