Class: Protobuf::Field::BytesField
- Defined in:
- lib/protobuf/field/bytes_field.rb
Direct Known Subclasses
Constant Summary collapse
- BYTES_ENCODING =
Constants
"ASCII-8BIT".freeze
Constants inherited from BaseField
Protobuf::Field::BaseField::PACKED_TYPES
Instance Attribute Summary
Attributes inherited from BaseField
#default, #default_value, #deprecated, #extension, #getter_method_name, #message_class, #name, #optional, #packed, #repeated, #required, #rule, #setter_method_name, #tag, #type_class
Class Method Summary collapse
-
.default ⇒ Object
Class Methods.
Instance Method Summary collapse
-
#acceptable?(val) ⇒ Boolean
Public Instance Methods.
- #decode(bytes) ⇒ Object
- #encode(value) ⇒ Object
- #wire_type ⇒ Object
Methods inherited from BaseField
#deprecated?, #enum?, #extension?, #initialize, #message?, #optional?, #packed?, #repeated?, #repeated_message?, #required?, #set, #to_s, #type, #warn_if_deprecated
Constructor Details
This class inherits a constructor from Protobuf::Field::BaseField
Class Method Details
.default ⇒ Object
Class Methods
17 18 19 |
# File 'lib/protobuf/field/bytes_field.rb', line 17 def self.default '' end |
Instance Method Details
#acceptable?(val) ⇒ Boolean
Public Instance Methods
25 26 27 |
# File 'lib/protobuf/field/bytes_field.rb', line 25 def acceptable?(val) val.nil? || val.is_a?(String) || val.is_a?(Symbol) || val.is_a?(::Protobuf::Message) end |
#decode(bytes) ⇒ Object
29 30 31 32 33 |
# File 'lib/protobuf/field/bytes_field.rb', line 29 def decode(bytes) bytes_to_decode = bytes.dup bytes_to_decode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) bytes_to_decode end |
#encode(value) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/protobuf/field/bytes_field.rb', line 35 def encode(value) value_to_encode = value.dup value_to_encode = value.encode if value.is_a?(::Protobuf::Message) value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) string_size << value_to_encode end |
#wire_type ⇒ Object
44 45 46 |
# File 'lib/protobuf/field/bytes_field.rb', line 44 def wire_type ::Protobuf::WireType::LENGTH_DELIMITED end |