Ejemplo n.º 1
0
 public Message Deserialize()
 {
     Message message = new Message();
      message.Version = ReadUInt16();
      int headerCount = ReadUInt16();
      for (int i = 0; i < headerCount; ++i)
      {
     string key = ReadShortString();
     bool required = ReadBoolean();
     int length = ReadInt32(); //doesn't seem necessary?
     object data = ReadData(ReadByte());
     message.Headers.Add(new Header(key, required, data));
      }
      int bodyCount = ReadUInt16();
      for (int i = 0; i < bodyCount; ++i)
      {
     string rawMethod = ReadShortString();
     int index = rawMethod.LastIndexOf('.');
     string method = rawMethod.Substring(index+1);
     if (index==-1)
     {
         index = 0;
     }
     string type = rawMethod.Substring(0, index);
     string target = ReadShortString();
     int length = ReadInt32();
     object data = ReadData(ReadByte());
     message.Bodies.Add(new Body(method, type, target, data));
      }
      return message;
 }
Ejemplo n.º 2
0
 public void SerializeRequest(Message message)
 {
     WriteUInt16(message.Version);
     WriteUInt16((UInt16)message.Headers.Count);
     foreach (Header header in message.Headers) {
         Write(header.Key);
         Write(header.Required);
         Write(-1);
         WriteData(header.Data);
     }
     WriteUInt16((UInt16)message.Bodies.Count);
     foreach (Body b in message.Bodies) {
         WriteString(b._type+"."+b._method);
         WriteString(b._target);
         Write(-1);
         WriteData(b._data);
     }
 }
Ejemplo n.º 3
0
 public void Serialize(Message message)
 {
     WriteUInt16(message.Version);
     WriteUInt16((UInt16)message.Headers.Count);
     foreach (Header header in message.Headers) {
         Write(header.Key);
         Write(header.Required);
         Write(-1);
         WriteData(header.Data);
     }
     WriteUInt16((UInt16)message.Response.Count);
     foreach (Response response in message.Response) {
         WriteString(response.ReplyMethod);
         WriteString("null");
         Write(-1);
         WriteData(response.Data);
     }
 }