Class: BareTypes::Optional
Overview
endregion
Instance Method Summary collapse
- #==(otherType) ⇒ Object
- #decode(msg) ⇒ Object
- #encode(msg, buffer) ⇒ Object
- #finalize_references(schema) ⇒ Object
-
#initialize(optionalType) ⇒ Optional
constructor
A new instance of Optional.
- #optionalType ⇒ Object
- #to_schema(buffer) ⇒ Object
Methods inherited from BaseType
Constructor Details
#initialize(optionalType) ⇒ Optional
Returns a new instance of Optional.
421 422 423 424 |
# File 'lib/types.rb', line 421 def initialize(optionalType) raise VoidUsedOutsideTaggedSet() if optionalType.class == BareTypes::Void @optionalType = optionalType end |
Instance Method Details
#==(otherType) ⇒ Object
397 398 399 |
# File 'lib/types.rb', line 397 def ==(otherType) return otherType.class == BareTypes::Optional && otherType.optionalType == @optionalType end |
#decode(msg) ⇒ Object
435 436 437 438 439 440 441 |
# File 'lib/types.rb', line 435 def decode(msg) if msg.unpack("C")[0] == 0 return nil, msg[1..msg.size] else return @optionalType.decode(msg[1..msg.size]) end end |
#encode(msg, buffer) ⇒ Object
426 427 428 429 430 431 432 433 |
# File 'lib/types.rb', line 426 def encode(msg, buffer) if msg.nil? buffer << "\x00".b else buffer << "\x01".b @optionalType.encode(msg, buffer) end end |
#finalize_references(schema) ⇒ Object
407 408 409 410 411 412 413 414 415 |
# File 'lib/types.rb', line 407 def finalize_references(schema) return if @finalized @finalized = true if @optionalType.is_a?(Symbol) @optionalType = Reference.new(@optionalType, schema[@optionalType]) else @optionalType.finalize_references(schema) end end |
#optionalType ⇒ Object
417 418 419 |
# File 'lib/types.rb', line 417 def optionalType @optionalType end |
#to_schema(buffer) ⇒ Object
401 402 403 404 405 |
# File 'lib/types.rb', line 401 def to_schema(buffer) buffer << "optional<" @optionalType.to_schema(buffer) buffer << ">" end |