public override void SendMessage(Message message) { if (_service != null) { lock (_sendingMsgCache) { var copy = Message.New(message.MessageType); var read = new BitDataInputStream(_exchange); var write = new BitDataOutputStream(_exchange); message.WriteTo(write); copy.ReadFrom(read); _sendingMsgCache.Add(copy); Monitor.Pulse(_sendingMsgCache); } } else { var identifiedMsg = message as IdentifiedMessage; if (identifiedMsg != null) { if (_messageReceiverDict.TryGetValue(IdentifiedMessage.MESSAGE_TYPE, out List <IMessageReceiver> receivers)) { foreach (var receiver in receivers) { receiver.MessageReceived(new IdentifiedMessage() { resp = true, guid = identifiedMsg.guid, innerMessage = null }); } } } } }
public override void WriteTo(byte[] buf, ref int i) { var stream = new BitDataOutputStream(buf, i); _innerMessage.WriteTo(stream); i = stream.i; }