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_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 31 // Returns true if the given messages (of type `m`) are equal. 32 bool upb_Message_IsEqualByDef(const upb_Message* msg1, const upb_Message* msg2, 33 const upb_MessageDef* msgdef, int options); 34 35 #endif // PYUPB_CONVERT_H__ 36