module Protobuf::Message::Serialization

Public Class Methods

included(other) click to toggle source
# File lib/protobuf/message/serialization.rb, line 24
def self.included(other)
  other.extend(ClassMethods)
end

Public Instance Methods

bytes()
Alias for: encode
decode(bytes) click to toggle source

Decode the given non-stream bytes into this message.

# File lib/protobuf/message/serialization.rb, line 34
def decode(bytes)
  decode_from(::StringIO.new(bytes))
end
Also aliased as: parse_from_string, deserialize
decode_from(stream) click to toggle source

Decode the given stream into this message.

# File lib/protobuf/message/serialization.rb, line 40
def decode_from(stream)
  ::Protobuf::Decoder.decode_each_field(stream) do |tag, bytes|
    set_field_bytes(tag, bytes)
  end

  self
end
Also aliased as: parse_from, deserialize_from
deserialize(bytes)
Alias for: decode
deserialize_from(stream)
Alias for: decode_from
encode() click to toggle source

Encode this message

# File lib/protobuf/message/serialization.rb, line 50
def encode
  stream = ::StringIO.new
  stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING)
  encode_to(stream)
  stream.string
end
Also aliased as: to_s, bytes, serialize, serialize_to_string
encode_to(stream) click to toggle source

Encode this message to the given stream.

# File lib/protobuf/message/serialization.rb, line 59
def encode_to(stream)
  ::Protobuf::Encoder.encode(self, stream)
end
Also aliased as: serialize_to
parse_from(stream)
Alias for: decode_from
parse_from_string(bytes)

Instance Aliases

Alias for: decode
serialize()
Alias for: encode
serialize_to(stream)
Alias for: encode_to
serialize_to_string()
Alias for: encode
to_s()
Alias for: encode

Private Instance Methods

set_field_bytes(tag, bytes) click to toggle source
# File lib/protobuf/message/serialization.rb, line 78
def set_field_bytes(tag, bytes)
  field = self.class.get_field(tag, true)
  field.set(self, bytes) if field
end