File indexing completed on 2025-01-31 10:11:59
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_SERIALIZATION_H__
0009 #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_SERIALIZATION_H__
0010
0011 #include <algorithm>
0012 #include <cstddef>
0013 #include <vector>
0014
0015 #include "absl/types/span.h"
0016 #include "google/protobuf/compiler/java/generator_common.h"
0017 #include "google/protobuf/descriptor.h"
0018 #include "google/protobuf/io/printer.h"
0019
0020 namespace google {
0021 namespace protobuf {
0022 namespace compiler {
0023 namespace java {
0024
0025
0026 void GenerateSerializeExtensionRange(io::Printer* printer,
0027 const Descriptor::ExtensionRange* range);
0028
0029
0030
0031
0032 inline void GenerateSerializeFieldsAndExtensions(
0033 io::Printer* printer,
0034 const std::vector<const FieldGenerator*>& field_generators,
0035 const Descriptor* descriptor, const FieldDescriptor** sorted_fields) {
0036 std::vector<const Descriptor::ExtensionRange*> sorted_extensions;
0037 sorted_extensions.reserve(descriptor->extension_range_count());
0038 for (int i = 0; i < descriptor->extension_range_count(); ++i) {
0039 sorted_extensions.push_back(descriptor->extension_range(i));
0040 }
0041 std::sort(sorted_extensions.begin(), sorted_extensions.end(),
0042 ExtensionRangeOrdering());
0043
0044 std::size_t range_idx = 0;
0045
0046
0047 for (int i = 0; i < descriptor->field_count(); ++i) {
0048 const FieldDescriptor* field = sorted_fields[i];
0049
0050
0051
0052
0053 const Descriptor::ExtensionRange* range = nullptr;
0054 while (range_idx < sorted_extensions.size() &&
0055 sorted_extensions[range_idx]->end_number() <= field->number()) {
0056 range = sorted_extensions[range_idx++];
0057 }
0058
0059 if (range != nullptr) {
0060 GenerateSerializeExtensionRange(printer, range);
0061 }
0062 size_t idx = static_cast<size_t>(field->index());
0063 field_generators[idx]->GenerateSerializationCode(printer);
0064 }
0065
0066
0067
0068 if (range_idx < sorted_extensions.size()) {
0069 GenerateSerializeExtensionRange(printer, sorted_extensions.back());
0070 }
0071 }
0072
0073 }
0074 }
0075 }
0076 }
0077
0078 #endif