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
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
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
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
Private Instance Methods
field_must_be_serialized?(field)
click to toggle source
# File lib/protobuf/message/serialization.rb, line 78 def field_must_be_serialized?(field) field.required? || ! @values[field.name].nil? end
set_field_bytes(tag, bytes)
click to toggle source
# File lib/protobuf/message/serialization.rb, line 82 def set_field_bytes(tag, bytes) field = self.class.get_field(tag, true) field.set(self, bytes) if field end