| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QPROTOBUFPROPERTYORDERING_H |
| 5 | #define QPROTOBUFPROPERTYORDERING_H |
| 6 | |
| 7 | #if 0 |
| 8 | # pragma qt_sync_skip_header_check |
| 9 | # pragma qt_sync_stop_processing |
| 10 | #endif |
| 11 | |
| 12 | #include <QtProtobuf/qtprotobufexports.h> |
| 13 | |
| 14 | #include <QtCore/qflags.h> |
| 15 | #include <QtCore/qtclasshelpermacros.h> |
| 16 | #include <QtCore/qutf8stringview.h> |
| 17 | #include <QtCore/qxptype_traits.h> |
| 18 | |
| 19 | QT_BEGIN_NAMESPACE |
| 20 | |
| 21 | namespace QtProtobufPrivate { |
| 22 | |
| 23 | enum class FieldFlag : uint { |
| 24 | NoFlags = 0x0, |
| 25 | NonPacked = 0x1, |
| 26 | Oneof = 0x02, |
| 27 | Optional = 0x04, |
| 28 | ExplicitPresence = 0x08, |
| 29 | Message = 0x10, |
| 30 | Enum = 0x20, |
| 31 | Repeated = 0x40, |
| 32 | Map = 0x80, |
| 33 | }; |
| 34 | Q_DECLARE_FLAGS(FieldFlags, FieldFlag) |
| 35 | Q_DECLARE_OPERATORS_FOR_FLAGS(FieldFlags) |
| 36 | |
| 37 | class QProtobufPropertyOrderingBuilder; |
| 38 | struct QProtobufPropertyOrdering |
| 39 | { |
| 40 | const struct Data |
| 41 | { |
| 42 | uint version; |
| 43 | uint numFields; |
| 44 | uint fieldNumberOffset; |
| 45 | uint propertyIndexOffset; |
| 46 | uint flagsOffset; |
| 47 | uint fullPackageNameSize; |
| 48 | } *data; |
| 49 | |
| 50 | Q_PROTOBUF_EXPORT QUtf8StringView messageFullName() const; |
| 51 | Q_PROTOBUF_EXPORT QUtf8StringView jsonName(int index) const; |
| 52 | Q_PROTOBUF_EXPORT int fieldNumber(int index) const; |
| 53 | Q_PROTOBUF_EXPORT int propertyIndex(int index) const; |
| 54 | Q_PROTOBUF_EXPORT FieldFlags fieldFlags(int index) const; |
| 55 | Q_PROTOBUF_EXPORT int indexOfFieldNumber(int fieldNumber) const; |
| 56 | int fieldCount() const { return int(data->numFields); } |
| 57 | |
| 58 | private: |
| 59 | friend class QProtobufPropertyOrderingBuilder; |
| 60 | QT_DEFINE_TAG_STRUCT(NonConstTag); |
| 61 | uint *uint_data(NonConstTag) const; |
| 62 | char *char_data(NonConstTag) const; |
| 63 | const uint *uint_data() const; |
| 64 | const char *char_data() const; |
| 65 | const uint &uint_dataForIndex(int index, uint offset) const; |
| 66 | }; |
| 67 | |
| 68 | // Convenience structure to hold a reference to a single field information |
| 69 | struct QProtobufFieldInfo |
| 70 | { |
| 71 | QProtobufFieldInfo(QProtobufPropertyOrdering ord, int ind) |
| 72 | : ordering(ord), index(ind) |
| 73 | { |
| 74 | Q_ASSERT(index >= 0); |
| 75 | } |
| 76 | |
| 77 | QUtf8StringView jsonName() const { return ordering.jsonName(index); } |
| 78 | int fieldNumber() const { return ordering.fieldNumber(index); } |
| 79 | int propertyIndex() const { return ordering.propertyIndex(index); } |
| 80 | FieldFlags fieldFlags() const { return ordering.fieldFlags(index); } |
| 81 | |
| 82 | private: |
| 83 | const QProtobufPropertyOrdering ordering; |
| 84 | const int index; |
| 85 | }; |
| 86 | |
| 87 | } // namespace QtProtobufPrivate |
| 88 | |
| 89 | QT_END_NAMESPACE |
| 90 | |
| 91 | #endif // QPROTOBUFPROPERTYORDERING_H |
| 92 | |