• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
31 #include <google/protobuf/generated_message_table_driven_lite.h>
32 
33 #include <type_traits>
34 
35 #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
36 #include <google/protobuf/metadata_lite.h>
37 #include <google/protobuf/repeated_field.h>
38 #include <google/protobuf/wire_format_lite.h>
39 
40 namespace google {
41 namespace protobuf {
42 namespace internal {
43 
44 namespace {
45 
MutableUnknownFields(MessageLite * msg,int64 arena_offset)46 std::string* MutableUnknownFields(MessageLite* msg, int64 arena_offset) {
47   return Raw<InternalMetadataWithArenaLite>(msg, arena_offset)
48       ->mutable_unknown_fields();
49 }
50 
51 struct UnknownFieldHandlerLite {
52   // TODO(mvels): consider renaming UnknownFieldHandler to (TableDrivenTraits?),
53   // and conflating InternalMetaData into it, simplifying the template.
IsLitegoogle::protobuf::internal::__anon7e95c71d0111::UnknownFieldHandlerLite54   static constexpr bool IsLite() { return true; }
55 
Skipgoogle::protobuf::internal::__anon7e95c71d0111::UnknownFieldHandlerLite56   static bool Skip(MessageLite* msg, const ParseTable& table,
57                    io::CodedInputStream* input, int tag) {
58     GOOGLE_DCHECK(!table.unknown_field_set);
59     io::StringOutputStream unknown_fields_string(
60         MutableUnknownFields(msg, table.arena_offset));
61     io::CodedOutputStream unknown_fields_stream(&unknown_fields_string, false);
62 
63     return internal::WireFormatLite::SkipField(input, tag,
64                                                &unknown_fields_stream);
65   }
66 
Varintgoogle::protobuf::internal::__anon7e95c71d0111::UnknownFieldHandlerLite67   static void Varint(MessageLite* msg, const ParseTable& table, int tag,
68                      int value) {
69     GOOGLE_DCHECK(!table.unknown_field_set);
70 
71     io::StringOutputStream unknown_fields_string(
72         MutableUnknownFields(msg, table.arena_offset));
73     io::CodedOutputStream unknown_fields_stream(&unknown_fields_string, false);
74     unknown_fields_stream.WriteVarint32(tag);
75     unknown_fields_stream.WriteVarint32(value);
76   }
77 
ParseExtensiongoogle::protobuf::internal::__anon7e95c71d0111::UnknownFieldHandlerLite78   static bool ParseExtension(MessageLite* msg, const ParseTable& table,
79                              io::CodedInputStream* input, int tag) {
80     ExtensionSet* extensions = GetExtensionSet(msg, table.extension_offset);
81     if (extensions == NULL) {
82       return false;
83     }
84 
85     const MessageLite* prototype = table.default_instance();
86 
87     GOOGLE_DCHECK(!table.unknown_field_set);
88     io::StringOutputStream unknown_fields_string(
89         MutableUnknownFields(msg, table.arena_offset));
90     io::CodedOutputStream unknown_fields_stream(&unknown_fields_string, false);
91     return extensions->ParseField(tag, input, prototype,
92                                   &unknown_fields_stream);
93   }
94 };
95 
96 }  // namespace
97 
MergePartialFromCodedStreamLite(MessageLite * msg,const ParseTable & table,io::CodedInputStream * input)98 bool MergePartialFromCodedStreamLite(MessageLite* msg, const ParseTable& table,
99                                      io::CodedInputStream* input) {
100   return MergePartialFromCodedStreamImpl<UnknownFieldHandlerLite,
101                                          InternalMetadataWithArenaLite>(
102       msg, table, input);
103 }
104 
105 }  // namespace internal
106 }  // namespace protobuf
107 }  // namespace google
108