@Override public String messageName() { return wrappedSchema.messageName(); }
@Override public String messageName() { return 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(); }
@Override 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(); }
/** * 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); }
if (tag != START_ELEMENT || !schema.messageName().equals(parser.getLocalName())) throw new XmlInputException("Expected token START_ELEMENT: " + schema.messageName());
/** * Serializes the {@code message} into a byte array with the supplied buffer. */ public static <T> byte[] toByteArray(T message, Schema<T> schema, LinkedBuffer buffer) { if (buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final YamlOutput output = new YamlOutput(buffer, schema); try { output.tail = YamlOutput.writeTag( schema.messageName(), false, output.sink, output, output.sink.writeByteArray( START_DIRECTIVE, output, buffer)); schema.writeTo(output, message); } catch (IOException e) { throw new RuntimeException("Serializing to a byte array threw an IOException " + "(should never happen).", e); } return output.toByteArray(); }
/** * Serializes the {@code message} into the {@link LinkedBuffer}. * * @return the total bytes written to the output. */ public static <T> int writeTo(LinkedBuffer buffer, T message, Schema<T> schema) { if (buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final YamlOutput output = new YamlOutput(buffer, schema); try { output.tail = YamlOutput.writeTag( schema.messageName(), false, output.sink, output, output.sink.writeByteArray( START_DIRECTIVE, output, buffer)); schema.writeTo(output, message); } catch (IOException e) { throw new RuntimeException("Serializing to a LinkedBuffer threw an IOException " + "(should never happen).", e); } return output.getSize(); }
/** * 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(); }
schema.messageName(), true, output.sink,
final String name = schema.messageName(); try
final String name = schema.messageName(); try
/** * Serializes the {@code messages} into an {@link OutputStream} using the given schema with the supplied buffer. * * @return the total bytes written to the output. */ public static <T> int writeListTo(OutputStream out, List<T> messages, 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(), true, output.sink, output, output.sink.writeByteArray( START_DIRECTIVE, output, buffer)); for (T m : messages) { schema.writeTo(output.writeSequenceDelim(), m); output.reset(); } LinkedBuffer.writeTo(out, buffer); return output.getSize(); }
/** * Serializes the {@code message} into an {@link OutputStream} using the given schema. * * @return the size of the message */ public static <T> int writeTo(final OutputStream out, final T message, final Schema<T> schema, final LinkedBuffer buffer) throws IOException { if (buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final XmlXOutput output = new XmlXOutput(buffer, out, schema); final String name = schema.messageName(); // header and start root element output.tail = output.sink.writeByte(XmlXOutput.END_TAG, output, output.sink.writeStrAscii(name, output, output.sink.writeByte(XmlXOutput.START_TAG, output, output.sink.writeByteArray(HEADER, output, output.tail)))); schema.writeTo(output, message); // end root element output.tail = output.sink.writeByte(XmlXOutput.END_TAG, output, output.sink.writeStrAscii(name, output, output.sink.writeByteArray(XmlXOutput.START_SLASH_TAG, output, output.tail))); LinkedBuffer.writeTo(out, buffer); return output.size; }
schema.messageName(), repeated, sink,