package com.foxx.androidcast.dev;

import org.junit.Test;

import java.nio.ByteBuffer;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public class StreamDumpWriterTest {

    @Test
    public void lengthPrefixRoundTrip() {
        byte[] payload = new byte[] {1, 2, 3, 4, 5};
        byte[] framed = StreamDumpWriter.encodeLengthPrefixedFrame(payload);
        assertEquals(payload.length, StreamDumpWriter.readLengthPrefix(framed));
        byte[] body = new byte[payload.length];
        System.arraycopy(framed, 4, body, 0, payload.length);
        assertArrayEquals(payload, body);
    }

    @Test
    public void lengthPrefixBigEndian() {
        byte[] framed = StreamDumpWriter.encodeLengthPrefixedFrame(new byte[10]);
        assertEquals(10, ByteBuffer.wrap(framed, 0, 4).getInt());
    }
}
