68
86
// of whatever type the individual field would be. Strings and
69
87
// Messages use RepeatedPtrFields while everything else uses
71
class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Message::Reflection {
89
class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
73
91
// Constructs a GeneratedMessageReflection.
75
93
// descriptor: The descriptor for the message type being implemented.
76
// base: Pointer to the location where the message object is
78
// default_base: Pointer to the location where the message's default
79
// instance is stored. This is only used to obtain
80
// pointers to default instances of embedded messages,
81
// which GetMessage() will return if the particular sub-
82
// message has not been initialized yet. (Thus, all
94
// default_instance: The default instance of the message. This is only
95
// used to obtain pointers to default instances of embedded
96
// messages, which GetMessage() will return if the particular
97
// sub-message has not been initialized yet. (Thus, all
83
98
// embedded message fields *must* have non-NULL pointers
84
99
// in the default instance.)
85
// offsets: An array of bits giving the byte offsets, relative to
86
// "base" and "default_base", of each field. These can
100
// offsets: An array of ints giving the byte offsets, relative to
101
// the start of the message object, of each field. These can
87
102
// be computed at compile time using the
88
103
// GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro, defined
90
// has_bits: An array of uint32s of size descriptor->field_count()/32,
91
// rounded up. This is a bitfield where each bit indicates
92
// whether or not the corresponding field of the message
93
// has been initialized. The bit for field index i is
94
// obtained by the expression:
105
// has_bits_offset: Offset in the message of an array of uint32s of size
106
// descriptor->field_count()/32, rounded up. This is a
107
// bitfield where each bit indicates whether or not the
108
// corresponding field of the message has been initialized.
109
// The bit for field index i is obtained by the expression:
95
110
// has_bits[i / 32] & (1 << (i % 32))
96
// extensions: The ExtensionSet for this message, or NULL if the
97
// message type has no extension ranges.
111
// unknown_fields_offset: Offset in the message of the UnknownFieldSet for
113
// extensions_offset: Offset in the message of the ExtensionSet for the
114
// message, or -1 if the message type has no extension
116
// pool: DescriptorPool to search for extension definitions. Only
117
// used by FindKnownExtensionByName() and
118
// FindKnownExtensionByNumber().
119
// object_size: The size of a message object of this type, as measured
98
121
GeneratedMessageReflection(const Descriptor* descriptor,
99
void* base, const void* default_base,
100
const int offsets[], uint32 has_bits[],
101
ExtensionSet* extensions);
122
const Message* default_instance,
125
int unknown_fields_offset,
126
int extensions_offset,
127
const DescriptorPool* pool,
102
129
~GeneratedMessageReflection();
104
inline const UnknownFieldSet& unknown_fields() const {
105
return unknown_fields_;
107
inline UnknownFieldSet* mutable_unknown_fields() {
108
return &unknown_fields_;
111
// implements Message::Reflection ----------------------------------
113
const UnknownFieldSet& GetUnknownFields() const;
114
UnknownFieldSet* MutableUnknownFields();
116
bool HasField(const FieldDescriptor* field) const;
117
int FieldSize(const FieldDescriptor* field) const;
118
void ClearField(const FieldDescriptor* field);
119
void ListFields(vector<const FieldDescriptor*>* output) const;
121
int32 GetInt32 (const FieldDescriptor* field) const;
122
int64 GetInt64 (const FieldDescriptor* field) const;
123
uint32 GetUInt32(const FieldDescriptor* field) const;
124
uint64 GetUInt64(const FieldDescriptor* field) const;
125
float GetFloat (const FieldDescriptor* field) const;
126
double GetDouble(const FieldDescriptor* field) const;
127
bool GetBool (const FieldDescriptor* field) const;
128
string GetString(const FieldDescriptor* field) const;
129
const string& GetStringReference(const FieldDescriptor* field,
131
// implements Reflection -------------------------------------------
133
const UnknownFieldSet& GetUnknownFields(const Message& message) const;
134
UnknownFieldSet* MutableUnknownFields(Message* message) const;
136
int SpaceUsed(const Message& message) const;
138
bool HasField(const Message& message, const FieldDescriptor* field) const;
139
int FieldSize(const Message& message, const FieldDescriptor* field) const;
140
void ClearField(Message* message, const FieldDescriptor* field) const;
141
void ListFields(const Message& message,
142
vector<const FieldDescriptor*>* output) const;
144
int32 GetInt32 (const Message& message,
145
const FieldDescriptor* field) const;
146
int64 GetInt64 (const Message& message,
147
const FieldDescriptor* field) const;
148
uint32 GetUInt32(const Message& message,
149
const FieldDescriptor* field) const;
150
uint64 GetUInt64(const Message& message,
151
const FieldDescriptor* field) const;
152
float GetFloat (const Message& message,
153
const FieldDescriptor* field) const;
154
double GetDouble(const Message& message,
155
const FieldDescriptor* field) const;
156
bool GetBool (const Message& message,
157
const FieldDescriptor* field) const;
158
string GetString(const Message& message,
159
const FieldDescriptor* field) const;
160
const string& GetStringReference(const Message& message,
161
const FieldDescriptor* field,
130
162
string* scratch) const;
131
const EnumValueDescriptor* GetEnum(const FieldDescriptor* field) const;
132
const Message& GetMessage(const FieldDescriptor* field) const;
134
void SetInt32 (const FieldDescriptor* field, int32 value);
135
void SetInt64 (const FieldDescriptor* field, int64 value);
136
void SetUInt32(const FieldDescriptor* field, uint32 value);
137
void SetUInt64(const FieldDescriptor* field, uint64 value);
138
void SetFloat (const FieldDescriptor* field, float value);
139
void SetDouble(const FieldDescriptor* field, double value);
140
void SetBool (const FieldDescriptor* field, bool value);
141
void SetString(const FieldDescriptor* field,
142
const string& value);
143
void SetEnum (const FieldDescriptor* field,
144
const EnumValueDescriptor* value);
145
Message* MutableMessage(const FieldDescriptor* field);
147
int32 GetRepeatedInt32 (const FieldDescriptor* field, int index) const;
148
int64 GetRepeatedInt64 (const FieldDescriptor* field, int index) const;
149
uint32 GetRepeatedUInt32(const FieldDescriptor* field, int index) const;
150
uint64 GetRepeatedUInt64(const FieldDescriptor* field, int index) const;
151
float GetRepeatedFloat (const FieldDescriptor* field, int index) const;
152
double GetRepeatedDouble(const FieldDescriptor* field, int index) const;
153
bool GetRepeatedBool (const FieldDescriptor* field, int index) const;
154
string GetRepeatedString(const FieldDescriptor* field, int index) const;
155
const string& GetRepeatedStringReference(const FieldDescriptor* field,
163
const EnumValueDescriptor* GetEnum(const Message& message,
164
const FieldDescriptor* field) const;
165
const Message& GetMessage(const Message& message,
166
const FieldDescriptor* field) const;
168
void SetInt32 (Message* message,
169
const FieldDescriptor* field, int32 value) const;
170
void SetInt64 (Message* message,
171
const FieldDescriptor* field, int64 value) const;
172
void SetUInt32(Message* message,
173
const FieldDescriptor* field, uint32 value) const;
174
void SetUInt64(Message* message,
175
const FieldDescriptor* field, uint64 value) const;
176
void SetFloat (Message* message,
177
const FieldDescriptor* field, float value) const;
178
void SetDouble(Message* message,
179
const FieldDescriptor* field, double value) const;
180
void SetBool (Message* message,
181
const FieldDescriptor* field, bool value) const;
182
void SetString(Message* message,
183
const FieldDescriptor* field,
184
const string& value) const;
185
void SetEnum (Message* message, const FieldDescriptor* field,
186
const EnumValueDescriptor* value) const;
187
Message* MutableMessage(Message* message, const FieldDescriptor* field) const;
189
int32 GetRepeatedInt32 (const Message& message,
190
const FieldDescriptor* field, int index) const;
191
int64 GetRepeatedInt64 (const Message& message,
192
const FieldDescriptor* field, int index) const;
193
uint32 GetRepeatedUInt32(const Message& message,
194
const FieldDescriptor* field, int index) const;
195
uint64 GetRepeatedUInt64(const Message& message,
196
const FieldDescriptor* field, int index) const;
197
float GetRepeatedFloat (const Message& message,
198
const FieldDescriptor* field, int index) const;
199
double GetRepeatedDouble(const Message& message,
200
const FieldDescriptor* field, int index) const;
201
bool GetRepeatedBool (const Message& message,
202
const FieldDescriptor* field, int index) const;
203
string GetRepeatedString(const Message& message,
204
const FieldDescriptor* field, int index) const;
205
const string& GetRepeatedStringReference(const Message& message,
206
const FieldDescriptor* field,
156
207
int index, string* scratch) const;
157
const EnumValueDescriptor* GetRepeatedEnum(const FieldDescriptor* field,
208
const EnumValueDescriptor* GetRepeatedEnum(const Message& message,
209
const FieldDescriptor* field,
158
210
int index) const;
159
const Message& GetRepeatedMessage(const FieldDescriptor* field,
211
const Message& GetRepeatedMessage(const Message& message,
212
const FieldDescriptor* field,
160
213
int index) const;
162
215
// Set the value of a field.
163
void SetRepeatedInt32 (const FieldDescriptor* field, int index, int32 value);
164
void SetRepeatedInt64 (const FieldDescriptor* field, int index, int64 value);
165
void SetRepeatedUInt32(const FieldDescriptor* field, int index, uint32 value);
166
void SetRepeatedUInt64(const FieldDescriptor* field, int index, uint64 value);
167
void SetRepeatedFloat (const FieldDescriptor* field, int index, float value);
168
void SetRepeatedDouble(const FieldDescriptor* field, int index, double value);
169
void SetRepeatedBool (const FieldDescriptor* field, int index, bool value);
170
void SetRepeatedString(const FieldDescriptor* field, int index,
171
const string& value);
172
void SetRepeatedEnum (const FieldDescriptor* field, int index,
173
const EnumValueDescriptor* value);
216
void SetRepeatedInt32 (Message* message,
217
const FieldDescriptor* field, int index, int32 value) const;
218
void SetRepeatedInt64 (Message* message,
219
const FieldDescriptor* field, int index, int64 value) const;
220
void SetRepeatedUInt32(Message* message,
221
const FieldDescriptor* field, int index, uint32 value) const;
222
void SetRepeatedUInt64(Message* message,
223
const FieldDescriptor* field, int index, uint64 value) const;
224
void SetRepeatedFloat (Message* message,
225
const FieldDescriptor* field, int index, float value) const;
226
void SetRepeatedDouble(Message* message,
227
const FieldDescriptor* field, int index, double value) const;
228
void SetRepeatedBool (Message* message,
229
const FieldDescriptor* field, int index, bool value) const;
230
void SetRepeatedString(Message* message,
231
const FieldDescriptor* field, int index,
232
const string& value) const;
233
void SetRepeatedEnum(Message* message, const FieldDescriptor* field,
234
int index, const EnumValueDescriptor* value) const;
174
235
// Get a mutable pointer to a field with a message type.
175
Message* MutableRepeatedMessage(const FieldDescriptor* field, int index);
236
Message* MutableRepeatedMessage(Message* message,
237
const FieldDescriptor* field,
177
void AddInt32 (const FieldDescriptor* field, int32 value);
178
void AddInt64 (const FieldDescriptor* field, int64 value);
179
void AddUInt32(const FieldDescriptor* field, uint32 value);
180
void AddUInt64(const FieldDescriptor* field, uint64 value);
181
void AddFloat (const FieldDescriptor* field, float value);
182
void AddDouble(const FieldDescriptor* field, double value);
183
void AddBool (const FieldDescriptor* field, bool value);
184
void AddString(const FieldDescriptor* field, const string& value);
185
void AddEnum(const FieldDescriptor* field, const EnumValueDescriptor* value);
186
Message* AddMessage(const FieldDescriptor* field);
240
void AddInt32 (Message* message,
241
const FieldDescriptor* field, int32 value) const;
242
void AddInt64 (Message* message,
243
const FieldDescriptor* field, int64 value) const;
244
void AddUInt32(Message* message,
245
const FieldDescriptor* field, uint32 value) const;
246
void AddUInt64(Message* message,
247
const FieldDescriptor* field, uint64 value) const;
248
void AddFloat (Message* message,
249
const FieldDescriptor* field, float value) const;
250
void AddDouble(Message* message,
251
const FieldDescriptor* field, double value) const;
252
void AddBool (Message* message,
253
const FieldDescriptor* field, bool value) const;
254
void AddString(Message* message,
255
const FieldDescriptor* field, const string& value) const;
256
void AddEnum(Message* message,
257
const FieldDescriptor* field,
258
const EnumValueDescriptor* value) const;
259
Message* AddMessage(Message* message, const FieldDescriptor* field) const;
188
261
const FieldDescriptor* FindKnownExtensionByName(const string& name) const;
189
262
const FieldDescriptor* FindKnownExtensionByNumber(int number) const;
192
265
friend class GeneratedMessage;
194
267
const Descriptor* descriptor_;
196
const void* default_base_;
268
const Message* default_instance_;
197
269
const int* offsets_;
199
// TODO(kenton): These two pointers just point back into the message object.
200
// We could save space by removing them and using offsets instead.
202
ExtensionSet* extensions_;
204
// We put this directly in the GeneratedMessageReflection because every
205
// message class needs it, and if we don't find any unknown fields, it
206
// takes up only one pointer of space.
207
UnknownFieldSet unknown_fields_;
209
template <typename Type>
210
inline const Type& GetRaw(const FieldDescriptor* field) const;
211
template <typename Type>
212
inline Type* MutableRaw(const FieldDescriptor* field);
271
int has_bits_offset_;
272
int unknown_fields_offset_;
273
int extensions_offset_;
276
const DescriptorPool* descriptor_pool_;
278
template <typename Type>
279
inline const Type& GetRaw(const Message& message,
280
const FieldDescriptor* field) const;
281
template <typename Type>
282
inline Type* MutableRaw(Message* message,
283
const FieldDescriptor* field) const;
213
284
template <typename Type>
214
285
inline const Type& DefaultRaw(const FieldDescriptor* field) const;
215
286
inline const Message* GetMessagePrototype(const FieldDescriptor* field) const;
217
inline bool HasBit(const FieldDescriptor* field) const;
218
inline void SetBit(const FieldDescriptor* field);
219
inline void ClearBit(const FieldDescriptor* field);
221
template <typename Type>
222
inline const Type& GetField(const FieldDescriptor* field) const;
223
template <typename Type>
224
inline void SetField(const FieldDescriptor* field, const Type& value);
225
template <typename Type>
226
inline Type* MutableField(const FieldDescriptor* field);
227
template <typename Type>
228
inline const Type& GetRepeatedField(const FieldDescriptor* field,
288
inline const uint32* GetHasBits(const Message& message) const;
289
inline uint32* MutableHasBits(Message* message) const;
290
inline const ExtensionSet& GetExtensionSet(const Message& message) const;
291
inline ExtensionSet* MutableExtensionSet(Message* message) const;
293
inline bool HasBit(const Message& message,
294
const FieldDescriptor* field) const;
295
inline void SetBit(Message* message,
296
const FieldDescriptor* field) const;
297
inline void ClearBit(Message* message,
298
const FieldDescriptor* field) const;
300
template <typename Type>
301
inline const Type& GetField(const Message& message,
302
const FieldDescriptor* field) const;
303
template <typename Type>
304
inline void SetField(Message* message,
305
const FieldDescriptor* field, const Type& value) const;
306
template <typename Type>
307
inline Type* MutableField(Message* message,
308
const FieldDescriptor* field) const;
309
template <typename Type>
310
inline const Type& GetRepeatedField(const Message& message,
311
const FieldDescriptor* field,
229
312
int index) const;
230
313
template <typename Type>
231
inline void SetRepeatedField(const FieldDescriptor* field, int index,
233
template <typename Type>
234
inline Type* MutableRepeatedField(const FieldDescriptor* field, int index);
235
template <typename Type>
236
inline void AddField(const FieldDescriptor* field, const Type& value);
237
template <typename Type>
238
inline Type* AddField(const FieldDescriptor* field);
314
inline void SetRepeatedField(Message* message,
315
const FieldDescriptor* field, int index,
316
const Type& value) const;
317
template <typename Type>
318
inline Type* MutableRepeatedField(Message* message,
319
const FieldDescriptor* field,
321
template <typename Type>
322
inline void AddField(Message* message,
323
const FieldDescriptor* field, const Type& value) const;
324
template <typename Type>
325
inline Type* AddField(Message* message,
326
const FieldDescriptor* field) const;
240
328
int GetExtensionNumberOrDie(const Descriptor* type) const;