package com.lingniu.ingest.protocol.jt808.codec;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class Jt808EscapeTest {

    @Test
    void roundTrip() {
        byte[] raw = {0x30, 0x7e, 0x08, 0x7d, (byte) 0xFF};
        byte[] escaped = Jt808Escape.escape(raw);
        assertThat(escaped).containsExactly(0x30, 0x7d, 0x02, 0x08, 0x7d, 0x01, 0xFF);

        byte[] back = Jt808Escape.unescape(escaped, 0, escaped.length);
        assertThat(back).containsExactly(raw[0], raw[1], raw[2], raw[3], raw[4]);
    }

    @Test
    void noEscapeNeeded() {
        byte[] raw = {0x01, 0x02, 0x03};
        assertThat(Jt808Escape.escape(raw)).containsExactly(0x01, 0x02, 0x03);
        assertThat(Jt808Escape.unescape(raw, 0, raw.length)).containsExactly(0x01, 0x02, 0x03);
    }
}
