Class: Protopuffs::Embedded

Inherits:
LengthDelimited show all
Defined in:
lib/protopuffs/message/field.rb

Instance Attribute Summary

Attributes inherited from MessageField

#default, #identifier, #tag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LengthDelimited

shift, wire_type

Methods inherited from MessageField

factory, #key, #optional?, #repeated?, shift_tag, #to_wire_format_with_value

Constructor Details

#initialize(type, modifier, identifier, tag, default = nil) ⇒ Embedded

Returns a new instance of Embedded.



210
211
212
213
# File 'lib/protopuffs/message/field.rb', line 210

def initialize(type, modifier, identifier, tag, default = nil)
  @type = type
  super(modifier, identifier, tag, default)
end

Class Method Details

.encode(value) ⇒ Object



219
220
221
222
# File 'lib/protopuffs/message/field.rb', line 219

def self.encode(value)
  embedded_bytes = value.to_wire_format
  VarInt.encode(embedded_bytes.size) + embedded_bytes
end

Instance Method Details

#decode(bytes) ⇒ Object



214
215
216
217
218
# File 'lib/protopuffs/message/field.rb', line 214

def decode(bytes)
  bytes.force_encoding("BINARY") if bytes.respond_to?(:force_encoding)
  value = Message.const_get(@type.delete("_")).new
  value.from_wire_format(StringIO.new(bytes))
end