package org.etsi.ttcn.codec.its.iicp;

import org.etsi.adapter.TERFactory;
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;
import org.etsi.ttcn.tci.Value;

public class IicpMsg extends Union {
    
    public IicpMsg(MainCodec mainCodec) {
        super(mainCodec);
    }
    
    @Override
    public Value decode(CodecBuffer buf, Type decodingHypothesis) {
        
        TERFactory.getInstance().logDebug(String.format("IicpMsg.decode: %s - 0x%02x", decodingHypothesis.getName(), buf.getBytes()[6]));
        String variant = "";
        Byte spRef = buf.getBytes()[6]; // Cf. IIC-Request/IIC-Response data structure description (RequestID field)
        switch (spRef) { 
            case 0x00: // IIC-Request
                variant = "msg_req";
                mainCodec.setHint(decodingHypothesis.getName(), variant);
                break;
            case 0x01: // IIC-Response
                variant = "msg_resp";
                mainCodec.setHint(decodingHypothesis.getName(), variant);
                break;
            default:
                return null;
        } // End of 'switch' statement
        
        return super.decode(buf, decodingHypothesis);
    }

} // End of class IicpMsg 
