Class: ProtocolBuffers::Field::AggregateField
- Inherits:
-
ProtocolBuffers::Field
- Object
- ProtocolBuffers::Field
- ProtocolBuffers::Field::AggregateField
- Defined in:
- lib/protocol_buffers/runtime/field.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#proxy_class ⇒ Object
readonly
Returns the value of attribute proxy_class.
Attributes inherited from ProtocolBuffers::Field
Instance Method Summary collapse
- #default_value ⇒ Object
- #deserialize(io) ⇒ Object
-
#initialize(proxy_class, otype, name, tag, opts = {}) ⇒ AggregateField
constructor
A new instance of AggregateField.
-
#serialize(value) ⇒ Object
TODO: serialize could be more efficient if it used the underlying stream directly rather than string copying, but that would require knowing the length beforehand.
- #text_format(io, value, options = nil) ⇒ Object
- #valid_type?(value) ⇒ Boolean
Methods inherited from ProtocolBuffers::Field
#add_methods_to, #add_reader_to, #add_writer_to, #check_valid, #check_value, create, #inspect_value, #packed?, #repeated?
Constructor Details
#initialize(proxy_class, otype, name, tag, opts = {}) ⇒ AggregateField
Returns a new instance of AggregateField.
620 621 622 623 |
# File 'lib/protocol_buffers/runtime/field.rb', line 620 def initialize(proxy_class, otype, name, tag, opts = {}) super(otype, name, tag, opts) @proxy_class = proxy_class end |
Instance Attribute Details
#proxy_class ⇒ Object (readonly)
Returns the value of attribute proxy_class.
618 619 620 |
# File 'lib/protocol_buffers/runtime/field.rb', line 618 def proxy_class @proxy_class end |
Instance Method Details
#default_value ⇒ Object
625 626 627 |
# File 'lib/protocol_buffers/runtime/field.rb', line 625 def default_value @proxy_class.new end |
#deserialize(io) ⇒ Object
640 641 642 |
# File 'lib/protocol_buffers/runtime/field.rb', line 640 def deserialize(io) @proxy_class.parse(io) end |
#serialize(value) ⇒ Object
TODO: serialize could be more efficient if it used the underlying stream directly rather than string copying, but that would require knowing the length beforehand.
636 637 638 |
# File 'lib/protocol_buffers/runtime/field.rb', line 636 def serialize(value) value.to_s end |
#text_format(io, value, options = nil) ⇒ Object
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 |
# File 'lib/protocol_buffers/runtime/field.rb', line 644 def text_format(io, value, = nil) = .dup [:nest] ||= 0 if [:short] indent = "" newline = " " else indent = " " * [:nest] newline = "\n" end [:nest] += 1 io.write "{#{newline}" value.text_format(io, ) io.write " " if [:short] io.write "#{indent}}" end |
#valid_type?(value) ⇒ Boolean
629 630 631 |
# File 'lib/protocol_buffers/runtime/field.rb', line 629 def valid_type?(value) value.is_a?(@proxy_class) end |