/**
 * @author      ETSI / STF462 / Alexandre Berge
 * @version     $URL: $
 *              $Id: $
 */
package org.etsi.ttcn.codec.its.geonetworking;

import org.etsi.ttcn.codec.CodecBuffer;
import org.etsi.ttcn.codec.MainCodec;
import org.etsi.ttcn.codec.generic.Record;
import org.etsi.ttcn.tci.RecordValue;
import org.etsi.ttcn.tci.Type;

public class GnIndReq extends Record {

    public GnIndReq(MainCodec mainCodec) {
        super(mainCodec);
    }

    @Override
    protected void preDecodeField(String fieldName, CodecBuffer buf, Type decodingHypothesis, RecordValue rv) {

        if(fieldName.equals("macDestinationAddress")) {
            buf.overwriteWith(macBuffer);
        }
        else {
            buf.overwriteWith(messageBuffer);
        }
    }

    @Override
    protected void preDecode(CodecBuffer buf, Type decodingHypothesis) {
        int msgLen = buf.getNbBits() - 48;
        
        messageBuffer = buf.getBuffer(0, msgLen);
        macBuffer = buf.getBuffer(msgLen, 48);
    }
    
    private CodecBuffer messageBuffer = null;
    private CodecBuffer macBuffer = null;
}
