/**
 * @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.Union;
import org.etsi.ttcn.tci.Type;

public class GeoNetworkingPacket extends Union {

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

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

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

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