예제 #1
0
        public void PushMessagesToSend(MessagesToSend messages)
        {
            serializedMessagesToSend.SerializeFrom(messages, commandMetaDataManager.GetEmptyMetaDataStorage());
            var metaData = serializedMessagesToSend.SendAndClear(connection);

            commandMetaDataManager.AddMetaData(metaData);
            serializedMessagesToSend.Clear();
            messages.Clear();
        }
        private void SerializeMessages()
        {
            // Block until a new message is available to serialize.
            while (messagesToSerialize.TryTake(out var messagesToSend, -1))
            {
                // If adding is complete then there is no reason to deserialize the message.
                if (messagesToSerialize.IsAddingCompleted)
                {
                    return;
                }

                SerializedMessagesToSend serialized = serializedMessagesToSendPool.Rent();
                CommandMetaData          metaData   = commandMetaDataManager.GetEmptyMetaDataStorage();

                // Serialize the messages and add them to the queue to be sent
                serialized.SerializeFrom(messagesToSend, metaData);
                messagesToSend.Clear();
                messagesToSendPool.Return(messagesToSend);
                serializedMessages.Enqueue(serialized);
            }
        }