Class: Kiwi::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/kiwi/schema.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definitions) ⇒ Schema

Returns a new instance of Schema.



30
31
32
33
# File 'lib/kiwi/schema.rb', line 30

def initialize(definitions)
  @definitions = definitions
  instance_eval Compiler.compile(self)
end

Class Method Details

.from_binary(bytes) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kiwi/schema.rb', line 5

def self.from_binary(bytes)
  defs = []
  bb = ByteBuffer.new(bytes)
  definition_count = bb.read_var_uint

  (0...definition_count).each do
    type_name = bb.read_string
    kind = bb.read_byte
    field_count = bb.read_var_uint
    fields = []

    (0...(field_count)).each do |field|
      name = bb.read_string
      type_id = bb.read_var_int
      is_array = bb.read_bool
      value = bb.read_var_uint
      fields << Field.new(name: name, type_id: type_id, is_array: is_array, value: value)
    end

    defs << Definition.new(name: type_name, kind: kind, fields: fields)
  end

  Kiwi::Schema.new(defs)
end

Instance Method Details

#definitionsObject



35
36
37
# File 'lib/kiwi/schema.rb', line 35

def definitions
  @definitions
end