public ManualResetEventSlim Send(CommandObject command) { if (!command.Schema.ProcessRuntimeID.HasValue) { return(Send(PacketMethods.CreatePacket(PacketContents.CommandSchemaWithData, 0, command.ToCommand().ToArray()))); } else { int schemeRuntimeID; lock (m_knownSchemas) { if (!m_knownSchemas.TryGetValue(command.Schema.ProcessRuntimeID.Value, out schemeRuntimeID)) { if (command.Schema.ProcessRuntimeID == -1) { throw new Exception("Cannot serialize a schema that has not been defined in this process."); } schemeRuntimeID = m_knownSchemas.Count; m_knownSchemas.Add(command.Schema.ProcessRuntimeID.Value, schemeRuntimeID); Send(command.Schema.ToCommand(schemeRuntimeID)); } } return(Send(command.ToDataCommandPacket(schemeRuntimeID))); } }
private ManualResetEventSlim Send(PooledBuffer packet) { if (packet.Length > MaximumPacketSize) { throw new Exception("This packet is too large to send, if this is a legitimate size, increase the MaxPacketSize."); } switch (m_compressionMode) { case CtpCompressionMode.None: return(m_send(packet)); break; case CtpCompressionMode.Deflate: using (var ms = new MemoryStream()) { using (var comp = new DeflateStream(ms, CompressionMode.Compress, true)) { packet.CopyTo(comp); } return(m_send(PacketMethods.CreatePacket(PacketContents.CompressedDeflate, packet.Length, ms.ToArray()))); } break; case CtpCompressionMode.Zlib: if (m_stream == null) { m_stream = new MemoryStream(); m_deflate = new Ionic.Zlib.DeflateStream(m_stream, Ionic.Zlib.CompressionMode.Compress); m_deflate.FlushMode = FlushType.Sync; } m_stream.Write(BigEndian.GetBytes(packet.Length), 0, 4); packet.CopyTo(m_deflate); m_deflate.Flush(); byte[] rv = m_stream.ToArray(); m_stream.SetLength(0); return(m_send(PacketMethods.CreatePacket(PacketContents.CompressedZlib, packet.Length, rv))); break; default: throw new ArgumentOutOfRangeException(); } }