Package org.msgpack.core.buffer

Examples of org.msgpack.core.buffer.MessageBuffer


                    String s = v.get().asString().toString();
                    System.out.println("read string: " + s);
                    break;
                case BINARY:
                    // Message buffer is an efficient byte buffer
                    MessageBuffer mb = v.get().asBinary().toMessageBuffer();
                    System.out.println("read binary: " + mb.toHexString(0, mb.size()));
                    break;
                case ARRAY:
                    ArrayValue arr = v.get().asArrayValue();
                    for(ValueRef a : arr) {
                        System.out.println("read array element: " + a);
View Full Code Here


        encodeBuffer.flip();
        int strLen = encodeBuffer.remaining();

        // Preserve the current buffer
        MessageBuffer tmpBuf = buffer;

        // Switch the buffer to write the string length
        if(strLenBuffer == null) {
            strLenBuffer = MessageBuffer.newBuffer(5);
        }
View Full Code Here

            // First, flush the current buffer contents
            flush();

            // Wrap the input source as a MessageBuffer
            MessageBuffer wrapped = MessageBuffer.wrap(src).slice(src.position(), src.remaining());
            // Then, dump the source data to the output
            out.flush(wrapped);
            src.position(src.limit());
        }
        else {
View Full Code Here

            // Flush the current buffer contents
            flush();

            // Wrap the input array as a MessageBuffer
            MessageBuffer wrapped = MessageBuffer.wrap(src).slice(off, len);
            // Dump the source data to the output
            out.flush(wrapped);
        }
        else {
            int cursor = 0;
View Full Code Here

    private MessageBuffer takeNextBuffer() throws IOException {
        if(reachedEOF)
            return null;

        MessageBuffer nextBuffer = null;
        if(secondaryBuffer == null) {
            nextBuffer = in.next();
        }
        else {
            nextBuffer = secondaryBuffer;
View Full Code Here

                                 |-------|---------- secondary buffer (slice) ----------------|

             */

        // If the byte size to read fits within the extra buffer, use the extraBuffer
        MessageBuffer newBuffer = byteSizeToRead <= extraBuffer.size() ? extraBuffer : MessageBuffer.newBuffer(byteSizeToRead);

        // Copy the remaining buffer contents to the new buffer
        int firstHalfSize = buffer.size() - position;
        if(firstHalfSize > 0)
            buffer.copyTo(position, newBuffer, 0, firstHalfSize);

        // Read the last half contents from the next buffers
        int cursor = firstHalfSize;
        while(cursor < byteSizeToRead) {
            secondaryBuffer = takeNextBuffer();
            if(secondaryBuffer == null)
                return false; // No more buffer to read

            // Copy the contents from the secondary buffer to the new buffer
            int copyLen = Math.min(byteSizeToRead - cursor, secondaryBuffer.size());
            secondaryBuffer.copyTo(0, newBuffer, cursor, copyLen);

            // Truncate the copied part from the secondaryBuffer
            secondaryBuffer = copyLen == secondaryBuffer.size() ? null : secondaryBuffer.slice(copyLen, secondaryBuffer.size()-copyLen);
            cursor += copyLen;
        }

        // Replace the current buffer with the new buffer
        totalReadBytes += position;
        buffer = byteSizeToRead == newBuffer.size() ? newBuffer : newBuffer.slice(0, byteSizeToRead);
        position = 0;

        return true;
    }
View Full Code Here

    public MessageBuffer readPayloadAsReference(int length) throws IOException {
        checkArgument(length >= 0);
        if(!ensure(length))
            throw new EOFException();

        MessageBuffer ref = buffer.slice(position, length);
        position += length;
        return ref;
    }
View Full Code Here

TOP

Related Classes of org.msgpack.core.buffer.MessageBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.