Exemplo n.º 1
0
 private static void SendUpdateMessage(ISolutionStrategy strategy, ProblemUpdateType updateType, ZmqSocket socket, IBinaryConvertible data)
 {
     ZmqMessage message = new ZmqMessage();
     message.Append(Encoding.UTF8.GetBytes(strategy.Signature));
     message.AppendEmptyFrame();
     message.Append(new byte[1] { (byte)updateType });
     message.AppendEmptyFrame();
     message.Append(new byte[1] { 0x7f });
     message.Append(data.GetBytes());
     socket.SendMessage(message);
 }
Exemplo n.º 2
0
 private static void SendUpdateMessage(ISolutionStrategy strategy, ProblemUpdateType updateType, ZmqSocket socket, object data, IFormatter formatter = null)
 {
     formatter = formatter ?? new BinaryFormatter();
     ZmqMessage message = new ZmqMessage();
     message.Append(Encoding.UTF8.GetBytes(strategy.Signature));
     message.AppendEmptyFrame();
     message.Append(new byte[1] { (byte)updateType });
     message.AppendEmptyFrame();
     message.Append(new byte[1] { 0x7f });
     using (MemoryStream ms = new MemoryStream())
     {
         formatter.Serialize(ms, data);
         // TODO: Find more efficient way to write byte[] since MemoryStream.ToArray performs a copy
         //       whereas MemoryStream.GetBuffer() returns all allocated bytes whether they are empty or not
         message.Append(ms.ToArray());
     }
     socket.SendMessage(message);
 }