All Downloads are FREE. Search and download functionalities are using the official Maven repository.

orcus.bigtable.codec.DerivedFamilyEncoder.scala Maven / Gradle / Ivy

There is a newer version: 0.28.9
Show newest version
package orcus.bigtable.codec

import com.google.protobuf.ByteString
import shapeless3.deriving.*

trait DerivedFamilyEncoder[A] extends FamilyEncoder[A]

object DerivedFamilyEncoder extends DerivedFamilyEncoder1

private[codec] trait DerivedFamilyEncoder1:

  given familyEncoderGen[A](using
    inst: K0.ProductInstances[PrimitiveEncoder, A],
    labelling: Labelling[A]
  ): DerivedFamilyEncoder[A] with
    def apply(v: A): Map[ByteString, ByteString] =
      val builder = Map.newBuilder[ByteString, ByteString]
      labelling.elemLabels.zipWithIndex.foreach { case (l, i) =>
        builder += ByteString.copyFromUtf8(l) -> inst.project(v)(i)(
          [t] => (f: PrimitiveEncoder[t], pt: t) => f(pt)
        )
      }
      builder.result()

  inline def derived[A](using K0.ProductGeneric[A]): DerivedFamilyEncoder[A] = familyEncoderGen




© 2015 - 2024 Weber Informatics LLC | Privacy Policy