File: protobuf_ffi.rb

package info (click to toggle)
protobuf 3.25.4-4
  • links: PTS
  • area: main
  • in suites: experimental
  • size: 45,992 kB
  • sloc: cpp: 204,199; java: 87,622; ansic: 81,204; objc: 58,434; cs: 27,303; python: 22,799; php: 11,340; ruby: 8,637; pascal: 3,324; xml: 2,333; sh: 1,331; makefile: 538; lisp: 86; awk: 17
file content (50 lines) | stat: -rw-r--r-- 1,854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Protocol Buffers - Google's data interchange format
# Copyright 2023 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 'ffi-compiler/loader'
require 'google/protobuf/ffi/ffi'
require 'google/protobuf/ffi/internal/type_safety'
require 'google/protobuf/ffi/internal/pointer_helper'
require 'google/protobuf/ffi/internal/arena'
require 'google/protobuf/ffi/internal/convert'
require 'google/protobuf/ffi/descriptor'
require 'google/protobuf/ffi/enum_descriptor'
require 'google/protobuf/ffi/field_descriptor'
require 'google/protobuf/ffi/oneof_descriptor'
require 'google/protobuf/ffi/descriptor_pool'
require 'google/protobuf/ffi/file_descriptor'
require 'google/protobuf/ffi/map'
require 'google/protobuf/ffi/object_cache'
require 'google/protobuf/ffi/repeated_field'
require 'google/protobuf/ffi/message'
require 'google/protobuf/descriptor_dsl'

module Google
  module Protobuf
    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

    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
  end
end