static void verify(int field, Schema<?> schema) { if(field < 3 || field > 127) { throw new IllegalArgumentException( "The indexed fields must be 3-127. (" + field + " on " + schema.messageName() + ")"); } if(null == schema.getFieldName(field)) { throw new IllegalArgumentException("The field: " + field + " does not exist for " + schema.messageName()); } }
/** * Serializes the {@code message} into an {@link XMLStreamWriter} * using the given {@code schema}. */ public static <T> void writeTo(XMLStreamWriter writer, T message, Schema<T> schema) throws IOException, XMLStreamException, XmlOutputException { writer.writeStartElement(schema.messageName()); schema.writeTo(new XmlOutput(writer, schema), message); writer.writeEndElement(); }
protected Input begin(Pipe.Schema<?> pipeSchema) throws IOException { //final String simpleName = pipeSchema.wrappedSchema.messageName(); try { if(parser.nextTag() != START_ELEMENT || !pipeSchema.wrappedSchema.messageName().equals(parser.getLocalName())) { throw new XmlInputException("Expected token START_ELEMENT: " + pipeSchema.wrappedSchema.messageName()); } if(parser.nextTag() == END_ELEMENT) { //if(!simpleName.equals(parser.getLocalName())) // throw new XmlInputException("Expecting token END_ELEMENT: " + // simpleName); // empty message; return null; } } catch(XMLStreamException e) { throw new XmlInputException(e); } return xmlInput; }
/** * Serializes the {@code messages} into the {@link XMLStreamWriter} using the given schema. */ public static <T> void writeListTo(XMLStreamWriter writer, List<T> messages, Schema<T> schema) throws IOException, XMLStreamException { writer.writeStartElement("list"); if(messages.isEmpty()) { writer.writeEndElement(); return; } final String simpleName = schema.messageName(); final XmlOutput output = new XmlOutput(writer, schema); for(T m : messages) { writer.writeStartElement(simpleName); schema.writeTo(output, m); writer.writeEndElement(); } writer.writeEndElement(); }
public static RuntimeException failureOnCompare(Pipe.Schema<?> ps, int fieldNumber) { return new Operation("CAS failed on " + ps.wrappedSchema.messageName() + "::" + ps.wrappedSchema.getFieldName(fieldNumber)); }
/** * Merges the {@code message} from the {@link XMLStreamReader} * using the given {@code schema}. */ public static <T> void mergeFrom(XMLStreamReader parser, T message, Schema<T> schema) throws IOException, XMLStreamException, XmlInputException { //final String simpleName = schema.messageName(); if(parser.nextTag() != START_ELEMENT || !schema.messageName().equals(parser.getLocalName())) { throw new XmlInputException("Expected token START_ELEMENT: " + schema.messageName()); } if(parser.nextTag() == END_ELEMENT) { //if(!simpleName.equals(parser.getLocalName())) // throw new XmlInputException("Expecting token END_ELEMENT: " + simpleName); // empty message; return; } schema.mergeFrom(new XmlInput(parser), message); //if(!simpleName.equals(parser.getLocalName())) // throw new XmlInputException("Expecting token END_ELEMENT: " + simpleName); }
public static RuntimeException failureOnValidate(Pipe.Schema<?> ps, int fieldNumber) { return new Validation("Validation failed on " + ps.wrappedSchema.messageName() + "::" + ps.wrappedSchema.getFieldName(fieldNumber)); }
public static RuntimeException invalidOneByteValue(Pipe.Schema<?> ps, int fieldNumber) { return new Validation("Validation failed on " + ps.wrappedSchema.messageName() + "::" + ps.wrappedSchema.getFieldName(fieldNumber) + " (Invalid one-byte value)"); }
if(tag != START_ELEMENT || !schema.messageName().equals(parser.getLocalName())) throw new XmlInputException("Expected token START_ELEMENT: " + schema.messageName());
schema.messageName(), false, output.sink,
schema.messageName(), false, output.sink,
/** * Serializes the {@code message} into an {@link OutputStream} * with the supplied buffer. * * @return the total bytes written to the output. */ public static <T> int writeTo(OutputStream out, T message, Schema<T> schema, LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final YamlOutput output = new YamlOutput(buffer, out, schema); output.tail = YamlOutput.writeTag( schema.messageName(), false, output.sink, output, output.sink.writeByteArray( START_DIRECTIVE, output, buffer)); schema.writeTo(output, message); LinkedBuffer.writeTo(out, buffer); return output.getSize(); }
/** * Serializes the {@code message} into a {@link WriteSession}. * * @return the total bytes written to the output. */ public static <T> int writeTo(WriteSession session, T message, Schema<T> schema) throws IOException { final int size = session.size; final YamlOutput output = new YamlOutput(session.head, session.out, schema); output.size = size; output.tail = YamlOutput.writeTag( schema.messageName(), false, output.sink, output, output.sink.writeByteArray( START_DIRECTIVE, output, output.tail)); schema.writeTo(output, message); return output.getSize() - size; }
public RpcResponse newRpcResponse(final Schema<?> schema, WriteContext context, RpcHeader header, RpcProtocol protocol, final RpcWorker worker, WriteSession session) throws IOException { final YamlOutput output = this.output; response.worker.currentOutput = output; output.use(schema).reset(); output.size = session.size; protocol.writeHeader(RpcError.NONE, header, this, worker, output); output.tail = YamlOutput.writeTag( schema.messageName(), false, output.sink, output, output.sink.writeByteArray( YAML_START_DIRECTIVE, output, output.tail)); return response; }
schema.messageName(), true, output.sink,
public <T> RpcError writeError(RpcError error, T message, Schema<T> schema, RpcHeader header, RpcProtocol protocol, RpcWorker worker, WriteSession session) throws IOException { final YamlOutput output = this.output; response.worker.currentOutput = output; output.use(schema).reset(); output.size = session.size; protocol.writeHeader(error, header, this, worker, output); output.tail = YamlOutput.writeTag( schema.messageName(), false, output.sink, output, output.sink.writeByteArray( YAML_START_DIRECTIVE, output, output.tail)); schema.writeTo(output, message); return error; }
final String name = schema.messageName(); try
schema.messageName(), true, output.sink,
final String name = schema.messageName(); try
final String name = schema.messageName();