Module: Protobuf::Message::Serialization
- Included in:
- Protobuf::Message
- Defined in:
- lib/protobuf/message/serialization.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#decode(bytes) ⇒ Object
(also: #parse_from_string, #deserialize)
Decode the given non-stream bytes into this message.
-
#decode_from(stream) ⇒ Object
(also: #parse_from, #deserialize_from)
Decode the given stream into this message.
-
#encode ⇒ Object
(also: #to_s, #bytes, #serialize, #serialize_to_string)
Encode this message.
-
#encode_to(stream) ⇒ Object
(also: #serialize_to)
Encode this message to the given stream.
Instance Method Details
#decode(bytes) ⇒ Object Also known as: parse_from_string, deserialize
Decode the given non-stream bytes into this message.
30 31 32 |
# File 'lib/protobuf/message/serialization.rb', line 30 def decode(bytes) decode_from(::StringIO.new(bytes)) end |
#decode_from(stream) ⇒ Object Also known as: parse_from, deserialize_from
Decode the given stream into this message.
36 37 38 39 40 41 42 |
# File 'lib/protobuf/message/serialization.rb', line 36 def decode_from(stream) ::Protobuf::Decoder.decode_each_field(stream) do |tag, bytes| set_field_bytes(tag, bytes) end self end |
#encode ⇒ Object Also known as: to_s, bytes, serialize, serialize_to_string
Encode this message
46 47 48 49 |
# File 'lib/protobuf/message/serialization.rb', line 46 def encode stream = ::StringIO.new.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) encode_to(stream).string end |