package org.etsi.ttcn.tool.elvior.codec;

import org.elvior.ttcn.tritci.TriProvider;
import org.etsi.common.ByteHelper;
import org.etsi.ttcn.tci.Type;
import org.etsi.ttcn.tci.Value;
import org.etsi.ttcn.tri.TriMessage;

/**
 * 
 * Note that "Enable Internal Codec" field shall be set to true
 *
 */
public class LibItsContainer_asn1 extends LibIts_asn1 {
    
    /**
     * Constructor
     */
    public LibItsContainer_asn1() {
        _encodingName = "ITS_Container";
    }
    
    @Override 
    public Value decode(final TriMessage message, final Type decodingHypothesis) {
        
        Value value = null;
        if (decodingHypothesis.getName().equals("TimestampIts")) {
        	int ival = ByteHelper.byteArrayToInt(message.getEncodedMessage());
        	long lval = ((long)ival) << 6;
            TriMessage msg = TriProvider.getInstance().getTriFactory().createMessage();
            msg.setEncodedMessage(ByteHelper.longToByteArray(lval, 6));
            value = super.decode(msg, decodingHypothesis); 
        } else if (decodingHypothesis.getName().equals("TimeMark")) {
            TriMessage msg1 = TriProvider.getInstance().getTriFactory().createMessage();
            msg1.setEncodedMessage(message.getEncodedMessage());
            value = super.decode(msg1, decodingHypothesis); 
        } else {
            value = super.decode(message, decodingHypothesis);
        }
        
        return value;
    }
    
} // End of class LibItsContainer_asn1 
