blob: 88dd9afc85b859f63230c5c5a2d8e6b4c09fb444 [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_CONVERT_H__
9#define PYUPB_CONVERT_H__
10
11#include "protobuf.h"
12#include "upb/reflection/def.h"
13#include "upb/reflection/message.h"
14
15// Converts `val` to a Python object according to the type information in `f`.
16// Any newly-created Python objects that reference non-primitive data from `val`
17// will take a reference on `arena`; the caller must ensure that `val` belongs
18// to `arena`. If the conversion cannot be performed, returns NULL and sets a
19// Python error.
20PyObject* PyUpb_UpbToPy(upb_MessageValue val, const upb_FieldDef* f,
21 PyObject* arena);
22
23// Converts `obj` to a upb_MessageValue `*val` according to the type information
24// in `f`. If `arena` is provided, any string data will be copied into `arena`,
25// otherwise the returned value will alias the Python-owned data (this can be
26// useful for an ephemeral upb_MessageValue). If the conversion cannot be
27// performed, returns false.
28bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val,
29 upb_Arena* arena);
30
Adam Cozzette501ecec2023-09-26 14:36:20 -070031// Returns true if the given messages (of type `m`) are equal.
Eric Saloc69ed472024-02-09 13:37:03 -080032bool upb_Message_IsEqualByDef(const upb_Message* msg1, const upb_Message* msg2,
Eric Saloe1a19ba2024-03-11 10:13:53 -070033 const upb_MessageDef* msgdef, int options);
Adam Cozzette501ecec2023-09-26 14:36:20 -070034
35#endif // PYUPB_CONVERT_H__