···152152 instance_variables - [:@type_object, :@data_object, :@blocks]
153153 end
154154155155- # Checks if all required fields are set in the data object.
156156- # @param fields [Array<String>] list of fields to check
157157- # @raise [DecodeError] if any of the fields is nil or not set
158158- def check_if_not_nil(fields)
159159- missing = fields.select { |f| @data_object[f].nil? }
160155161161- raise DecodeError.new("Missing event details (#{missing.map(&:to_s).join(', ')})") if missing.length > 0
162162- end
156156+ private
163157158158+ # Note: this method is written this way as an optimization
159159+ def check_if_not_nil(a, b = nil, c = nil, d = nil, e = nil, f = nil)
160160+ ok = @data_object.has_key?(a)
161161+ ok &&= @data_object.has_key?(b) if b
162162+ ok &&= @data_object.has_key?(c) if c
163163+ ok &&= @data_object.has_key?(d) if d
164164+ ok &&= @data_object.has_key?(e) if e
165165+ ok &&= @data_object.has_key?(f) if f
164166165165- private
167167+ if !ok
168168+ expected_fields = [a, b, c, d, e, f].compact
169169+ missing_fields = expected_fields.select { |x| @data_object[x].nil? }
170170+ raise DecodeError.new("Missing event details (#{missing_fields.map(&:to_s).join(', ')})")
171171+ end
172172+ end
166173167174 def self.decode_cbor_objects(data)
168175 objects = CBOR.decode_sequence(data)