static byte[] getBytes(ByteBuffer buffer) {
        int remaining = buffer.remaining();
        if (buffer.hasArray() && buffer.arrayOffset() == 0) {
            // do not copy data if the ByteBuffer is a simple wrapper over an array
            byte[] array = buffer.array();
            if (array.length == remaining) {
                return array;
            }
        }
        buffer.mark();
        byte[] avroEncodedData = new byte[remaining];
        buffer.get(avroEncodedData);
        buffer.reset();
        return avroEncodedData;
    }
@Test
    public void testGetBytesOffsetZeroDifferentLen() {
        byte[] originalArray = {1, 2, 3};
        ByteBuffer wrapped = ByteBuffer.wrap(originalArray, 1, 2);
        assertEquals(0, wrapped.arrayOffset());
        assertEquals(2, wrapped.remaining());
        byte[] result = ByteBufferSchemaWrapper.getBytes(wrapped);
        assertNotSame(result, originalArray);
        assertArrayEquals(result, new byte[] {2,3});
    }