Skip to content

Data Models

A data model represents a set of types that are supported by Getty. The types within a data model are purely conceptual; they aren't actually Zig types. For example, there is no i32 or u64 in either of Getty's data models. Instead, they're both considered to be Integers.

Models

Getty maintains two data models: one for serialization and another for deserialization.

Serialization
Boolean

Represented by a bool value.

Enum

Represented by any enum value.

Float

Represented by any floating-point value (comptime_float, f16, f32, f64, f80, f128).

Integer

Represented by any integer value (comptime_int, u0u65535, i0i65535).

Map

Represented by a getty.ser.Map interface value.

Null

Represented by a null value.

Seq

Represented by a getty.ser.Seq interface value.

Some

Represented by the payload of an optional value.

String

Represented by any string value as determined by std.meta.trait.isZigString.

Structure

Represented by a getty.ser.Structure interface value.

Void

Represented by a void value.

Deserialization
Boolean

Represented by a bool value.

Enum

Represented by any enum value.

Float

Represented by any floating-point value (comptime_float, f16, f32, f64, f80, f128).

Integer

Represented by any integer value (comptime_int, u0u65535, i0i65535).

Map

Represented by a getty.de.MapAccess interface value.

Null

Represented by a null value.

Seq

Represented by a getty.de.SeqAccess interface value.

Some

Represented by the payload of an optional value.

String

Represented by any string value as determined by std.meta.trait.isZigString.

Union

Represented by a getty.de.UnionAccess interface value and a getty.de.VariantAccess interface value.

Void

Represented by a void value.

Motivation

Getty's data models establish a generic baseline from which (de)serializers can operate.

Data Model Data Model

This design often simplifies the job of a (de)serializer significantly. For example, suppose you wanted to serialize []i32, [100]i32, std.ArrayList(i32), and std.TailQueue(i32) values. Since Zig considers all of these types to be different, you'd have to write unique serialization logic for all of them (as well as for integers)!

In Getty, you don't have to do nearly as much work. Getty considers all of the aforementioned types to be the same: they are all Sequences. This means that you only have to specify the serialization process for two types: Integers and Sequences. And by doing so, you'll automatically be able to serialize values of any of the aforementioned types, plus any other value whose type is supported by Getty and is considered a Sequence, such as std.SinglyLinkedList and std.BoundedArray.

Interactions

Notice how (de)serializers in Getty never interact directly with Zig.

  • Serializers receive values from Getty's data model and serialize them into a data format.
  • Deserializers receive values from a data format and deserialize them into Getty's data model.