2023-08-07 10:01:08 -07:00
|
|
|
// Protocol Buffers - Google's data interchange format
|
|
|
|
|
// Copyright 2023 Google LLC. All rights reserved.
|
|
|
|
|
//
|
2023-11-20 13:38:15 -08:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2021-12-08 23:32:05 -08:00
|
|
|
|
|
|
|
|
#ifndef PYUPB_REPEATED_H__
|
|
|
|
|
#define PYUPB_REPEATED_H__
|
|
|
|
|
|
2026-05-19 19:56:10 -07:00
|
|
|
// clang-format off
|
|
|
|
|
#include "Python.h"
|
|
|
|
|
// chang-format on
|
2021-12-08 23:32:05 -08:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
2025-04-28 18:32:05 -07:00
|
|
|
#include "python/protobuf.h"
|
2023-09-26 14:36:20 -07:00
|
|
|
#include "python/python_api.h"
|
|
|
|
|
#include "upb/reflection/def.h"
|
2021-12-08 23:32:05 -08:00
|
|
|
|
2021-12-30 01:04:49 -08:00
|
|
|
// Creates a new repeated field stub for field `f` of message object `parent`.
|
2022-01-05 15:47:59 -08:00
|
|
|
// Precondition: `parent` must be a stub.
|
2021-12-30 01:04:49 -08:00
|
|
|
PyObject* PyUpb_RepeatedContainer_NewStub(PyObject* parent,
|
2022-01-12 07:19:28 -08:00
|
|
|
const upb_FieldDef* f,
|
2021-12-30 01:04:49 -08:00
|
|
|
PyObject* arena);
|
2021-12-08 23:32:05 -08:00
|
|
|
|
2021-12-28 20:46:58 -08:00
|
|
|
// Returns a repeated field object wrapping `arr`, of field type `f`, which
|
2021-12-08 23:32:05 -08:00
|
|
|
// must be on `arena`. If an existing wrapper object exists, it will be
|
|
|
|
|
// returned, otherwise a new object will be created. The caller always owns a
|
|
|
|
|
// ref on the returned value.
|
2022-01-12 07:19:28 -08:00
|
|
|
PyObject* PyUpb_RepeatedContainer_GetOrCreateWrapper(upb_Array* arr,
|
|
|
|
|
const upb_FieldDef* f,
|
2021-12-08 23:32:05 -08:00
|
|
|
PyObject* arena);
|
|
|
|
|
|
2021-12-30 01:04:49 -08:00
|
|
|
// Reifies a repeated field stub to point to the concrete data in `arr`.
|
2022-01-09 23:52:23 -08:00
|
|
|
// If `arr` is NULL, an appropriate empty array will be constructed.
|
2025-04-28 18:32:05 -07:00
|
|
|
upb_Array* PyUpb_RepeatedContainer_Reify(PyObject* self, upb_Array* arr,
|
|
|
|
|
PyUpb_WeakMap* subobj_map,
|
|
|
|
|
intptr_t iter);
|
2021-12-08 23:32:05 -08:00
|
|
|
|
2026-05-20 11:30:51 -07:00
|
|
|
// Reifies this repeated object if it is not already reified, and ensures it is
|
|
|
|
|
// mutable. If the parent message (for stubs) or the repeated array itself (for
|
|
|
|
|
// reified arrays) is frozen, this function will set a Python TypeError and
|
|
|
|
|
// return NULL.
|
|
|
|
|
upb_Array* PyUpb_RepeatedContainer_AssureWritable(PyObject* self);
|
2022-01-05 12:55:52 -08:00
|
|
|
|
2021-12-28 20:46:58 -08:00
|
|
|
// Implements repeated_field.extend(iterable). `_self` must be a repeated
|
|
|
|
|
// field (either repeated composite or repeated scalar).
|
2021-12-08 23:32:05 -08:00
|
|
|
PyObject* PyUpb_RepeatedContainer_Extend(PyObject* _self, PyObject* value);
|
2021-12-28 20:46:58 -08:00
|
|
|
|
|
|
|
|
// Implements repeated_field.add(initial_values). `_self` must be a repeated
|
|
|
|
|
// composite field.
|
2021-12-08 23:32:05 -08:00
|
|
|
PyObject* PyUpb_RepeatedCompositeContainer_Add(PyObject* _self, PyObject* args,
|
|
|
|
|
PyObject* kwargs);
|
|
|
|
|
|
|
|
|
|
// Module-level init.
|
|
|
|
|
bool PyUpb_Repeated_Init(PyObject* m);
|
|
|
|
|
|
|
|
|
|
#endif // PYUPB_REPEATED_H__
|