• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #ifndef RUBY_PROTOBUF_CONVERT_H_
9 #define RUBY_PROTOBUF_CONVERT_H_
10 
11 #include "protobuf.h"
12 #include "ruby-upb.h"
13 
14 // Converts |ruby_val| to a upb_MessageValue according to |type_info|.
15 //
16 // The |arena| parameter indicates the lifetime of the container where this
17 // value will be assigned. It is used as follows:
18 // - If type is string or bytes, the string data will be copied into |arena|.
19 // - If type is message, and we need to auto-construct a message due to implicit
20 //   conversions (eg. Time -> Google::Protobuf::Timestamp), the new message
21 //   will be created in |arena|.
22 // - If type is message and the Ruby value is a message instance, we will fuse
23 //   the message's arena into |arena|, to ensure that this message outlives the
24 //   container.
25 upb_MessageValue Convert_RubyToUpb(VALUE ruby_val, const char *name,
26                                    TypeInfo type_info, upb_Arena *arena);
27 
28 // Converts |upb_val| to a Ruby VALUE according to |type_info|. This may involve
29 // creating a Ruby wrapper object.
30 //
31 // The |arena| parameter indicates the arena that owns the lifetime of
32 // |upb_val|. Any Ruby wrapper object that is created will reference |arena|
33 // and ensure it outlives the wrapper.
34 VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info,
35                         VALUE arena);
36 
37 // Creates a deep copy of |msgval| in |arena|.
38 upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info,
39                                  upb_Arena *arena);
40 
41 // Returns true if |val1| and |val2| are equal. Their type is given by
42 // |type_info|.
43 bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
44                     TypeInfo type_info);
45 
46 // Returns a hash value for the given upb_MessageValue.
47 uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
48                         uint64_t seed);
49 
50 #endif  // RUBY_PROTOBUF_CONVERT_H_
51