// Generated on 2011 June Thu, 30 at 03:18:25 by the CERTI message generator
#include "addressbook.h"
// The generated file will be put in 
// the MsgTutorial package
package MsgTutorial 

   nmsg_create(nmsg_t* cthis) {
      //type= <no default value in message spec using builtin>
      //messageName= <no default value in message spec using builtin>
   }
   void nmsg_destroy(nmsg_t* cthis) {
      free(cthis);
   }

   void nmsg_serialize(MsgBuffer_t* msgBuffer) {
      //Specific serialization code
      MB_write_uint32(msgBuffer,type);
      MB_write_string(msgBuffer,messageName);
   }

   void nmsg_deserialize(MsgBuffer_t* msgBuffer) {
      //Specific deserialization code
      type = MB_read_uint32(msgBuffer);
      MB_read_string(msgBuffer,messageName);
   }

   FILE* nmsg_show(FILE* out) {
      fprintf(out,"[nmsg -Begin] \n");
      fflush(out);      //Specific show code
      fprintf(out," type = " + type + " "        + "\n");
      fflush(out);
      fprintf(out," messageName = " + messageName + " "        + "\n");
      fflush(out);
      fprintf(out,"[nmsg -End] \n");
      fflush(out);
      return out;
   }

   PhoneNumber_create(PhoneNumber_t* cthis) {
      //number= <no default value in message spec using builtin>
      _hasType=0;
      //type= <no default value in message spec using builtin>
   }
   void PhoneNumber_destroy(PhoneNumber_t* cthis) {
      free(cthis);
   }

   void PhoneNumber_serialize(MsgBuffer_t* msgBuffer) {
      //Specific serialization code
      MB_write_string(msgBuffer,number);
      MB_write_bool(msgBuffer,_hasType);
      if (_hasType) {
         MB_write_uint32(msgBuffertype);
      }
   }

   void PhoneNumber_deserialize(MsgBuffer_t* msgBuffer) {
      //Specific deserialization code
      MB_read_string(msgBuffer,number);
      _hasType = MB_read_bool(msgBuffer);
      if (_hasType) {
         type = static_cast<addressbook_PhoneType>(MB_read_uint32 ());
      }
   }

   FILE* PhoneNumber_show(FILE* out) {
      fprintf(out,"[PhoneNumber -Begin] \n");
      fflush(out);      //Specific show code
      fprintf(out," number = " + number + " "        + "\n");
      fflush(out);
      fprintf(out,"(opt) type =" + type + " "       + "\n");
      fflush(out)
      fprintf(out,"[PhoneNumber -End] \n");
      fflush(out);
      return out;
   }

   Person_create(Person_t* cthis) {
      char* temp;
       temp = malloc(sizeof(char)*strlen("Person")));
      strcpy(temp,"Person");
      cthis->super->messageName = temp; 
      cthis->super->type = PERSON;
      //name= <no default value in message spec using builtin>
      //id= <no default value in message spec using builtin>
      _hasEmail=0;
      //email= <no default value in message spec using builtin>
      //phone= <no default value in message spec using builtin>
   }
   void Person_destroy(Person_t* cthis) {
      free(cthis);
   }

   void Person_serialize(MsgBuffer_t* msgBuffer) {
      //Call mother class
      Super_serialize(msgBuffer);
      //Specific serialization code
      MB_write_string(msgBuffer,name);
      MB_write_int32(msgBuffer,id);
      MB_write_bool(msgBuffer,_hasEmail);
      if (_hasEmail) {
         MB_write_string(msgBuffer,email);
      }
      uint32_t phoneSize = phonesize;
      MB_write_uint32(msgBuffer,phoneSize);
      for (uint32_t i = 0; i < phoneSize; ++i) {
         phone[i]_serialize(msgBuffer);
      }
   }

   void Person_deserialize(MsgBuffer_t* msgBuffer) {
      //Call mother class
      Super_deserialize(msgBuffer);
      //Specific deserialization code
      MB_read_string(msgBuffer,name);
      id = MB_read_int32(msgBuffer);
      _hasEmail = MB_read_bool(msgBuffer);
      if (_hasEmail) {
         MB_read_string(msgBuffer,email);
      }
      uint32_t phoneSize = MB_read_uint32(msgBuffer);
      phonesize =phoneSize);
      for (uint32_t i = 0; i < phoneSize; ++i) {
         phone[i]_deserialize(msgBuffer);
      }
   }

   FILE* Person_show(FILE* out) {
      fprintf(out,"[Person -Begin] \n");
      fflush(out);      //Call mother class
      Super_show(out);
      //Specific show code
      fprintf(out," name = " + name + " "        + "\n");
      fflush(out);
      fprintf(out," id = " + id + " "        + "\n");
      fflush(out);
      fprintf(out,"(opt) email =" + email + " "       + "\n");
      fflush(out)
      fprintf(out,"    phone [] = 
");
fflush(out);
      for (uint32_t i = 0; i < getPhoneSize(); ++i) {
         out phone[i].show(out);
      }
      fprintf(out,"\n");
      fflush(out);
      fprintf(out,"[Person -End] \n");
      fflush(out);
      return out;
   }

   AddressBook_create(AddressBook_t* cthis) {
      char* temp;
       temp = malloc(sizeof(char)*strlen("AddressBook")));
      strcpy(temp,"AddressBook");
      cthis->super->messageName = temp; 
      cthis->super->type = ADDRESSBOOK;
      //person= <no default value in message spec using builtin>
   }
   void AddressBook_destroy(AddressBook_t* cthis) {
      free(cthis);
   }

   void AddressBook_serialize(MsgBuffer_t* msgBuffer) {
      //Call mother class
      Super_serialize(msgBuffer);
      //Specific serialization code
      uint32_t personSize = personsize;
      MB_write_uint32(msgBuffer,personSize);
      for (uint32_t i = 0; i < personSize; ++i) {
         person[i]_serialize(msgBuffer);
      }
   }

   void AddressBook_deserialize(MsgBuffer_t* msgBuffer) {
      //Call mother class
      Super_deserialize(msgBuffer);
      //Specific deserialization code
      uint32_t personSize = MB_read_uint32(msgBuffer);
      personsize =personSize);
      for (uint32_t i = 0; i < personSize; ++i) {
         person[i]_deserialize(msgBuffer);
      }
   }

   FILE* AddressBook_show(FILE* out) {
      fprintf(out,"[AddressBook -Begin] \n");
      fflush(out);      //Call mother class
      Super_show(out);
      //Specific show code
      fprintf(out,"    person [] = 
");
fflush(out);
      for (uint32_t i = 0; i < getPersonSize(); ++i) {
         out person[i].show(out);
      }
      fprintf(out,"\n");
      fflush(out);
      fprintf(out,"[AddressBook -End] \n");
      fflush(out);
      return out;
   }

   nmsg* M_Factory_create(M_Type type) throw (string) { 
      nmsg* msg = NULL;

      switch (type) {
         case nmsg_NOT_USED:
            throw string("NOT_USED message type should not be used!!");
            break;
         case nmsg_PERSON:
            msg = new Person();
            break;
         case nmsg_ADDRESSBOOK:
            msg = new AddressBook();
            break;
         case nmsg_LAST:
            throw string("LAST message type should not be used!!");
            break;
      } // end if switch (type)
      return msg;
   } /* end of M_Factory_create */

} // end of namespace MsgTutorial 
