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.
34 35 36 |
# File 'lib/protobuf/message/serialization.rb', line 34 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.
40 41 42 43 44 45 46 |
# 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 |
#encode ⇒ Object Also known as: to_s, bytes, serialize, serialize_to_string
Encode this message
50 51 52 53 54 55 |
# 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 |