private void CreateBufferWriteSingle(MessageFrame messageFrame) { var sendBufferSize = MessageFrame.HeaderSize + messageFrame.RawMessage.Length; WeakReference <MemoryStream> reference; var mem = GetOrCreateMemoryStream(sendBufferSize, out reference); try { WriteTypeId(mem, messageFrame.MessageTypeId); WriteLength(mem, messageFrame.RawMessage.Length); WriteBody(mem, messageFrame.RawMessage); var toSend = mem.GetBuffer(); _streamSocket.Write(toSend, 0, sendBufferSize); } finally { mem.SetLength(0); RecycledMemoryStreams.Enqueue(reference); } }
public void WriteGreeting(NodeGreetingMessage greetingMessage) { var serialized = greetingMessage.Serialize(); _streamSocket.Write(serialized, 0, serialized.Length); }