context: //  =========================================================================
  //    ZreMsgOriginal - work with ZRE messages - as generated by ZProt
  //
  //    Codec class for ZreMsgOriginal.
  //
  //    ** WARNING *************************************************************
  //    THIS SOURCE FILE IS 100% GENERATED. If you edit this file, you will lose
  //    your changes at the next build cycle. This is great for temporary printf
  //    statements. DO NOT MAKE ANY CHANGES YOU WISH TO KEEP. The correct places
  //    for commits are:
  //
  //     * The XML model used for this code generation: zre_msg.xml, or
  //     * The code generation script that built this file: zproto_codec_cs
  //    ************************************************************************
  //    =========================================================================
  
  using System;
  using System.Collections.Generic;
  using System.Text;
  using NetMQ;
  using NetMQ.Sockets;
  using NetMQ.zmq;
  #pragma warning disable 168
  
  // ReSharper disable once CheckNamespace
  namespace NetMQ.Zyre
  {
  	/// <summary>
  	/// work with ZRE messages - as generated by ZProt
  	/// </summary>
  	public class ZreMsgOriginal
  	{
  		public class MessageException : Exception
  		{
  			public MessageException(string message) : base(message)
  			{
  			}
  		}
  
  		public enum MessageId
  		{
  			Hello = 1,
  			Whisper = 2,
  			Shout = 3,
  			Join = 4,
  			Leave = 5,
  			Ping = 6,
  			PingOk = 7,
  		}
  		
  		#region Hello
  
  		public class HelloMessage
  		{
  			public HelloMessage()
  			{
  			}			
  
  			/// <summary>
  			/// Get/Set the Version field
  			/// </summary>
  			public byte Version
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// Get/Set the Sequence field
  			/// </summary>
  			public UInt16 Sequence
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// Get/Set the Endpoint field
  			/// </summary>
  			public string Endpoint
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// /// Get/Set the Groups list
  			/// </summary>
  			public List<string> Groups
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// Get/Set the Status field
  			/// </summary>
  			public byte Status
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// Get/Set the Name field
  			/// </summary>
  			public string Name
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// Get/Set the Headers dictionary
  			/// </summary>
  			public Dictionary<string, string> Headers
  			{
  				get;set;
  			}
  
  
  			internal int GetFrameSize()
  			{
  				int frameSize = 0;
  
  				//  Version
  				frameSize += 1;          
  
  				//  Sequence
  				frameSize += 2;          
  
  				//  Endpoint
  				frameSize += 1 + Endpoint.Length;
  
  				//  Groups
  				frameSize += 4;            //  Size is 4 octets
  				if (Groups != null) 
  				{
  					foreach(string s in Groups)
  					{
  						frameSize += 4 + s.Length;
  					}                
  				}
  
  				//  Status
  				frameSize += 1;          
  
  				//  Name
  				frameSize += 1 + Name.Length;
  
  				//  Headers
  				frameSize += 4;            //  Size is 4 octets
  				if (Headers != null) 
  				{                
  					int headersSize = 0;
  
  					foreach (var pair in Headers)
  					{
  						headersSize += 1 + pair.Key.Length;
  						headersSize += 4 + pair.Value.Length;
  					}
  
  					frameSize += headersSize;
  				}
              
  
  				return frameSize;
  			}		
  
  			internal void Write(ZreMsgOriginal m)
  			{
  				// Version
  				m.PutNumber1(2); // Version
  
  				// Sequence
  				m.PutNumber2(Sequence);
  
  				// Endpoint
  				m.PutString(Endpoint);
  
  				// Groups
  				if (Groups != null) 
  				{
  					m.PutNumber4((UInt32)Groups.Count);
  
  					foreach (string s in Groups)
  					{
  						m.PutLongString(s);
  					}                
  				}
  				else
  					m.PutNumber4(0);    //  Empty string array
  
  				// Status
  				m.PutNumber1(Status);
  
  				// Name
  				m.PutString(Name);
  
  				// Headers
  				if (Headers != null) 
  				{
  					m.PutNumber4((UInt32)Headers.Count);
                 
  					foreach(var pair in Headers)
  					{
  						m.PutString(pair.Key);
  						m.PutLongString(pair.Value);
  					}				
  				}
  				else
  					m.PutNumber4(0);    //  Empty dictionary
  
  			}
  
  			internal void Read(ZreMsgOriginal m)
  			{
  				int listSize;
  				int hashSize;
  				int chunkSize;
  				byte[] guidBytes;
  				byte version;
  
  				// Version
  				version = m.GetNumber1();                          
  				if (version != 2) 
  				{
  					throw new MessageException("Version is invalid");						
  				}													
  
  				// Sequence
  				Sequence = m.GetNumber2();
  
  				// Endpoint
  				Endpoint = m.GetString();
  
  				// Groups
  				listSize = (int)m.GetNumber4();                
  				Groups = new List<string>(listSize);                 
  				while (listSize-- > 0) 
  				{
  					string s = m.GetLongString();
  					Groups.Add(s);                    
  				}												
  
  				// Status
  				Status = m.GetNumber1();
  
  				// Name
  				Name = m.GetString();
  
  				// Headers
  				hashSize = (int)m.GetNumber4();                
  				Headers = new Dictionary<string, string>();                
  				while (hashSize-- > 0)  
  				{
  					string key = m.GetString();
  					string value = m.GetLongString();
  					Headers.Add(key, value);
  				}						
  
  			}
  		}
  
  		#endregion
  
  		#region Whisper
  
  		public class WhisperMessage
  		{
  			public WhisperMessage()
  			{
  			}			
  
  			/// <summary>
  			/// Get/Set the Version field
  			/// </summary>
  			public byte Version
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// Get/Set the Sequence field
  			/// </summary>
  			public UInt16 Sequence
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// /// Get/Set the Content NetMQMessage
  			/// </summary>
  			public NetMQMessage Content 
  			{
  				get;set;
  			}
  
  
  			internal int GetFrameSize()
  			{
  				int frameSize = 0;
  
  				//  Version
  				frameSize += 1;          
  
  				//  Sequence
  				frameSize += 2;          
  
  				//  Content
  
  				return frameSize;
  			}		
  
  			internal void Write(ZreMsgOriginal m)
  			{
  				// Version
  				m.PutNumber1(2); // Version
  
  				// Sequence
  				m.PutNumber2(Sequence);
  
  				// Content
  
  			}
  
  			internal void Read(ZreMsgOriginal m)
  			{
  				int listSize;
  				int hashSize;
  				int chunkSize;
  				byte[] guidBytes;
  				byte version;
  
  				// Version
  				version = m.GetNumber1();                          
  				if (version != 2) 
  				{
  					throw new MessageException("Version is invalid");						
  				}													
  
  				// Sequence
  				Sequence = m.GetNumber2();
  
  				// Content
  
  			}
  		}
  
  		#endregion
  
  		#region Shout
  
  		public class ShoutMessage
  		{
  			public ShoutMessage()
  			{
  			}			
  
  			/// <summary>
  			/// Get/Set the Version field
  			/// </summary>
  			public byte Version
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// Get/Set the Sequence field
  			/// </summary>
  			public UInt16 Sequence
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// Get/Set the Group field
  			/// </summary>
  			public string Group
  			{
  				get;set;
  			}
  
  			/// <summary>
  			/// /// Get/Set the Content NetMQMessage
  			/// </summary>
  			public NetMQMessage Content 
  			{
  				get;set;
  			}
  
  
  			internal int GetFrameSize()
  			{
  				int frameSize = 0;
  
  				//  Version
  				frameSize += 1;          
  
  				//  Sequence
  				frameSize += 2;          
  
  				//  Group
  
gt: 				frameSize += 1 + Group.Length;