Method: Puppet::Pops::Serialization::Deserializer#read

Defined in:
lib/puppet/pops/serialization/deserializer.rb

#readObject

Read the next value from the reader.

Returns:

  • (Object)

    the value that was read



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/puppet/pops/serialization/deserializer.rb', line 26

def read
  val = @reader.read
  case val
  when Extension::Tabulation
    @read[val.index]
  when Extension::Default
    :default
  when Extension::ArrayStart
    result = remember([])
    val.size.times { result << read }
    result
  when Extension::MapStart
    result = remember({})
    val.size.times { key = read; result[key] = read }
    result
  when Extension::SensitiveStart
    Types::PSensitiveType::Sensitive.new(read)
  when Extension::PcoreObjectStart
    type_name = val.type_name
    type = Types::TypeParser.singleton.parse(type_name, @loader)
    raise SerializationError, _("No implementation mapping found for Puppet Type %{type_name}") % { type_name: type_name } if type.is_a?(Types::PTypeReferenceType)
    result = type.read(val.attribute_count, self)
    if result.is_a?(Types::PObjectType)
      existing_type = loader.load(:type, result.name)
      if result.eql?(existing_type)
        result = existing_type
      else
        # Add result to the loader unless it is equal to the existing_type. The add
        # will only succeed when the existing_type is nil.
        loader.add_entry(:type, result.name, result, nil)
      end
    end
    result
  when Extension::ObjectStart
    type = read
    type.read(val.attribute_count - 1, self)
  when Numeric, String, true, false, nil
    val
  else
    remember(val)
  end
end