#include "gen_classes.h"
#include "Ports/MessagesIdentifiers.h"

#include <fstream>


/* For debugging with MMAGIC
ofstream myfile;
myfile.open ("C:\\Temp\\logs.txt", ios::out | ios::app );
myfile << "CaptureSource::PreEncodeField: " << field_id << std::endl;
myfile.close();
  */

namespace t3devlib { namespace gen {

  void ImsInterfaceProfile::PreEncodeField (int field_id, Buffer& buffer) throw (EncodeError)
  {
    Charstring value;
    Unsigned fieldLength(2 * 8); // 2 octet length
    switch (field_id) {
      case id_SUTHomeDomain:
        {
          // Set the string length.
          value = Get_SUTHomeDomain();
          std::cout << "ImsInterfaceProfile::PreEncodeField: id_SUTHomeDomain value=" << value << " - " << value.GetLength() / 8 << std::endl;
          fieldLength.SetValue(value.GetLength() / 8);
        }
        break;
      case id_SUTIpaddr:
        {
          value = static_cast<Charstring>(Get_SUTIpaddr());
          std::cout << "ImsInterfaceProfile::PreEncodeField: id_IpAddress value=" << value << " - " << value.GetLength() / 8 << std::endl;
          fieldLength.SetValue(value.GetLength() / 8);
        }
        break;
      case id_SUTPort:
        {
          fieldLength.SetValue(sizeof(t3devlib::Signed));
        }
        break;
      default:
        std::cerr << "ImsInterfaceProfile::PreEncodeField: Non processed field: " << field_id << std::endl;
        return;
    }
    //std::cout << "ImsInterfaceProfile::PreEncodeField: fieldLength " << (int)fieldLength.GetValue() << std::endl;
    fieldLength.Encode(buffer);
  }

}} // namespaces
