upb/python/message.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2021, Google LLC
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of Google LLC nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef PYPB_MESSAGE_H__
29 #define PYPB_MESSAGE_H__
30 
31 #include <stdbool.h>
32 
33 #include "python/protobuf.h"
34 #include "upb/reflection.h"
35 
36 // Removes the wrapper object for this field from the unset subobject cache.
37 void PyUpb_CMessage_CacheDelete(PyObject* _self, const upb_FieldDef* f);
38 
39 // Sets the field value for `f` to `subobj`, evicting the wrapper object from
40 // the "unset subobject" cache now that real data exists for it. The caller
41 // must also update the wrapper associated with `f` to point to `subobj` also.
42 void PyUpb_CMessage_SetConcreteSubobj(PyObject* _self, const upb_FieldDef* f,
43  upb_MessageValue subobj);
44 
45 // Gets a Python wrapper object for message `u_msg` of type `m`, returning a
46 // cached wrapper if one was previously created. If a new object is created,
47 // it will reference `arena`, which must own `u_msg`.
48 PyObject* PyUpb_CMessage_Get(upb_Message* u_msg, const upb_MessageDef* m,
49  PyObject* arena);
50 
51 // Verifies that a Python object is a message. Sets a TypeError exception and
52 // returns false on failure.
53 bool PyUpb_CMessage_Verify(PyObject* self);
54 
55 // Gets the upb_Message* for this message object if the message is reified.
56 // Otherwise returns NULL.
58 
59 // Returns the `upb_MessageDef` for a given CMessage.
60 const upb_MessageDef* PyUpb_CMessage_GetMsgdef(PyObject* self);
61 
62 // Functions that match the corresponding methods on the message object.
63 PyObject* PyUpb_CMessage_MergeFrom(PyObject* self, PyObject* arg);
64 PyObject* PyUpb_CMessage_MergeFromString(PyObject* self, PyObject* arg);
65 PyObject* PyUpb_CMessage_SerializeToString(PyObject* self, PyObject* args,
66  PyObject* kwargs);
67 
68 // Sets fields of the message according to the attribuges in `kwargs`.
69 int PyUpb_CMessage_InitAttributes(PyObject* _self, PyObject* args,
70  PyObject* kwargs);
71 
72 // Checks that `key` is a field descriptor for an extension type, and that the
73 // extendee is this message. Otherwise returns NULL and sets a KeyError.
74 const upb_FieldDef* PyUpb_CMessage_GetExtensionDef(PyObject* _self,
75  PyObject* key);
76 
77 // Clears the given field in this message.
78 void PyUpb_CMessage_DoClearField(PyObject* _self, const upb_FieldDef* f);
79 
80 // Clears the ExtensionDict from the message. The message must have an
81 // ExtensionDict set.
82 void PyUpb_CMessage_ClearExtensionDict(PyObject* _self);
83 
84 // Implements the equivalent of getattr(msg, field), once `field` has
85 // already been resolved to a `upb_FieldDef*`.
86 PyObject* PyUpb_CMessage_GetFieldValue(PyObject* _self,
87  const upb_FieldDef* field);
88 
89 // Implements the equivalent of setattr(msg, field, value), once `field` has
90 // already been resolved to a `upb_FieldDef*`.
91 int PyUpb_CMessage_SetFieldValue(PyObject* _self, const upb_FieldDef* field,
92  PyObject* value, PyObject* exc);
93 
94 // Returns the version associated with this message. The version will be
95 // incremented when the message changes.
96 int PyUpb_CMessage_GetVersion(PyObject* _self);
97 
98 // Module-level init.
99 bool PyUpb_InitMessage(PyObject* m);
100 
101 #endif // PYPB_MESSAGE_H__
PyUpb_CMessage_Get
PyObject * PyUpb_CMessage_Get(upb_Message *u_msg, const upb_MessageDef *m, PyObject *arena)
Definition: upb/python/message.c:751
PyUpb_CMessage_GetIfReified
upb_Message * PyUpb_CMessage_GetIfReified(PyObject *_self)
Definition: upb/python/message.c:246
PyUpb_CMessage_GetVersion
int PyUpb_CMessage_GetVersion(PyObject *_self)
Definition: upb/python/message.c:896
upb_MessageDef
Definition: upb/upb/def.c:100
PyUpb_CMessage_SerializeToString
PyObject * PyUpb_CMessage_SerializeToString(PyObject *self, PyObject *args, PyObject *kwargs)
Definition: upb/python/message.c:1451
PyUpb_CMessage_GetFieldValue
PyObject * PyUpb_CMessage_GetFieldValue(PyObject *_self, const upb_FieldDef *field)
Definition: upb/python/message.c:854
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
upb_MessageValue
Definition: upb/upb/reflection.h:40
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
PyUpb_CMessage_GetMsgdef
const upb_MessageDef * PyUpb_CMessage_GetMsgdef(PyObject *self)
Definition: upb/python/message.c:220
PyUpb_CMessage_MergeFrom
PyObject * PyUpb_CMessage_MergeFrom(PyObject *self, PyObject *arg)
Definition: upb/python/message.c:1097
arg
Definition: cmdline.cc:40
reflection.h
PyUpb_CMessage_CacheDelete
void PyUpb_CMessage_CacheDelete(PyObject *_self, const upb_FieldDef *f)
Definition: upb/python/message.c:708
protobuf.h
upb_Message
void upb_Message
Definition: msg.h:49
PyUpb_CMessage_MergeFromString
PyObject * PyUpb_CMessage_MergeFromString(PyObject *self, PyObject *arg)
Definition: upb/python/message.c:1129
upb_FieldDef
Definition: upb/upb/def.c:56
value
const char * value
Definition: hpack_parser_table.cc:165
PyUpb_CMessage_SetConcreteSubobj
void PyUpb_CMessage_SetConcreteSubobj(PyObject *_self, const upb_FieldDef *f, upb_MessageValue subobj)
Definition: upb/python/message.c:713
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
key
const char * key
Definition: hpack_parser_table.cc:164
PyUpb_InitMessage
bool PyUpb_InitMessage(PyObject *m)
Definition: upb/python/message.c:1823
PyUpb_CMessage_ClearExtensionDict
void PyUpb_CMessage_ClearExtensionDict(PyObject *_self)
Definition: upb/python/message.c:1475
PyUpb_CMessage_GetExtensionDef
const upb_FieldDef * PyUpb_CMessage_GetExtensionDef(PyObject *_self, PyObject *key)
Definition: upb/python/message.c:1342
PyUpb_CMessage_Verify
bool PyUpb_CMessage_Verify(PyObject *self)
Definition: upb/python/message.c:235
regress.m
m
Definition: regress/regress.py:25
PyUpb_CMessage_DoClearField
void PyUpb_CMessage_DoClearField(PyObject *_self, const upb_FieldDef *f)
Definition: upb/python/message.c:1220
PyUpb_CMessage_InitAttributes
int PyUpb_CMessage_InitAttributes(PyObject *_self, PyObject *args, PyObject *kwargs)
Definition: upb/python/message.c:436
PyUpb_CMessage_SetFieldValue
int PyUpb_CMessage_SetFieldValue(PyObject *_self, const upb_FieldDef *field, PyObject *value, PyObject *exc)
Definition: upb/python/message.c:871


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:37