private final boolean message_ready ()
    {
        //  Read new message. If there is none, return false.
        //  Note that new state is set only if write is successful. That way
        //  unsuccessful write will cause retry on the next state machine
        //  invocation.
        
        if (msg_source == null)
            return false;
        
        in_progress = msg_source.pull_msg ();
        if (in_progress == null) {
            return false;
        }

        int protocol_flags = 0;
        if (in_progress.has_more ())
            protocol_flags |= V1Protocol.MORE_FLAG;
        if (in_progress.size () > 255)
            protocol_flags |= V1Protocol.LARGE_FLAG;
        tmpbuf [0] = (byte) protocol_flags;
        
        //  Encode the message length. For messages less then 256 bytes,
        //  the length is encoded as 8-bit unsigned integer. For larger
        //  messages, 64-bit unsigned integer in network byte order is used.
        final int size = in_progress.size ();
        if (size > 255) {
            ByteBuffer b = ByteBuffer.wrap (tmpbuf);
            b.position (1);
            b.putLong (size);
            next_step (tmpbuf, 9, size_ready, false);
        }
        else {
            tmpbuf [1] = (byte) (size);
            next_step (tmpbuf, 2, size_ready, false);
        }
        return true;
    }