Class: Protopuffs::String
- Inherits:
-
LengthDelimited
- Object
- MessageField
- LengthDelimited
- Protopuffs::String
- Defined in:
- lib/protopuffs/message/field.rb
Instance Attribute Summary
Attributes inherited from MessageField
Class Method Summary collapse
Instance Method Summary collapse
- #decode(bytes) ⇒ Object
-
#initialize(modifier, identifier, tag, default = nil) ⇒ String
constructor
A new instance of String.
Methods inherited from LengthDelimited
Methods inherited from MessageField
factory, #key, #optional?, #repeated?, shift_tag, #to_wire_format_with_value
Constructor Details
#initialize(modifier, identifier, tag, default = nil) ⇒ String
Returns a new instance of String.
182 183 184 |
# File 'lib/protopuffs/message/field.rb', line 182 def initialize(modifier, identifier, tag, default = nil) super(modifier, identifier, tag, default || "") end |
Class Method Details
.encode(value) ⇒ Object
185 186 187 188 189 190 191 |
# File 'lib/protopuffs/message/field.rb', line 185 def self.encode(value) value = value.to_s value.force_encoding("UTF-8") if value.respond_to?(:force_encoding) # Use #bytesize in Ruby 1.9, and #size in Ruby 1.8 size = value.respond_to?(:bytesize) ? value.bytesize : value.size VarInt.encode(size) + value end |
Instance Method Details
#decode(bytes) ⇒ Object
192 193 194 |
# File 'lib/protopuffs/message/field.rb', line 192 def decode(bytes) bytes.respond_to?(:force_encoding) ? bytes.force_encoding("UTF-8") : bytes end |