Class: Protobuf::Field::BaseFieldObjectDefinitions::StringEncodeToStream
- Inherits:
-
Object
- Object
- Protobuf::Field::BaseFieldObjectDefinitions::StringEncodeToStream
- Defined in:
- lib/protobuf/field/base_field_object_definitions.rb
Instance Method Summary collapse
- #call(value, stream) ⇒ Object
-
#initialize(selph) ⇒ StringEncodeToStream
constructor
A new instance of StringEncodeToStream.
Constructor Details
#initialize(selph) ⇒ StringEncodeToStream
Returns a new instance of StringEncodeToStream.
76 77 78 79 |
# File 'lib/protobuf/field/base_field_object_definitions.rb', line 76 def initialize(selph) @selph = selph @tag_encoded = selph.tag_encoded end |
Instance Method Details
#call(value, stream) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/protobuf/field/base_field_object_definitions.rb', line 81 def call(value, stream) new_value = "" + value if new_value.encoding != ::Protobuf::Field::StringField::ENCODING new_value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") end stream << @tag_encoded << ::Protobuf::Field::VarintField.encode(new_value.bytesize) << new_value end |