return new LinkedBuffer(session.nextBufferSize, new LinkedBuffer(value, offset, offset+valueLen, lb)); return new LinkedBuffer(lb, new LinkedBuffer(value, offset, offset+valueLen, lb)); lb = new LinkedBuffer(session.nextBufferSize, lb);
/** Returns the buffer encoded with the tag and LinkedBuffer (zero-copy) */ public static LinkedBuffer writeTagAndLinkedBuffer(int tag, final LinkedBuffer buffer, final WriteSession session, LinkedBuffer lb) { final int valueLen = buffer.offset - buffer.start; if(valueLen == 0) { // write only the tag and delimiter return writeTagAndRawVarInt32(tag, valueLen, session, lb); } lb = writeTagAndRawVarInt32(tag, valueLen, session, lb); // zero copy lb.next = buffer; final int remaining = lb.buffer.length - lb.offset; // if all filled up, return a fresh buffer. return remaining == 0 ? new LinkedBuffer(session.nextBufferSize, buffer) : new LinkedBuffer(lb, buffer); }
/** * Returns the buffer encoded with the variable int 32. */ public static LinkedBuffer writeRawVarInt32(int value, final WriteSession session, LinkedBuffer lb) { final int size = computeRawVarint32Size(value); if(lb.offset + size > lb.buffer.length) lb = new LinkedBuffer(session.nextBufferSize, lb); final byte[] buffer = lb.buffer; int offset = lb.offset; lb.offset += size; session.size += size; if (size == 1) buffer[offset] = (byte)value; else { for (int i = 0, last = size - 1; i < last; i++, value >>>= 7) buffer[offset++] = (byte)((value & 0x7F) | 0x80); buffer[offset] = (byte)value; } return lb; }
/** Returns the buffer encoded with the tag and little endian 64 */ public static LinkedBuffer writeTagAndRawLittleEndian64(int tag, long value, final WriteSession session, LinkedBuffer lb) { final int tagSize = computeRawVarint32Size(tag); final int totalSize = tagSize + LITTLE_ENDIAN_64_SIZE; if(lb.offset + totalSize > lb.buffer.length) lb = new LinkedBuffer(session.nextBufferSize, lb); final byte[] buffer = lb.buffer; int offset = lb.offset; lb.offset += totalSize; session.size += totalSize; if (tagSize == 1) buffer[offset++] = (byte)tag; else { for (int i = 0, last = tagSize - 1; i < last; i++, tag >>>= 7) buffer[offset++] = (byte)((tag & 0x7F) | 0x80); buffer[offset++] = (byte)tag; } writeRawLittleEndian64(value, buffer, offset); return lb; }
/** Returns the buffer encoded with the tag and little endian 32 */ public static LinkedBuffer writeTagAndRawLittleEndian32(int tag, int value, final WriteSession session, LinkedBuffer lb) { final int tagSize = computeRawVarint32Size(tag); final int totalSize = tagSize + LITTLE_ENDIAN_32_SIZE; if(lb.offset + totalSize > lb.buffer.length) lb = new LinkedBuffer(session.nextBufferSize, lb); final byte[] buffer = lb.buffer; int offset = lb.offset; lb.offset += totalSize; session.size += totalSize; if (tagSize == 1) buffer[offset++] = (byte)tag; else { for (int i = 0, last = tagSize - 1; i < last; i++, tag >>>= 7) buffer[offset++] = (byte)((tag & 0x7F) | 0x80); buffer[offset++] = (byte)tag; } writeRawLittleEndian32(value, buffer, offset); return lb; }
lb = new LinkedBuffer(session.nextBufferSize, lb);
lb = new LinkedBuffer(session.nextBufferSize, lb);
/** * Used by the code generated messages that implement {@link java.io.Externalizable}. * Writes to the {@link DataOutput}. * * @return the size of the message. */ public static <T> int writeDelimitedTo(DataOutput out, T message, Schema<T> schema) throws IOException { final LinkedBuffer buffer = new LinkedBuffer(LinkedBuffer.MIN_BUFFER_SIZE); final ProtostuffOutput output = new ProtostuffOutput(buffer); schema.writeTo(output, message); ProtobufOutput.writeRawVarInt32Bytes(out, output.size); LinkedBuffer.writeTo(out, buffer); return output.size; }
final LinkedBuffer nextBuffer = new LinkedBuffer(nextBufferSize); new LinkedBuffer(delimited, 0, delimited.length, lastBuffer).next = nextBuffer; final LinkedBuffer view = new LinkedBuffer(lastBuffer.buffer, lastOffset + 1, lastBuffer.offset); new LinkedBuffer(delimited, 0, delimited.length, lastBuffer).next = view;
/** * Used by the code generated messages that implement {@link java.io.Externalizable}. * Writes to the {@link DataOutput}. * * @return the size of the message. */ public static <T> int writeDelimitedTo(DataOutput out, T message, Schema<T> schema) throws IOException { final LinkedBuffer buffer = new LinkedBuffer(LinkedBuffer.MIN_BUFFER_SIZE); final ProtostuffOutput output = new ProtostuffOutput(buffer); final GraphProtostuffOutput graphOutput = new GraphProtostuffOutput(output); schema.writeTo(graphOutput, message); ProtobufOutput.writeRawVarInt32Bytes(out, output.size); LinkedBuffer.writeTo(out, buffer); return output.size; }
/** * Used by the code generated messages that implement {@link java.io.Externalizable}. * Writes to the {@link DataOutput}. * * @return the size of the message. */ public static <T> int writeDelimitedTo(DataOutput out, T message, Schema<T> schema) throws IOException { final LinkedBuffer buffer = new LinkedBuffer(LinkedBuffer.MIN_BUFFER_SIZE); final ProtobufOutput output = new ProtobufOutput(buffer); schema.writeTo(output, message); final int size = output.getSize(); ProtobufOutput.writeRawVarInt32Bytes(out, size); final int msgSize = LinkedBuffer.writeTo(out, buffer); assert size == msgSize; return size; }