generated_message_table_driven_lite.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include <google/protobuf/generated_message_table_driven_lite.h>
  31. #include <type_traits>
  32. #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
  33. #include <google/protobuf/metadata_lite.h>
  34. #include <google/protobuf/repeated_field.h>
  35. #include <google/protobuf/wire_format_lite.h>
  36. #include <google/protobuf/wire_format_lite_inl.h>
  37. namespace google {
  38. namespace protobuf {
  39. namespace internal {
  40. namespace {
  41. string* MutableUnknownFields(MessageLite* msg, int64 arena_offset) {
  42. return Raw<InternalMetadataWithArenaLite>(msg, arena_offset)
  43. ->mutable_unknown_fields();
  44. }
  45. struct UnknownFieldHandlerLite {
  46. static bool Skip(MessageLite* msg, const ParseTable& table,
  47. io::CodedInputStream* input,
  48. int tag) {
  49. GOOGLE_DCHECK(!table.unknown_field_set);
  50. ::google::protobuf::io::StringOutputStream unknown_fields_string(
  51. MutableUnknownFields(msg, table.arena_offset));
  52. ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
  53. &unknown_fields_string, false);
  54. return ::google::protobuf::internal::WireFormatLite::SkipField(
  55. input, tag, &unknown_fields_stream);
  56. }
  57. static void Varint(MessageLite* msg, const ParseTable& table,
  58. int tag, int value) {
  59. GOOGLE_DCHECK(!table.unknown_field_set);
  60. ::google::protobuf::io::StringOutputStream unknown_fields_string(
  61. MutableUnknownFields(msg, table.arena_offset));
  62. ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
  63. &unknown_fields_string, false);
  64. unknown_fields_stream.WriteVarint32(tag);
  65. unknown_fields_stream.WriteVarint32(value);
  66. }
  67. static bool ParseExtension(
  68. MessageLite* msg, const ParseTable& table,
  69. io::CodedInputStream* input, int tag) {
  70. ExtensionSet* extensions = GetExtensionSet(msg, table.extension_offset);
  71. if (extensions == NULL) {
  72. return false;
  73. }
  74. const MessageLite* prototype = table.default_instance();
  75. GOOGLE_DCHECK(!table.unknown_field_set);
  76. ::google::protobuf::io::StringOutputStream unknown_fields_string(
  77. MutableUnknownFields(msg, table.arena_offset));
  78. ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
  79. &unknown_fields_string, false);
  80. return extensions->ParseField(
  81. tag, input, prototype, &unknown_fields_stream);
  82. }
  83. };
  84. } // namespace
  85. bool MergePartialFromCodedStreamLite(
  86. MessageLite* msg, const ParseTable& table, io::CodedInputStream* input) {
  87. return MergePartialFromCodedStreamImpl<UnknownFieldHandlerLite,
  88. InternalMetadataWithArenaLite>(
  89. msg, table, input);
  90. }
  91. } // namespace internal
  92. } // namespace protobuf
  93. } // namespace google