@zio.dev/zio-blocks 0.0.32 → 0.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/guides/compile-time-resource-safety-with-scope.md +16 -17
  2. package/guides/getting-started-with-mux.md +1507 -0
  3. package/guides/query-dsl-extending.md +161 -102
  4. package/guides/query-dsl-fluent-builder.md +217 -157
  5. package/guides/query-dsl-reified-optics.md +12 -10
  6. package/guides/query-dsl-sql.md +246 -165
  7. package/guides/telemetry-guide.md +1069 -0
  8. package/guides/zio-schema-migration.md +29 -22
  9. package/index.md +293 -51
  10. package/package.json +1 -1
  11. package/plans/config-follow-up-prs.md +188 -0
  12. package/plans/config-pr-assessment-roadmap.md +310 -0
  13. package/reference/MuxDataFlow.jsx +250 -0
  14. package/reference/async.md +651 -0
  15. package/reference/chunk.md +3533 -308
  16. package/reference/codegen/case-class.md +436 -0
  17. package/reference/codegen/emitter-config.md +383 -0
  18. package/reference/codegen/examples.md +664 -0
  19. package/reference/codegen/field.md +316 -0
  20. package/reference/codegen/index.md +317 -0
  21. package/reference/codegen/scala-emitter.md +392 -0
  22. package/reference/codegen/scala-file.md +276 -0
  23. package/reference/codegen/sealed-trait.md +408 -0
  24. package/reference/codegen/type-definition.md +340 -0
  25. package/reference/codegen/type-ref.md +201 -0
  26. package/reference/combinators.md +347 -117
  27. package/reference/config.md +158 -0
  28. package/reference/context.md +4 -4
  29. package/reference/datastar.md +346 -0
  30. package/reference/docs.md +1461 -345
  31. package/reference/endpoint/auth-type.md +146 -0
  32. package/reference/endpoint/endpoint.md +297 -0
  33. package/reference/endpoint/http-codec.md +249 -0
  34. package/reference/endpoint/index.md +825 -0
  35. package/reference/endpoint/path-codec.md +237 -0
  36. package/reference/endpoint/route-pattern.md +196 -0
  37. package/reference/endpoint/route-tree.md +111 -0
  38. package/reference/endpoint/segment-codec.md +212 -0
  39. package/reference/html.md +1120 -0
  40. package/reference/htmx/attribute-values.md +359 -0
  41. package/reference/htmx/hx-encoding.md +111 -0
  42. package/reference/htmx/hx-params.md +204 -0
  43. package/reference/htmx/hx-swap.md +276 -0
  44. package/reference/htmx/hx-sync.md +251 -0
  45. package/reference/htmx/hx-target.md +314 -0
  46. package/reference/htmx/hx-trigger.md +457 -0
  47. package/reference/htmx/hx-url-update.md +239 -0
  48. package/reference/htmx/index.md +855 -0
  49. package/reference/http-model/index.md +47 -0
  50. package/reference/http-model/model.md +1481 -0
  51. package/reference/http-model/schema.md +747 -0
  52. package/reference/maybe.md +826 -0
  53. package/reference/media-type.md +2 -2
  54. package/reference/mux.mdx +823 -0
  55. package/reference/openapi.md +1351 -0
  56. package/reference/resource-management/defer-handle.md +1 -1
  57. package/reference/resource-management/resource.md +31 -2
  58. package/reference/resource-management/scope.md +28 -12
  59. package/reference/resource-management/wire.md +3 -7
  60. package/reference/ringbuffer/MpmcDiagram.jsx +717 -0
  61. package/reference/ringbuffer/MpscDiagram.jsx +618 -0
  62. package/reference/ringbuffer/SpmcDiagram.jsx +680 -0
  63. package/reference/ringbuffer/SpscDiagram.jsx +677 -0
  64. package/reference/ringbuffer/advanced.mdx +109 -0
  65. package/reference/ringbuffer/index.mdx +145 -0
  66. package/reference/ringbuffer/mpmc.mdx +151 -0
  67. package/reference/ringbuffer/mpsc.mdx +132 -0
  68. package/reference/ringbuffer/spmc.mdx +108 -0
  69. package/reference/ringbuffer/spsc.mdx +344 -0
  70. package/reference/{allows.md → schema/allows.md} +4 -4
  71. package/reference/{binding-resolver.md → schema/binding-resolver.md} +1 -1
  72. package/reference/{binding.md → schema/binding.md} +2 -3
  73. package/reference/schema/built-in-codecs/avro.md +451 -0
  74. package/reference/schema/built-in-codecs/bson.md +480 -0
  75. package/reference/schema/built-in-codecs/csv.md +564 -0
  76. package/reference/schema/built-in-codecs/index.md +77 -0
  77. package/reference/schema/built-in-codecs/json/index.md +295 -0
  78. package/reference/schema/built-in-codecs/json/json-config.md +217 -0
  79. package/reference/{json-patch.md → schema/built-in-codecs/json/json-patch.md} +3 -3
  80. package/reference/{json-schema.md → schema/built-in-codecs/json/json-schema.md} +14 -47
  81. package/reference/schema/built-in-codecs/json/json-selection.md +322 -0
  82. package/reference/{json.md → schema/built-in-codecs/json/json.md} +32 -64
  83. package/reference/schema/built-in-codecs/messagepack.md +508 -0
  84. package/reference/schema/built-in-codecs/thrift.md +433 -0
  85. package/reference/schema/built-in-codecs/toon.md +1078 -0
  86. package/reference/{xml.md → schema/built-in-codecs/xml.md} +34 -192
  87. package/reference/schema/built-in-codecs/yaml.md +552 -0
  88. package/reference/{codec.md → schema/codec.md} +10 -10
  89. package/reference/{dynamic-optic.md → schema/dynamic-optic.md} +151 -5
  90. package/reference/{dynamic-schema.md → schema/dynamic-schema.md} +8 -8
  91. package/reference/schema/format.md +92 -0
  92. package/reference/schema/index.md +50 -0
  93. package/reference/schema/migration.md +297 -0
  94. package/reference/{modifier.md → schema/modifier.md} +58 -7
  95. package/reference/{optics.md → schema/optics.md} +2 -2
  96. package/reference/{patch.md → schema/patch.md} +1 -1
  97. package/{path-interpolator.md → reference/schema/path-interpolator.md} +165 -72
  98. package/reference/{schema-evolution → schema/schema-evolution}/as.md +5 -5
  99. package/reference/{schema-evolution → schema/schema-evolution}/index.md +2 -2
  100. package/reference/{schema-evolution → schema/schema-evolution}/into.md +3 -3
  101. package/reference/{schema-expr.md → schema/schema-expr.md} +110 -175
  102. package/reference/{schema.md → schema/schema.md} +13 -1
  103. package/reference/{structural-types.md → schema/structural-types.md} +1 -1
  104. package/reference/{type-class-derivation.md → schema/type-class-derivation.md} +63 -1
  105. package/reference/smithy.md +533 -0
  106. package/reference/sql/db-codec-deriver.md +71 -0
  107. package/reference/sql/db-codec.md +687 -0
  108. package/reference/sql/db-con.md +271 -0
  109. package/reference/sql/db-connection.md +153 -0
  110. package/reference/sql/db-param-writer.md +77 -0
  111. package/reference/sql/db-param.md +66 -0
  112. package/reference/sql/db-result-reader.md +146 -0
  113. package/reference/sql/db-tx.md +82 -0
  114. package/reference/sql/db-value.md +41 -0
  115. package/reference/sql/ddl.md +85 -0
  116. package/reference/sql/frag.md +254 -0
  117. package/reference/sql/index.md +341 -0
  118. package/reference/sql/repo.md +600 -0
  119. package/reference/sql/sql-dialect.md +73 -0
  120. package/reference/sql/sql-logger.md +62 -0
  121. package/reference/sql/sql-name-mapper.md +70 -0
  122. package/reference/sql/table-metadata.md +134 -0
  123. package/reference/sql/table.md +448 -0
  124. package/reference/sql/transactor-zio.md +399 -0
  125. package/reference/sql/transactor.md +353 -0
  126. package/reference/sql-zio.md +112 -0
  127. package/reference/streams/concurrent-operators.md +106 -0
  128. package/reference/streams/index.md +653 -0
  129. package/reference/streams/pipeline.md +718 -0
  130. package/reference/streams/reader.md +1284 -0
  131. package/reference/streams/scala-2-compatibility.md +55 -0
  132. package/reference/streams/sink.md +1426 -0
  133. package/reference/streams/stream.md +2526 -0
  134. package/reference/streams/writer.md +1045 -0
  135. package/reference/streams/zero-boxing.md +275 -0
  136. package/reference/telemetry.md +693 -0
  137. package/reference/typeid.md +2922 -583
  138. package/sidebars.js +238 -43
  139. package/superpowers/plans/2026-03-19-docs-critique-subagent.md +407 -0
  140. package/superpowers/specs/2026-03-19-docs-critique-subagent-design.md +222 -0
  141. package/reference/formats.md +0 -694
  142. package/reference/http-model.md +0 -1716
  143. package/reference/streams.md +0 -989
  144. package/ringbuffer.md +0 -249
  145. /package/reference/{json-differ.md → schema/built-in-codecs/json/json-differ.md} +0 -0
  146. /package/reference/{dynamic-value.md → schema/dynamic-value.md} +0 -0
  147. /package/reference/{lazy.md → schema/lazy.md} +0 -0
  148. /package/reference/{reflect.md → schema/reflect.md} +0 -0
  149. /package/reference/{registers.md → schema/registers.md} +0 -0
  150. /package/reference/{schema-error.md → schema/schema-error.md} +0 -0
  151. /package/reference/{syntax.md → schema/syntax.md} +0 -0
  152. /package/reference/{validation.md → schema/validation.md} +0 -0
@@ -0,0 +1,433 @@
1
+ ---
2
+ id: thrift
3
+ title: "Thrift Codec Module"
4
+ ---
5
+
6
+ `zio-blocks-schema-thrift` is a **schema-driven Thrift codec module** for serializing and deserializing Scala types to and from Thrift binary format. It provides comprehensive encoding and decoding with support for 27 primitive types, records, variants, sequences, maps, and recursive types. Core types: `ThriftCodec`, `ThriftCodecDeriver`, `ThriftFormat`.
7
+
8
+ The module integrates with Apache Thrift to provide native binary serialization using TBinaryProtocol with automatic schema generation and optimized performance for distributed systems.
9
+
10
+ ## Motivation
11
+
12
+ Thrift is a compact binary serialization format that appears widely across distributed systems, microservices, and real-time messaging. Manually writing Thrift encoders and decoders is error-prone and repetitive, especially for complex types with records, nested structures, and recursive definitions. `zio-blocks-schema-thrift` eliminates this friction by deriving codec instances directly from your Scala types using ZIO Schema. You describe your data shape once, and the module handles:
13
+ - Full Thrift type support (all primitives, records, unions, arrays, maps)
14
+ - Automatic schema generation from Scala types
15
+ - Optimized encoding with minimal overhead using TBinaryProtocol
16
+ - Precise error reporting with location traces showing the path to errors
17
+ - Recursive type support with automatic cycle detection
18
+ - Multiple encoding paths: ByteBuffer and byte arrays
19
+ - Multiple decoding paths: ByteBuffer and byte arrays
20
+ - JVM support (not available for Scala.js)
21
+
22
+ Rather than writing custom encoders or relying on code generation from .thrift files, you work with strongly-typed schemas that the compiler validates.
23
+
24
+ ## Installation
25
+
26
+ Add the module to your `build.sbt`:
27
+
28
+ ```sbt
29
+ libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.51"
30
+ ```
31
+
32
+ **Note:** This module is JVM-only and is not available for Scala.js.
33
+
34
+ Supported Scala versions: 2.13.x and 3.x
35
+
36
+ ## Introduction
37
+
38
+ The module provides a complete pipeline for Thrift codec derivation and usage:
39
+
40
+ 1. **Define your type** — Any Scala type with a `Schema` instance
41
+ 2. **Derive a codec** — Use `Schema.derive(ThriftFormat)` to obtain a `ThriftCodec[A]`
42
+ 3. **Encode or decode** — Call `codec.encode(value)` or `codec.decode(bytes)`
43
+ 4. **Handle errors** — Catch `SchemaError` with location traces showing where the error occurred
44
+
45
+ The derivation process is automatic for all supported types (all 27 primitives, records, variants, sequences, maps). The module automatically generates Thrift-compatible formats and handles encoding/decoding without manual configuration.
46
+
47
+ ## How They Work Together
48
+
49
+ The Thrift codec pipeline flows through these layers:
50
+
51
+ ```
52
+ 1. User defines Schema[A] for their type
53
+ ↓
54
+ 2. Schema[A].derive(ThriftFormat) creates ThriftCodec[A]
55
+ ↓
56
+ 3. ThriftCodecDeriver derives Encoder and Decoder implementations
57
+ - For primitives: type-specific Thrift encoders/decoders
58
+ - For records: field-by-field composition with Thrift struct encoding
59
+ - For variants: union encoding with discriminators
60
+ - For sequences: array encoding/decoding
61
+ - For maps: map encoding/decoding
62
+ ↓
63
+ 4. ThriftCodec provides multiple encoding paths
64
+ - encode(value) → Array[Byte]
65
+ - encode(value, buffer: ByteBuffer) → Unit
66
+ ↓
67
+ 5. ThriftCodec provides multiple decoding paths
68
+ - decode(bytes: Array[Byte]) → Either[SchemaError, A]
69
+ - decode(buffer: ByteBuffer) → Either[SchemaError, A]
70
+ ↓
71
+ 6. TBinaryProtocol manages I/O with Thrift wire format
72
+ - Efficient binary encoding with type information
73
+ - Automatic format detection and optimization
74
+ - Support for unknown fields (schema evolution)
75
+ ↓
76
+ 7. Errors include location traces
77
+ Shows path (.field[index].nested) to error location
78
+ ```
79
+
80
+ **Typical workflow:**
81
+
82
+ A user type flows through the derivation and encoding pipeline as follows:
83
+
84
+ ```
85
+ User type (e.g., case class Person)
86
+ ↓
87
+ Schema.derived (automatic via macro)
88
+ ↓
89
+ Schema[Person].derive(ThriftFormat) → ThriftCodec[Person]
90
+ ↓
91
+ Use codec.encode(person) to serialize → Array[Byte]
92
+ Use codec.decode(bytes) to deserialize → Either[SchemaError, Person]
93
+ ↓
94
+ Handle SchemaError with location trace on failure
95
+ ```
96
+
97
+ ### Type Relationships
98
+
99
+ - **`ThriftCodec[A]`** — Main public API; contains encoder and decoder for bidirectional serialization
100
+ - **`ThriftCodecDeriver`** — Configuration and derivation system; generates codecs from Schema
101
+ - **`ThriftFormat`** — Integration with ZIO Schema format system; enables `Schema[A].derive(ThriftFormat)`
102
+
103
+ ## Common Patterns
104
+
105
+ This section shows practical patterns for working with Thrift codecs in real-world scenarios.
106
+
107
+ ### Pattern 1: Derive and Encode a Simple Record
108
+
109
+
110
+ To derive a Thrift codec for a record type and encode a value:
111
+
112
+ ```scala
113
+ import zio.blocks.schema._
114
+ import zio.blocks.schema.thrift._
115
+
116
+ case class Person(name: String, age: Int, email: String)
117
+
118
+ object Person {
119
+ implicit val schema: Schema[Person] = Schema.derived
120
+ }
121
+
122
+ val codec = Person.schema.derive(ThriftFormat)
123
+ val person = Person("Alice", 30, "alice@example.com")
124
+ val bytes = codec.encode(person)
125
+ ```
126
+
127
+ ### Pattern 2: Decode Thrift with Error Handling
128
+
129
+ When decoding Thrift data, errors include location traces showing where the problem occurred.
130
+
131
+ To decode bytes and handle errors with location information:
132
+
133
+ ```scala
134
+ import zio.blocks.schema._
135
+ import zio.blocks.schema.thrift._
136
+
137
+ case class Employee(id: Int, name: String, salary: Double)
138
+
139
+ object Employee {
140
+ implicit val schema: Schema[Employee] = Schema.derived
141
+ }
142
+
143
+ val codec = Employee.schema.derive(ThriftFormat)
144
+ val bytes = Array[Byte](1, 2, 3) // truncated data
145
+
146
+ val result = codec.decode(bytes)
147
+
148
+ result match {
149
+ case Right(employee) => println(s"Decoded: $employee")
150
+ case Left(error) =>
151
+ println(s"Error: ${error.getMessage}")
152
+ }
153
+ ```
154
+
155
+ ### Pattern 3: Handle Recursive Types
156
+
157
+ Recursive types (types that reference themselves) are fully supported with automatic cycle detection.
158
+
159
+ To define and encode a recursive data structure:
160
+
161
+ ```scala
162
+ import zio.blocks.schema._
163
+ import zio.blocks.schema.thrift._
164
+
165
+ sealed trait Node
166
+ case class Leaf(value: String) extends Node
167
+ case class Branch(left: Node, right: Node) extends Node
168
+
169
+ object Node {
170
+ implicit val schema: Schema[Node] = Schema.derived
171
+ }
172
+
173
+ val codec = Node.schema.derive(ThriftFormat)
174
+ val tree: Node = Branch(Leaf("A"), Branch(Leaf("B"), Leaf("C")))
175
+ val bytes = codec.encode(tree)
176
+ ```
177
+
178
+ ### Pattern 4: Work with Variants (Sealed Traits)
179
+
180
+ Thrift unions are encoded as discriminated variants with type information.
181
+
182
+ To derive a codec for a sealed trait:
183
+
184
+ ```scala
185
+ import zio.blocks.schema._
186
+ import zio.blocks.schema.thrift._
187
+
188
+ sealed trait Status
189
+ case class Active(since: String) extends Status
190
+ case class Inactive(reason: String) extends Status
191
+
192
+ object Status {
193
+ implicit val schema: Schema[Status] = Schema.derived
194
+ }
195
+
196
+ val codec = Status.schema.derive(ThriftFormat)
197
+ val status: Status = Active("2024-01-01")
198
+ val bytes = codec.encode(status)
199
+ ```
200
+
201
+ ---
202
+
203
+ ## ThriftCodec[A]
204
+
205
+ Main codec type for encoding and decoding values to and from Thrift binary format. Contains encoder and decoder for bidirectional serialization.
206
+
207
+ ### Overview
208
+
209
+ `ThriftCodec[A]` holds both an encoder and decoder, providing a complete solution for serializing and deserializing values in Thrift binary format. The codec is derived automatically from a `Schema[A]` using `ThriftFormat`.
210
+
211
+ ### Encoding Values to Byte Array
212
+
213
+ Use the codec to convert values to byte arrays:
214
+
215
+ ```scala
216
+ import zio.blocks.schema._
217
+ import zio.blocks.schema.thrift._
218
+
219
+ case class Product(name: String, price: Double)
220
+
221
+ object Product {
222
+ implicit val schema: Schema[Product] = Schema.derived
223
+ }
224
+
225
+ val codec = Product.schema.derive(ThriftFormat)
226
+ val product = Product("Widget", 9.99)
227
+ val bytes = codec.encode(product)
228
+ ```
229
+
230
+ ### Encoding Values to ByteBuffer
231
+
232
+ Write encoded values directly to a ByteBuffer:
233
+
234
+ ```scala
235
+ import zio.blocks.schema._
236
+ import zio.blocks.schema.thrift._
237
+ import java.nio.ByteBuffer
238
+
239
+ case class Item(name: String, quantity: Int)
240
+
241
+ object Item {
242
+ implicit val schema: Schema[Item] = Schema.derived
243
+ }
244
+
245
+ val codec = Item.schema.derive(ThriftFormat)
246
+ val item = Item("Gadget", 42)
247
+ val buffer = ByteBuffer.allocate(1024)
248
+ codec.encode(item, buffer)
249
+ val bytes = java.util.Arrays.copyOf(buffer.array, buffer.position)
250
+ ```
251
+
252
+ ### Decoding Values from Byte Array
253
+
254
+ Use the codec to convert byte arrays back to values:
255
+
256
+ ```scala
257
+ import zio.blocks.schema._
258
+ import zio.blocks.schema.thrift._
259
+
260
+ case class Record(id: Int, value: String)
261
+
262
+ object Record {
263
+ implicit val schema: Schema[Record] = Schema.derived
264
+ }
265
+
266
+ val codec = Record.schema.derive(ThriftFormat)
267
+ val record = Record(123, "test")
268
+ val buffer = java.nio.ByteBuffer.allocate(256)
269
+ codec.encode(record, buffer)
270
+ buffer.flip()
271
+ val bytes = new Array[Byte](buffer.remaining())
272
+ buffer.get(bytes)
273
+
274
+ val result: Either[zio.blocks.schema.SchemaError, Record] = codec.decode(bytes)
275
+ ```
276
+
277
+ ### Decoding Values from ByteBuffer
278
+
279
+ Read and decode values from a ByteBuffer:
280
+
281
+ ```scala
282
+ import zio.blocks.schema._
283
+ import zio.blocks.schema.thrift._
284
+ import java.nio.ByteBuffer
285
+
286
+ case class Data(timestamp: Long, payload: String)
287
+
288
+ object Data {
289
+ implicit val schema: Schema[Data] = Schema.derived
290
+ }
291
+
292
+ val codec = Data.schema.derive(ThriftFormat)
293
+ // Use encoded data from a previous encoding
294
+ val data = Data(System.currentTimeMillis(), "example")
295
+ val encBuffer = java.nio.ByteBuffer.allocate(256)
296
+ codec.encode(data, encBuffer)
297
+ encBuffer.flip()
298
+ val result = codec.decode(encBuffer)
299
+ ```
300
+
301
+ ---
302
+
303
+ ## ThriftCodecDeriver
304
+
305
+ Configuration and derivation system for creating `ThriftCodec[A]` instances from `Schema[A]`.
306
+
307
+ ### Overview
308
+
309
+ `ThriftCodecDeriver` implements the schema-driven derivation of Thrift codecs. It automatically handles 27 primitive types and complex types (records, variants, sequences, maps), generating appropriate Thrift encoders and decoders.
310
+
311
+ ### How Derivation Works
312
+
313
+ To create a codec from a schema:
314
+
315
+ ```scala
316
+ import zio.blocks.schema._
317
+ import zio.blocks.schema.thrift._
318
+
319
+ case class Person(name: String, age: Int)
320
+
321
+ object Person {
322
+ implicit val schema: Schema[Person] = Schema.derived
323
+ }
324
+
325
+ val codec = Person.schema.derive(ThriftFormat)
326
+ // codec: ThriftCodec[Person] = zio.blocks.schema.thrift.ThriftCodecDeriver$$anon$3@52aa2c93
327
+ ```
328
+
329
+ ### Primitive Type Support
330
+
331
+ All 27 ZIO Schema primitives are supported:
332
+ - Numeric: `Byte`, `Short`, `Int`, `Long`, `Float`, `Double`, `BigInt`, `BigDecimal`
333
+ - Logical: `Boolean`, `Char`, `String`
334
+ - Temporal: `Instant`, `LocalDate`, `LocalDateTime`, `LocalTime`, `Duration`, `Period`, `Year`, `YearMonth`, `MonthDay`, `Month`, `DayOfWeek`, `ZonedDateTime`, `OffsetDateTime`, `OffsetTime`, `ZoneId`, `ZoneOffset`
335
+ - Special: `UUID`, `Currency`, `Unit`
336
+
337
+ ### Record Type Support
338
+
339
+ Case classes (records) are fully supported. Each field becomes a named field in the Thrift struct:
340
+
341
+ ```scala
342
+ import zio.blocks.schema._
343
+ import zio.blocks.schema.thrift._
344
+
345
+ case class Address(street: String, city: String, zip: String)
346
+
347
+ object Address {
348
+ implicit val schema: Schema[Address] = Schema.derived
349
+ }
350
+
351
+ val codec = Address.schema.derive(ThriftFormat)
352
+ ```
353
+
354
+ ### Variant Type Support
355
+
356
+ Sealed traits and sum types are encoded as Thrift union types with discriminators:
357
+
358
+ ```scala
359
+ import zio.blocks.schema._
360
+ import zio.blocks.schema.thrift._
361
+
362
+ sealed trait Status
363
+ case class Active(since: String) extends Status
364
+ case class Inactive(reason: String) extends Status
365
+
366
+ object Status {
367
+ implicit val schema: Schema[Status] = Schema.derived
368
+ }
369
+
370
+ val codec = Status.schema.derive(ThriftFormat)
371
+ ```
372
+
373
+ ---
374
+
375
+ ## ThriftFormat
376
+
377
+ Integration point with ZIO Schema's format system. Provides `BinaryFormat[ThriftCodec]` to enable `Schema[A].derive(ThriftFormat)` for any supported type.
378
+
379
+ ### Using ThriftFormat
380
+
381
+ To derive a Thrift codec using the standard format:
382
+
383
+ ```scala
384
+ import zio.blocks.schema._
385
+ import zio.blocks.schema.thrift._
386
+
387
+ case class Sensor(id: Long, temperature: Double, humidity: Float)
388
+
389
+ object Sensor {
390
+ implicit val schema: Schema[Sensor] = Schema.derived
391
+ }
392
+
393
+ val codec = Sensor.schema.derive(ThriftFormat)
394
+ ```
395
+
396
+ `ThriftFormat` is a singleton object extending `BinaryFormat[ThriftCodec]` with the MIME type `"application/thrift"` and the `ThriftCodecDeriver` as its derivation strategy.
397
+
398
+ ---
399
+
400
+ ## Error Handling
401
+
402
+ Thrift decoding errors include location traces showing the path through nested structures where the error occurred.
403
+
404
+ ### Understanding Error Traces
405
+
406
+ Errors render as paths like `.field[0].nested.value` showing exactly where decoding failed:
407
+
408
+ ```scala
409
+ import zio.blocks.schema._
410
+ import zio.blocks.schema.thrift._
411
+
412
+ case class Contact(emails: Seq[String])
413
+
414
+ object Contact {
415
+ implicit val schema: Schema[Contact] = Schema.derived
416
+ }
417
+
418
+ val codec = Contact.schema.derive(ThriftFormat)
419
+ // Example invalid Thrift bytes
420
+ val invalidBytes: Array[Byte] = Array(0xFF.toByte, 0xFF.toByte)
421
+
422
+ val result = codec.decode(invalidBytes)
423
+
424
+ result match {
425
+ case Right(contact) => println(s"Success: $contact")
426
+ case Left(error) =>
427
+ println(s"Error: ${error.getMessage}")
428
+ }
429
+ ```
430
+
431
+ ### Zero-Overhead Error Handling
432
+
433
+ Errors use zero-overhead exceptions (no stack traces) for efficient error reporting in streaming scenarios where errors are expected and handled inline.