public LinkedBuffer packBytes(byte[] src, int offset, int length, WriteSession session, LinkedBuffer lb) throws IOException { return sink.writeByteArray(src, offset, length, session, 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))))))); }
JsonXOutput writeCommaAndStartObject() throws IOException { tail = sink.writeByteArray(COMMA_AND_START_OBJECT, this, tail); return this; }
public abstract LinkedBuffer writeByteArray(final byte[] value, final int offset, final int length, final WriteSession session, final LinkedBuffer lb) throws IOException;
@Override public void writeByteArray(int fieldNumber, byte[] value, boolean repeated) throws IOException { tail = sink.writeByteArray( value, this, writeField( fieldNumber, value.length, tail)); }
@Override public void writeByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated) throws IOException { tail = sink.writeByteArray( value, offset, length, this, writeField( fieldNumber, length, tail)); }
YamlOutput writeSequenceDelim() throws IOException { tail = sink.writeByteArray( DASH_AND_SPACE, this, newLine( indent, sink, this, tail)); indent = inc(indent, 2); return this; }
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; }
@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 writeByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated) throws IOException { tail = sink.writeByteArray( value, offset, length, this, sink.writeVarInt32( length, this, sink.writeVarInt32( makeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED), this, tail))); }
@Override public void writeByteArray(int fieldNumber, byte[] bytes, boolean repeated) throws IOException { tail = sink.writeByteArray( bytes, 0, bytes.length, this, sink.writeVarInt32( bytes.length, this, sink.writeVarInt32( makeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED), this, tail))); /* * tail = writeTagAndByteArray( makeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED), bytes, this, 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))))))); }
private LinkedBuffer writeField(final int number, final LinkedBuffer lb) throws IOException { if (numeric) { final int len = stringSize(number); numBuf[0] = (byte) len; numBuf[1] = (byte) ((len >>> 8) & 0xFF); return sink.writeStrFromInt( number, this, sink.writeByteArray( numBuf, 0, 2, this, lb)); } return sink.writeStrUTF8FixedDelimited( schema.getFieldName(number), true, this, lb); }
/** * 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; }
@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 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 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; }