Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2023 Google LLC. All rights reserved. |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 3 | // |
Protobuf Team Bot | 0fab773 | 2023-11-20 13:38:15 -0800 | [diff] [blame] | 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 |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 7 | |
| 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. |
| 20 | PyObject* 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. |
| 28 | bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val, |
| 29 | upb_Arena* arena); |
| 30 | |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 31 | // Returns true if the given messages (of type `m`) are equal. |
Eric Salo | c69ed47 | 2024-02-09 13:37:03 -0800 | [diff] [blame] | 32 | bool upb_Message_IsEqualByDef(const upb_Message* msg1, const upb_Message* msg2, |
Eric Salo | e1a19ba | 2024-03-11 10:13:53 -0700 | [diff] [blame] | 33 | const upb_MessageDef* msgdef, int options); |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 34 | |
| 35 | #endif // PYUPB_CONVERT_H__ |