adding and simplifying encoders/decoders
* make consistent between mri and jruby
* create a #to_h and have it use symbols for keys
* add #to_json and #to_proto helpers on the Google::Protobuf message classes
diff --git a/ruby/lib/google/protobuf.rb b/ruby/lib/google/protobuf.rb
index 7279724..99b1792 100644
--- a/ruby/lib/google/protobuf.rb
+++ b/ruby/lib/google/protobuf.rb
@@ -28,6 +28,9 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# require mixins before we hook them into the java & c code
+require 'google/protobuf/message_exts'
+
if RUBY_PLATFORM == "java"
require 'json'
require 'google/protobuf_java'
@@ -36,3 +39,25 @@
end
require 'google/protobuf/repeated_field'
+
+module Google
+ module Protobuf
+
+ def self.encode(msg)
+ msg.to_proto
+ end
+
+ def self.encode_json(msg)
+ msg.to_json
+ end
+
+ def self.decode(klass, proto)
+ klass.decode(proto)
+ end
+
+ def self.decode_json(klass, json)
+ klass.decode_json(json)
+ end
+
+ end
+end