@Override public void writeFloat(int fieldNumber, float value, boolean repeated) throws IOException { // TODO optimize final String str = Float.toString(value); tail = sink.writeStrAscii( str, this, writeField( fieldNumber, str.length(), tail)); }
@Override public void writeDouble(int fieldNumber, double value, boolean repeated) throws IOException { // TODO optimize final String str = Double.toString(value); tail = sink.writeStrAscii( str, this, writeField( fieldNumber, str.length(), tail)); }
static LinkedBuffer writeTag(final String name, final boolean repeated, final WriteSink sink, final WriteSession session, LinkedBuffer lb) throws IOException { lb = sink.writeStrAscii(name, session, sink.writeByte( EXCLAMATION, session, lb)); if (repeated) return sink.writeByteArray(EMPTY_ARRAY, session, lb); return lb; }
private void writeB64(String name, byte[] value, int offset, int length, boolean repeated) throws IOException { tail = sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByteArray(START_SLASH_TAG, this, sink.writeByteArrayB64(value, offset, length, this, sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByte(START_TAG, this, tail))))))); }
@Override public void writeBool(int fieldNumber, boolean value, boolean repeated) throws IOException { final String name = schema.getFieldName(fieldNumber); tail = sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByteArray(START_SLASH_TAG, this, sink.writeByteArray(value ? TRUE : FALSE, this, sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByte(START_TAG, this, tail))))))); }
@Override public void writeInt32(int fieldNumber, int value, boolean repeated) throws IOException { final String name = schema.getFieldName(fieldNumber); tail = sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByteArray(START_SLASH_TAG, this, sink.writeStrFromInt(value, this, sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByte(START_TAG, this, tail))))))); }
@Override public void writeInt64(int fieldNumber, long value, boolean repeated) throws IOException { final String name = schema.getFieldName(fieldNumber); tail = sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByteArray(START_SLASH_TAG, this, sink.writeStrFromLong(value, this, sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByte(START_TAG, this, tail))))))); }
@Override public void writeFloat(int fieldNumber, float value, boolean repeated) throws IOException { final String name = schema.getFieldName(fieldNumber); tail = sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByteArray(START_SLASH_TAG, this, sink.writeStrFromFloat(value, this, sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByte(START_TAG, this, tail))))))); }
@Override public void writeDouble(int fieldNumber, double value, boolean repeated) throws IOException { final String name = schema.getFieldName(fieldNumber); tail = sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByteArray(START_SLASH_TAG, this, sink.writeStrFromDouble(value, this, sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByte(START_TAG, this, tail))))))); }
@Override public void writeString(int fieldNumber, CharSequence value, boolean repeated) throws IOException { final String name = schema.getFieldName(fieldNumber); tail = sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByteArray(START_SLASH_TAG, this, sink.writeStrUTF8(value, this, sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByte(START_TAG, this, tail))))))); }
@Override public <T> void writeObject(int fieldNumber, T value, Schema<T> schema, boolean repeated) throws IOException { final Schema<?> lastSchema = this.schema; this.schema = schema; final String name = lastSchema.getFieldName(fieldNumber); // start tag tail = sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByte(START_TAG, this, tail))); schema.writeTo(this, value); // end tag tail = sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByteArray(START_SLASH_TAG, this, tail))); // restore state this.schema = lastSchema; }
output.sink.writeStrAscii(name, output, output.sink.writeByte(XmlXOutput.START_TAG, output, output.sink.writeByteArray(HEADER, output, output.tail)))); output.sink.writeStrAscii(name, output, output.sink.writeByteArray(XmlXOutput.START_SLASH_TAG, output, output.tail)));
@Override public void writeByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated) throws IOException { if (!utf8String) { // B64 encode writeB64(schema.getFieldName(fieldNumber), value, offset, length, repeated); return; } // write direct final String name = schema.getFieldName(fieldNumber); tail = sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByteArray(START_SLASH_TAG, this, sink.writeByteArray(value, offset, length, this, sink.writeByte(END_TAG, this, sink.writeStrAscii(name, this, sink.writeByte(START_TAG, this, tail))))))); }
output.sink.writeStrAscii(name, output, output.sink.writeByte(XmlXOutput.START_TAG, output, output.sink.writeByteArray(HEADER, output, output.tail)))); output.sink.writeStrAscii(name, output, output.sink.writeByteArray(XmlXOutput.START_SLASH_TAG, output, output.tail)));
/** * 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; }
private static LinkedBuffer writeKey(final String name, final int indent, final boolean repeated, final WriteSink sink, final WriteSession session, LinkedBuffer lb) throws IOException { lb = sink.writeByteArray( COLON_AND_SPACE, session, sink.writeStrAscii( name, session, newLine( indent, sink, session, lb))); if (repeated) { return sink.writeByteArray( DASH_AND_SPACE, session, newLine( inc(indent, 2), sink, session, lb)); } return lb; }
keySuffix, this, sink.writeStrAscii( schema.getFieldName(fieldNumber), this, keySuffix, this, sink.writeStrAscii( schema.getFieldName(fieldNumber), this, keySuffix, this, sink.writeStrAscii( schema.getFieldName(fieldNumber), this,
keySuffix, this, sink.writeStrAscii( schema.getFieldName(fieldNumber), this, keySuffix, this, sink.writeStrAscii( schema.getFieldName(fieldNumber), this, keySuffix, this, sink.writeStrAscii( schema.getFieldName(fieldNumber), this,