Class Entities

java.lang.Object
io.kubfly.sdk.format.Entities

public final class Entities extends Object
The nested entities of records — Environment, Usage and their parts (sdk/spec/entities.md, decision 10): no schema in the data, a version byte before every entity (0 — none), its fields in the order of its version. The fields of every version live in entities.tsv, the same for the SDKs of all languages: the reader decodes an old version by its line of the table and fills the current record by the names of the fields (a field the old version lacks gets its default); the writer writes the latest version, and refuses to start if the class no longer matches it — a changed record needs a new version in the table.

Kinds of fields: boolean (u8), int, long (zigzag), double, float (IEEE 754), string and zone (u8 0 — null, 1 — a string follows), enum:T (as a string: the name of the constant), list:K (varint count + 1, 0 — null, then the elements), record:T (an entity, with its own version byte; a component Option<T> of an entity is the same record:T, none — version 0, and one newer than the reader is none, where a required part newer than the reader passes its owner over). Types are named from io.kubfly.sdk.api: Environment, environment.Machine, usage.host.Cpu.

A union is a sealed interface of records (usage.platform.Platform): an entity whose fields are kind (the enum its method kind() returns), then one record per permitted record, in the order of permits, named by the record with a small first letter (jvm, go); only the part of the value is written, the others are version 0. The reader gives that part, the record of the interface.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    A field of a version of an entity.
    static interface 
    An entity read: its value, none (version 0), or newer than this reader — passed over by its length and told to the report.
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<String>
    current(Class<?>... roots)
    The lines of the current classes, as the table must hold them for their latest versions.
    fields(String name, int version)
    The fields of a version of a type.
    static int
    latest(String name)
    The latest version of a type.
    static String
    name(Class<?> type)
    The name of a type in the table.
    static <T extends Record>
    Option<T>
    read(BufferReader reader, Class<T> type)
    Reads an entity of any version known to entities.tsv into the current record.
    static <T extends Record>
    Entities.Read<T>
    read(BufferReader reader, Class<T> type, Newer newer)
    Reads an entity of any version known to entities.tsv into the current record; one newer than this reader is passed over by its length and told to the report (decision 89), and so is one whose required part is newer.
    static Set<String>
    The types of the table, for diagnostics.
    static int
    write(byte[] buffer, int offset, Record value)
    Writes an entity of its latest version, or 0 for null.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • write

      public static int write(byte[] buffer, int offset, Record value)
      Writes an entity of its latest version, or 0 for null.
      Parameters:
      buffer - the buffer or null to count only
      offset - where
      value - the entity or null
      Returns:
      the offset after it
      Throws:
      IllegalStateException - if the class does not match its latest version in entities.tsv
    • read

      public static <T extends Record> Option<T> read(BufferReader reader, Class<T> type) throws IOException
      Reads an entity of any version known to entities.tsv into the current record.
      Type Parameters:
      T - the type
      Parameters:
      reader - the reader
      type - the current class
      Returns:
      the entity; None for version 0 — no entity
      Throws:
      IOException - if the data is damaged or the version is unknown
    • read

      public static <T extends Record> Entities.Read<T> read(BufferReader reader, Class<T> type, Newer newer) throws IOException
      Reads an entity of any version known to entities.tsv into the current record; one newer than this reader is passed over by its length and told to the report (decision 89), and so is one whose required part is newer. A part newer than the reader in a list is left out of the list.
      Type Parameters:
      T - the type
      Parameters:
      reader - the reader
      type - the current class
      newer - the report of what was passed over
      Returns:
      the entity, none (version 0), or newer than this reader
      Throws:
      IOException - if the data is damaged
    • name

      public static String name(Class<?> type)
      The name of a type in the table.
      Parameters:
      type - the class
      Returns:
      usage.host.Cpu
    • current

      public static List<String> current(Class<?>... roots)
      The lines of the current classes, as the table must hold them for their latest versions.
      Parameters:
      roots - the root entities (Environment, Usage)
      Returns:
      type<TAB>field<TAB>kind, in the order of a walk from the roots
    • fields

      public static Option<List<Entities.Field>> fields(String name, int version)
      The fields of a version of a type.
      Parameters:
      name - the type
      version - the version
      Returns:
      the fields; None if the type or the version is unknown
    • latest

      public static int latest(String name)
      The latest version of a type.
      Parameters:
      name - the type
      Returns:
      the version, or 0 if unknown
    • types

      public static Set<String> types()
      The types of the table, for diagnostics.
      Returns:
      the names