This PR introduces the schema-thrift module, porting Thrift serialization support to ZIO Schema 2. It provides a fully functional ThriftDeriver that automatically generates type-safe ThriftBinaryCodec instances for any ZIO Schema type, ensuring feature parity with the existing Avro implementation.
This is a direct port of the logic from the original zio-schema-thrift implementation, adapted for the new modular structure and ZIO Schema 2 APIs.
schema-thriftschema-thrift, within the build configuration.org.apache.thrift:libthrift:0.20.0 and jakarta.annotation:jakarta.annotation-api:3.0.0 as core dependencies.chunk module to facilitate efficient, zero-copy byte handling.ThriftDeriver & ThriftFormatDeriver and Reflect APIs inherent to ZIO Schema 2.ThreadLocal) to handle recursive schemas for both Records and Variants (including DynamicValue), effectively preventing StackOverflowError during derivation.DynamicValue, allowing for flexible, schema-less serialization and deserialization via Thrift.ThriftTransport: Developed a custom TTransport implementation backed by zio.Chunk. This allows for efficient serialization directly to and from ZIO Chunks, minimizing unnecessary array inclusions and buffer copying.The codec enables Thrift serialization for the full spectrum of ZIO Schema primitives:
Boolean -> BOOL, Int -> I32, Long -> I64, etc.) or appropriate fallbacks (Char -> STRING).BigInt (serialized as STRING) and BigDecimal (serialized as a structured STRUCT).UUID and Currency (serialized as STRING).java.time suite (e.g., Instant, LocalDate, ZonedDateTime), using standardized String or Struct representations.List, Vector, Set (via TType.LIST/TType.SET), and Map (via TType.MAP).TType.STRUCT.ThriftCodecSpec, mirroring the rigorous coverage of AvroFormatSpec.DynamicValue.build.sbt structure.zio.blocks.schema.thrift.ThriftFormat.import zio.schema.Schema
import zio.blocks.schema.thrift.ThriftFormat
import zio.Chunk
case class Person(name: String, age: Int)
object Person {
implicit val schema: Schema[Person] = Schema.gen
}
val person = Person("Alice", 30)
// Encodes directly to a ZIO Chunk[Byte]
val binary: Chunk[Byte] = ThriftFormat.encode(person)
// Decodes back to a Person case class
val result: Either[String, Person] = ThriftFormat.decode[Person](binary)
/claim #681 Fixes: #681
Pranjal Negi
@Pranjal6955
ZIO
@ZIO