lib/protobuf/message/serialization.rb in protobuf-3.3.6 vs lib/protobuf/message/serialization.rb in protobuf-3.4.0

- old
+ new

@@ -6,16 +6,16 @@ class Message module Serialization module ClassMethods def decode(bytes) - self.new.decode(bytes) + new.decode(bytes) end # Create a new object with the given values and return the encoded bytes. def encode(fields = {}) - self.new(fields).encode + new(fields).encode end end def self.included(other) other.extend(ClassMethods) @@ -42,12 +42,14 @@ end # Encode this message # def encode - stream = ::StringIO.new.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - encode_to(stream).string + stream = ::StringIO.new + stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + encode_to(stream) + stream.string end # Encode this message to the given stream. # def encode_to(stream) @@ -79,6 +81,5 @@ end end end end -