message.h 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #ifndef RUBY_PROTOBUF_MESSAGE_H_
  31. #define RUBY_PROTOBUF_MESSAGE_H_
  32. #include <ruby/ruby.h>
  33. #include "protobuf.h"
  34. #include "ruby-upb.h"
  35. // Gets the underlying upb_msg* and upb_msgdef for the given Ruby message
  36. // wrapper. Requires that |value| is indeed a message object.
  37. const upb_msg *Message_Get(VALUE value, const upb_msgdef **m);
  38. // Like Message_Get(), but checks that the object is not frozen and returns a
  39. // mutable pointer.
  40. upb_msg *Message_GetMutable(VALUE value, const upb_msgdef **m);
  41. // Returns the Arena object for this message.
  42. VALUE Message_GetArena(VALUE value);
  43. // Converts |value| into a upb_msg value of the expected upb_msgdef type,
  44. // raising an error if this is not possible. Used when assigning |value| to a
  45. // field of another message, which means the message must be of a particular
  46. // type.
  47. //
  48. // This will perform automatic conversions in some cases (for example, Time ->
  49. // Google::Protobuf::Timestamp). If any new message is created, it will be
  50. // created on |arena|, and any existing message will have its arena fused with
  51. // |arena|.
  52. const upb_msg* Message_GetUpbMessage(VALUE value, const upb_msgdef* m,
  53. const char* name, upb_arena* arena);
  54. // Gets or constructs a Ruby wrapper object for the given message. The wrapper
  55. // object will reference |arena| and ensure that it outlives this object.
  56. VALUE Message_GetRubyWrapper(upb_msg* msg, const upb_msgdef* m, VALUE arena);
  57. // Implements #inspect for this message, printing the text to |b|.
  58. void Message_PrintMessage(StringBuilder* b, const upb_msg* msg,
  59. const upb_msgdef* m);
  60. // Returns a hash value for the given message.
  61. uint64_t Message_Hash(const upb_msg *msg, const upb_msgdef *m, uint64_t seed);
  62. // Returns a deep copy of the given message.
  63. upb_msg* Message_deep_copy(const upb_msg* msg, const upb_msgdef* m,
  64. upb_arena *arena);
  65. // Returns true if these two messages are equal.
  66. bool Message_Equal(const upb_msg *m1, const upb_msg *m2, const upb_msgdef *m);
  67. // Checks that this Ruby object is a message, and raises an exception if not.
  68. void Message_CheckClass(VALUE klass);
  69. // Returns a new Hash object containing the contents of this message.
  70. VALUE Scalar_CreateHash(upb_msgval val, TypeInfo type_info);
  71. // Creates a message class or enum module for this descriptor, respectively.
  72. VALUE build_class_from_descriptor(VALUE descriptor);
  73. VALUE build_module_from_enumdesc(VALUE _enumdesc);
  74. // Returns the Descriptor/EnumDescriptor for the given message class or enum
  75. // module, respectively. Returns nil if this is not a message class or enum
  76. // module.
  77. VALUE MessageOrEnum_GetDescriptor(VALUE klass);
  78. // Call at startup to register all types in this module.
  79. void Message_register(VALUE protobuf);
  80. #endif // RUBY_PROTOBUF_MESSAGE_H_