Compression was previously implemented in the connection.connection type, however this required the inspection of an already constructed wire message to determine if compression was allowed. Instead, the driver.OperationContext type should handle this directly. This can be done efficiently by retrieving the command name during wire message construction, returning it, and then using that to determine if compression can be done.
To hold the compression state, a CompressionContext type is used. This type has a CompressWireMessage method with the following signature:
func Compress(wm []byte, commandName string, desc description.Server) ([]byte, error)
The CompressionContext itself is defined as:
type CompressionContext struct { Compressors []string ZlibLevel int }
To aid in reuse of memory, global pools of zlib.ReaderCloser and zlib.Writer are required.
The Compress method should overwrite the provided slice with the newly compressed message. Internally, it can pull from it's own pool of []byte.