Class: Protobuf::Field::BytesField

Inherits:
BaseField
  • Object
show all
Defined in:
lib/protobuf/message/field.rb

Direct Known Subclasses

StringField

Instance Attribute Summary

Attributes inherited from BaseField

#default, #message_class, #name, #rule, #tag, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseField

#clear, #default_value, #descriptor, descriptor, #error_message, #get, #initialize, #initialized?, #max, #merge, #merge_array, #merge_value, #min, #optional?, #ready?, #repeated?, #required?, #set, #to_s, #typed_default_value

Constructor Details

This class inherits a constructor from Protobuf::Field::BaseField

Class Method Details

.defaultObject



279
# File 'lib/protobuf/message/field.rb', line 279

def default; '' end

Instance Method Details

#acceptable?(val) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (TypeError)


286
287
288
289
# File 'lib/protobuf/message/field.rb', line 286

def acceptable?(val)
  raise TypeError unless val.instance_of? String
  true
end

#decode(bytes) ⇒ Object



291
292
293
# File 'lib/protobuf/message/field.rb', line 291

def decode(bytes)
  bytes.pack('C*')
end

#encode(value) ⇒ Object



295
296
297
298
299
300
# File 'lib/protobuf/message/field.rb', line 295

def encode(value)
  value = value.dup
  value.force_encoding('ASCII-8BIT') if value.respond_to?(:force_encoding)
  string_size = VarintField.encode(value.size)
  string_size << value
end

#wire_typeObject



282
283
284
# File 'lib/protobuf/message/field.rb', line 282

def wire_type
  Protobuf::WireType::LENGTH_DELIMITED
end