blob: 08426a69e265d317a6c92cf9fae86923a2e96706 [file] [log] [blame]
Adam Cozzette501ecec2023-09-26 14:36:20 -07001// Protocol Buffers - Google's data interchange format
2// Copyright 2023 Google LLC. All rights reserved.
Adam Cozzette501ecec2023-09-26 14:36:20 -07003//
Protobuf Team Bot0fab7732023-11-20 13:38:15 -08004// 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
Adam Cozzette501ecec2023-09-26 14:36:20 -07007
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.
18PyObject* 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.
26PyObject* 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.
32void PyUpb_RepeatedContainer_Reify(PyObject* self, upb_Array* arr);
33
34// Reifies this repeated object if it is not already reified.
35upb_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).
39PyObject* PyUpb_RepeatedContainer_Extend(PyObject* _self, PyObject* value);
40
41// Implements repeated_field.add(initial_values). `_self` must be a repeated
42// composite field.
43PyObject* PyUpb_RepeatedCompositeContainer_Add(PyObject* _self, PyObject* args,
44 PyObject* kwargs);
45
46// Module-level init.
47bool PyUpb_Repeated_Init(PyObject* m);
48
49#endif // PYUPB_REPEATED_H__