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

import com.lingniu.ingest.protocol.jt808.codec.BodyParser;
import com.lingniu.ingest.protocol.jt808.model.Jt808Body;
import com.lingniu.ingest.protocol.jt808.model.Jt808Header;
import com.lingniu.ingest.protocol.jt808.model.Jt808MessageId;

import java.nio.ByteBuffer;

public final class PassthroughBodyParser implements BodyParser {

    @Override
    public int messageId() {
        return Jt808MessageId.TERMINAL_PASSTHROUGH;
    }

    @Override
    public Jt808Body parse(Jt808Header header, ByteBuffer body) {
        int type = body.hasRemaining() ? body.get() & 0xFF : 0;
        byte[] data = new byte[body.remaining()];
        body.get(data);
        return new Jt808Body.Passthrough(type, data);
    }
}
