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

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

public class BtpHeader extends Union {

    public BtpHeader(MainCodec mainCodec) {
        super(mainCodec);
        setLengths();
    }

    private void setLengths() {
        mainCodec.setHint("BtpPortIdLen", "16"); 
        mainCodec.setHint("BtpPortInfo", "16"); 
    }
    

    @Override
    protected void preDecode(CodecBuffer buf, Type decodingHypothesis) {

        String nhHint = mainCodec.getHint("GnNextHeader");
        String variant = "btpAHeader";

        if(nhHint != null) {
            int nh = Integer.parseInt(nhHint);
            switch(nh) {
            case 1:
                variant = "btpAHeader";
                break;
            case 2:
                variant = "btpBHeader";
                break;
            default:
                variant = "btpAHeader";
            }
        }
        mainCodec.setHint(decodingHypothesis.getName(), variant);
    }
}
