Register

zio.blocks.schema.binding.Register
See theRegister companion object
sealed trait Register[A]

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
class Object
trait Matchable
class Any
Known subtypes
class Boolean
class Byte
class Char
class Double
class Float
class Int
class Long
class Object[A]
class Short
object Unit
Show all

Members list

Type members

Types

final type Boxed = A

The type of the field's value, which get returns and set takes.

The type of the field's value, which get returns and set takes.

Attributes

Source
Register.scala

Value members

Abstract methods

def get(registers: Registers, base: RegisterOffset): Boxed

Reads the field from registers at this register's offset plus base.

Reads the field from registers at this register's offset plus base.

Attributes

Source
Register.scala
def set(registers: Registers, base: RegisterOffset, boxed: Boxed): Unit

Writes boxed into registers at this register's offset plus base.

Writes boxed into registers at this register's offset plus base.

Attributes

Source
Register.scala

The space the field takes, as a RegisterOffset: the size of its type in the byte area, one object slot, or nothing for Unit.

The space the field takes, as a RegisterOffset: the size of its type in the byte area, one object slot, or nothing for Unit.

Attributes

Source
Register.scala