Module: Google::Protobuf

Defined in:
lib/google/protobuf.rb,
lib/google/protobuf_ffi.rb,
lib/google/protobuf/any_pb.rb,
lib/google/protobuf/api_pb.rb,
lib/google/protobuf/ffi/ffi.rb,
lib/google/protobuf/ffi/map.rb,
lib/google/protobuf/type_pb.rb,
lib/google/protobuf/empty_pb.rb,
lib/google/protobuf/plugin_pb.rb,
lib/google/protobuf/struct_pb.rb,
lib/google/protobuf/duration_pb.rb,
lib/google/protobuf/ffi/message.rb,
lib/google/protobuf/wrappers_pb.rb,
lib/google/protobuf/message_exts.rb,
lib/google/protobuf/timestamp_pb.rb,
lib/google/protobuf/descriptor_pb.rb,
lib/google/protobuf/field_mask_pb.rb,
lib/google/protobuf/ffi/descriptor.rb,
lib/google/protobuf/repeated_field.rb,
lib/google/protobuf/ffi/object_cache.rb,
lib/google/protobuf/well_known_types.rb,
lib/google/protobuf/source_context_pb.rb,
lib/google/protobuf/ffi/internal/arena.rb,
lib/google/protobuf/ffi/repeated_field.rb,
lib/google/protobuf/ffi/descriptor_pool.rb,
lib/google/protobuf/ffi/enum_descriptor.rb,
lib/google/protobuf/ffi/file_descriptor.rb,
lib/google/protobuf/ffi/field_descriptor.rb,
lib/google/protobuf/ffi/internal/convert.rb,
lib/google/protobuf/ffi/oneof_descriptor.rb,
lib/google/protobuf/ffi/method_descriptor.rb,
lib/google/protobuf/internal/object_cache.rb,
lib/google/protobuf/ffi/service_descriptor.rb,
lib/google/protobuf/ffi/internal/type_safety.rb,
lib/google/protobuf/ffi/internal/pointer_helper.rb,
ext/google/protobuf_c/protobuf.c

Defined Under Namespace

Modules: Compiler, Internal, MessageExts Classes: Descriptor, DescriptorPool, EnumDescriptor, Error, FFI, FieldDescriptor, FileDescriptor, Map, MethodDescriptor, OneofDescriptor, ParseError, RepeatedField, ServiceDescriptor, TypeError, UnexpectedStructType

Constant Summary collapse

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
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
Any =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Any").msgclass
Api =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Api").msgclass
Method =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Method").msgclass
Mixin =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Mixin").msgclass
Type =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Type").msgclass
Field =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field").msgclass
Enum =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Enum").msgclass
EnumValue =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValue").msgclass
Option =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Option").msgclass
Syntax =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Syntax").enummodule
Empty =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Empty").msgclass
Struct =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Struct").msgclass
Value =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Value").msgclass
ListValue =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ListValue").msgclass
NullValue =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.NullValue").enummodule
Duration =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Duration").msgclass
DoubleValue =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DoubleValue").msgclass
FloatValue =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FloatValue").msgclass
Int64Value =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int64Value").msgclass
UInt64Value =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt64Value").msgclass
Int32Value =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int32Value").msgclass
UInt32Value =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt32Value").msgclass
BoolValue =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BoolValue").msgclass
StringValue =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.StringValue").msgclass
BytesValue =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BytesValue").msgclass
Timestamp =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Timestamp").msgclass
FileDescriptorSet =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileDescriptorSet").msgclass
FileDescriptorProto =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileDescriptorProto").msgclass
DescriptorProto =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DescriptorProto").msgclass
ExtensionRangeOptions =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ExtensionRangeOptions").msgclass
FieldDescriptorProto =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldDescriptorProto").msgclass
OneofDescriptorProto =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.OneofDescriptorProto").msgclass
EnumDescriptorProto =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumDescriptorProto").msgclass
EnumValueDescriptorProto =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValueDescriptorProto").msgclass
ServiceDescriptorProto =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ServiceDescriptorProto").msgclass
MethodDescriptorProto =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodDescriptorProto").msgclass
FileOptions =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileOptions").msgclass
MessageOptions =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MessageOptions").msgclass
FieldOptions =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions").msgclass
OneofOptions =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.OneofOptions").msgclass
EnumOptions =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumOptions").msgclass
EnumValueOptions =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValueOptions").msgclass
ServiceOptions =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ServiceOptions").msgclass
MethodOptions =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodOptions").msgclass
UninterpretedOption =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UninterpretedOption").msgclass
FeatureSet =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FeatureSet").msgclass
FeatureSetDefaults =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FeatureSetDefaults").msgclass
SourceCodeInfo =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceCodeInfo").msgclass
GeneratedCodeInfo =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.GeneratedCodeInfo").msgclass
Edition =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Edition").enummodule
FieldMask =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldMask").msgclass
OBJECT_CACHE =
cache_implementation.new
SourceContext =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceContext").msgclass

Class Method Summary collapse

Class Method Details

.decode(klass, proto, options = {}) ⇒ Object



38
39
40
# File 'lib/google/protobuf.rb', line 38

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

.decode_json(klass, json, options = {}) ⇒ Object



42
43
44
# File 'lib/google/protobuf.rb', line 42

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

.Google::Protobuf.deep_copy(obj) ⇒ Object

Performs a deep copy of a RepeatedField instance, a Map instance, or a message object, recursively copying its members.



305
306
307
308
309
310
311
312
313
314
315
316
# File 'ext/google/protobuf_c/protobuf.c', line 305

def self.deep_copy(object)
  case object
  when RepeatedField
    RepeatedField.send(:deep_copy, object)
  when Google::Protobuf::Map
    Google::Protobuf::Map.deep_copy(object)
  when Google::Protobuf::MessageExts
    object.class.send(:deep_copy, object.instance_variable_get(:@msg))
  else
    raise NotImplementedError
  end
end

.Google::Protobuf.discard_unknown(msg) ⇒ Object

Discard unknown fields in the given message object and recursively discard unknown fields in submessages.



288
289
290
291
292
293
294
295
# File 'ext/google/protobuf_c/protobuf.c', line 288

def self.discard_unknown(message)
  raise FrozenError if message.frozen?
  raise ArgumentError.new "Expected message, got #{message.class} instead." if message.instance_variable_get(:@msg).nil?
  unless Google::Protobuf::FFI.message_discard_unknown(message.instance_variable_get(:@msg), message.class.descriptor, 128)
    raise RuntimeError.new "Messages nested too deeply."
  end
  nil
end

.encode(msg, options = {}) ⇒ Object



30
31
32
# File 'lib/google/protobuf.rb', line 30

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

.encode_json(msg, options = {}) ⇒ Object



34
35
36
# File 'lib/google/protobuf.rb', line 34

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