1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2023 Google LLC. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 #ifndef PYUPB_REPEATED_H__ 9 #define PYUPB_REPEATED_H__ 10 11 #include <stdbool.h> 12 13 #include "python/python_api.h" 14 #include "upb/reflection/def.h" 15 16 // Creates a new repeated field stub for field `f` of message object `parent`. 17 // Precondition: `parent` must be a stub. 18 PyObject* PyUpb_RepeatedContainer_NewStub(PyObject* parent, 19 const upb_FieldDef* f, 20 PyObject* arena); 21 22 // Returns a repeated field object wrapping `arr`, of field type `f`, which 23 // must be on `arena`. If an existing wrapper object exists, it will be 24 // returned, otherwise a new object will be created. The caller always owns a 25 // ref on the returned value. 26 PyObject* PyUpb_RepeatedContainer_GetOrCreateWrapper(upb_Array* arr, 27 const upb_FieldDef* f, 28 PyObject* arena); 29 30 // Reifies a repeated field stub to point to the concrete data in `arr`. 31 // If `arr` is NULL, an appropriate empty array will be constructed. 32 void PyUpb_RepeatedContainer_Reify(PyObject* self, upb_Array* arr); 33 34 // Reifies this repeated object if it is not already reified. 35 upb_Array* PyUpb_RepeatedContainer_EnsureReified(PyObject* self); 36 37 // Implements repeated_field.extend(iterable). `_self` must be a repeated 38 // field (either repeated composite or repeated scalar). 39 PyObject* PyUpb_RepeatedContainer_Extend(PyObject* _self, PyObject* value); 40 41 // Implements repeated_field.add(initial_values). `_self` must be a repeated 42 // composite field. 43 PyObject* PyUpb_RepeatedCompositeContainer_Add(PyObject* _self, PyObject* args, 44 PyObject* kwargs); 45 46 // Module-level init. 47 bool PyUpb_Repeated_Init(PyObject* m); 48 49 #endif // PYUPB_REPEATED_H__ 50