def withCompression[T <: GenericRecord: ClassTag]()

in bijection-avro/src/main/scala/com/twitter/bijection/avro/AvroCodecs.scala [213:252]


  def withCompression[T <: GenericRecord: ClassTag](
      schema: Schema,
      codecFactory: CodecFactory
  ): Injection[T, Array[Byte]] =
    new GenericAvroCodec[T](schema, Some(codecFactory))

  /**
    * Returns Injection capable of serializing and deserializing a compiled Avro record using
    * SpecificDatumWriter and SpecificDatumReader. Data is compressed with the Bzip2 codec.
    * @tparam T
    *   generic record
    * @return
    *   Injection
    */
  def withBzip2Compression[T <: GenericRecord: ClassTag](
      schema: Schema
  ): Injection[T, Array[Byte]] =
    withCompression(schema, CodecFactory.bzip2Codec())

  /**
    * Returns Injection capable of serializing and deserializing a compiled Avro record using
    * SpecificDatumWriter and SpecificDatumReader. Data is compressed with the Deflate codec.
    * @param compressionLevel
    *   Compression level should be between 1 and 9, inclusive. Higher values result in better
    *   compression at the expense of encoding speed. Default compression level is 5.
    * @tparam T
    *   generic record
    * @return
    *   Injection
    */
  def withDeflateCompression[T <: GenericRecord: ClassTag](
      schema: Schema,
      compressionLevel: Int = 5
  ): Injection[T, Array[Byte]] = {
    require(
      1 <= compressionLevel && compressionLevel <= 9,
      "Compression level should be between 1 and 9, inclusive"
    )
    withCompression(schema, CodecFactory.deflateCodec(compressionLevel))
  }