public int get(byte[] dest) {
	    while(true) {
	        final long s = state.get();
	        final int read = getRead(s);
	        final int write = getWritten(s);
	        final int claim = getClaimed(s);
	        assert read <= write && write <= claim;
	        
	        if (read == write)
	            return 0;
	        
	        System.arraycopy(data, read, dest, 0, write - read);
	        
	        long newState;
	        if (write == claim)
	            newState = 0; // read everything in the buffer
	        else
	            newState = encode(write,claim,write);
	        
	        if (state.compareAndSet(s,newState))
	            return write - read;
	    }
	}