The position of one field of a record in Registers, and the kind of register that holds it. Reflect.Record#registers computes one per field, in field order, from the fields' types: a field stored as a Boolean, Byte, Short, Char, Int, Float, Long or Double (a primitive node of that type, or a wrapper node that Reflect treats as one, such as an opaque type over Int) gets the register of that type at the next free position of the byte area, a Unit field gets Register.Unit, and every other field gets a Register.Object at the next object slot. Lenses, Reflect.Record#fromDynamicValue and Reflect.Record#toDynamicValue use these registers to move a field's value in and out of registers without knowing its type.
get and set take a base offset, which is added to the register's own offset, so the same register works for a record placed anywhere in a larger Registers.
import zio.blocks.schema.binding._
case class Book(title: String, year: Int)
object Book {
implicit val schema: Schema[Book] = Schema.derived
}
val record = Book.schema.reflect.asRecord.get
val year = record.registers(1) // Int(1): byte 0, after the object slot of title
val registers = Registers(record.usedRegisters)
record.deconstructor.deconstruct(registers, RegisterOffset.Zero, Book("Zionomicon", 2021))
val value = year.get(registers, RegisterOffset.Zero) // 2021
Type parameters
- A
-
the type of the field
Attributes
- See also
- Companion
- object
- Source
- Register.scala
- Graph
-
- Supertypes
- Known subtypes