Sha256: 147f4f143eae500b892e8a58266b0cfbae3bbcab8f75ea89b47a50ae4e720eb3

Contents?: true

Size: 1.86 KB

Versions: 110

Compression:

Stored size: 1.86 KB

Contents

# Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc.  All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd

# require mixins before we hook them into the java & c code
require 'google/protobuf/message_exts'
require 'google/protobuf/object_cache'

# We define these before requiring the platform-specific modules.
# That way the module init can grab references to these.
module Google
  module Protobuf
    class Error < StandardError; end
    class ParseError < Error; end
    class TypeError < ::TypeError; end

    PREFER_FFI = case ENV['PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION']
                 when nil, "", /^native$/i
                   false
                 when /^ffi$/i
                   true
                 else
                   warn "Unexpected value `#{ENV['PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION']}` for environment variable `PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION`. Should be either \"FFI\", \"NATIVE\"."
                   false
                 end

    def self.encode(msg, options = {})
      msg.to_proto(options)
    end

    def self.encode_json(msg, options = {})
      msg.to_json(options)
    end

    def self.decode(klass, proto, options = {})
      klass.decode(proto, options)
    end

    def self.decode_json(klass, json, options = {})
      klass.decode_json(json, options)
    end

    IMPLEMENTATION = if PREFER_FFI
      begin
        require 'google/protobuf_ffi'
        :FFI
      rescue LoadError
        warn "Caught exception `#{$!.message}` while loading FFI implementation of google/protobuf."
        warn "Falling back to native implementation."
        require 'google/protobuf_native'
        :NATIVE
      end
    else
      require 'google/protobuf_native'
      :NATIVE
    end
  end
end

Version data entries

110 entries across 110 versions & 1 rubygems

Version Path
google-protobuf-3.25.6-java lib/google/protobuf.rb
google-protobuf-3.25.6 lib/google/protobuf.rb
google-protobuf-3.25.6-x86_64-linux lib/google/protobuf.rb
google-protobuf-3.25.6-x86_64-darwin lib/google/protobuf.rb
google-protobuf-3.25.6-x86-mingw32 lib/google/protobuf.rb
google-protobuf-3.25.6-x86-linux lib/google/protobuf.rb
google-protobuf-3.25.6-x64-mingw32 lib/google/protobuf.rb
google-protobuf-3.25.6-x64-mingw-ucrt lib/google/protobuf.rb
google-protobuf-3.25.6-arm64-darwin lib/google/protobuf.rb
google-protobuf-3.25.6-aarch64-linux lib/google/protobuf.rb
google-protobuf-3.25.5-java lib/google/protobuf.rb
google-protobuf-3.25.5 lib/google/protobuf.rb
google-protobuf-3.25.5-x86_64-linux lib/google/protobuf.rb
google-protobuf-3.25.5-x86_64-darwin lib/google/protobuf.rb
google-protobuf-3.25.5-x86-mingw32 lib/google/protobuf.rb
google-protobuf-3.25.5-x86-linux lib/google/protobuf.rb
google-protobuf-3.25.5-x64-mingw32 lib/google/protobuf.rb
google-protobuf-3.25.5-x64-mingw-ucrt lib/google/protobuf.rb
google-protobuf-3.25.5-arm64-darwin lib/google/protobuf.rb
google-protobuf-3.25.5-aarch64-linux lib/google/protobuf.rb