bindings/lua/msg.c
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 /*
29  * lupb_Message -- Message/Array/Map objects in Lua/C that wrap upb/msg.h
30  */
31 
32 #include "upb/msg.h"
33 
34 #include <float.h>
35 #include <math.h>
36 #include <stddef.h>
37 #include <stdlib.h>
38 #include <string.h>
39 
40 #include "lauxlib.h"
41 #include "upb/bindings/lua/upb.h"
42 #include "upb/json_decode.h"
43 #include "upb/json_encode.h"
44 #include "upb/port_def.inc"
45 #include "upb/reflection.h"
46 #include "upb/text_encode.h"
47 
48 /*
49  * Message/Map/Array objects. These objects form a directed graph: a message
50  * can contain submessages, arrays, and maps, which can then point to other
51  * messages. This graph can technically be cyclic, though this is an error and
52  * a cyclic graph cannot be serialized. So it's better to think of this as a
53  * tree of objects.
54  *
55  * The actual data exists at the upb level (upb_Message, upb_Map, upb_Array),
56  * independently of Lua. The upb objects contain all the canonical data and
57  * edges between objects. Lua wrapper objects expose the upb objects to Lua,
58  * but ultimately they are just wrappers. They pass through all reads and
59  * writes to the underlying upb objects.
60  *
61  * Each upb object lives in a upb arena. We have a Lua object to wrap the upb
62  * arena, but arenas are never exposed to the user. The Lua arena object just
63  * serves to own the upb arena and free it at the proper time, once the Lua GC
64  * has determined that there are no more references to anything that lives in
65  * that arena. All wrapper objects strongly reference the arena to which they
66  * belong.
67  *
68  * A global object cache stores a mapping of C pointer (upb_Message*,
69  * upb_Array*, upb_Map*) to a corresponding Lua wrapper. These references are
70  * weak so that the wrappers can be collected if they are no longer needed. A
71  * new wrapper object can always be recreated later.
72  *
73  * +-----+
74  * lupb_Arena |cache|-weak-+
75  * | ^ +-----+ |
76  * | | V
77  * Lua level | +------------lupb_Message
78  * ----------------|-----------------|------------------------------------------
79  * upb level | |
80  * | +----V----------------------------------+
81  * +->upb_Arena | upb_Message ...(empty arena storage) |
82  * +---------------------------------------+
83  *
84  * If the user creates a reference between two objects that have different
85  * arenas, we need to fuse the two arenas together, so that the blocks will
86  * outlive both arenas.
87  *
88  * +-------------------------->(fused)<----------------+
89  * | |
90  * V +-----+ V
91  * lupb_Arena +-weak-|cache|-weak-+ lupb_Arena
92  * | ^ | +-----+ | ^ |
93  * | | V V | |
94  * Lua level | +------------lupb_Message lupb_Message--+ |
95  * ----------------|-----------------|----------------------|-----------|------
96  * upb level | | | |
97  * | +----V--------+ +----V--------+ V
98  * +->upb_Arena | upb_Message | | upb_Message | upb_Arena
99  * +------|------+ +--^----------+
100  * +------------------+
101  * Key invariants:
102  * 1. every wrapper references the arena that contains it.
103  * 2. every fused arena includes all arenas that own upb objects reachable
104  * from that arena. In other words, when a wrapper references an arena,
105  * this is sufficient to ensure that any upb object reachable from that
106  * wrapper will stay alive.
107  *
108  * Additionally, every message object contains a strong reference to the
109  * corresponding Descriptor object. Likewise, array/map objects reference a
110  * Descriptor object if they are typed to store message values.
111  */
112 
113 #define LUPB_ARENA "lupb.arena"
114 #define LUPB_ARRAY "lupb.array"
115 #define LUPB_MAP "lupb.map"
116 #define LUPB_MSG "lupb.msg"
117 
118 #define LUPB_ARENA_INDEX 1
119 #define LUPB_MSGDEF_INDEX 2 /* For msg, and map/array that store msg */
120 
121 static void lupb_Message_Newmsgwrapper(lua_State* L, int narg,
122  upb_MessageValue val);
123 static upb_Message* lupb_msg_check(lua_State* L, int narg);
124 
125 static upb_CType lupb_checkfieldtype(lua_State* L, int narg) {
126  uint32_t n = lupb_checkuint32(L, narg);
127  bool ok = n >= kUpb_CType_Bool && n <= kUpb_CType_Bytes;
128  luaL_argcheck(L, ok, narg, "invalid field type");
129  return n;
130 }
131 
133 
134 /* lupb_cacheinit()
135  *
136  * Creates the global cache used by lupb_cacheget() and lupb_cacheset().
137  */
138 static void lupb_cacheinit(lua_State* L) {
139  /* Create our object cache. */
140  lua_newtable(L);
141 
142  /* Cache metatable gives the cache weak values */
143  lua_createtable(L, 0, 1);
144  lua_pushstring(L, "v");
145  lua_setfield(L, -2, "__mode");
146  lua_setmetatable(L, -2);
147 
148  /* Set cache in the registry. */
149  lua_rawsetp(L, LUA_REGISTRYINDEX, &cache_key);
150 }
151 
152 /* lupb_cacheget()
153  *
154  * Pushes cache[key] and returns true if this key is present in the cache.
155  * Otherwise returns false and leaves nothing on the stack.
156  */
157 static bool lupb_cacheget(lua_State* L, const void* key) {
158  if (key == NULL) {
159  lua_pushnil(L);
160  return true;
161  }
162 
163  lua_rawgetp(L, LUA_REGISTRYINDEX, &cache_key);
164  lua_rawgetp(L, -1, key);
165  if (lua_isnil(L, -1)) {
166  lua_pop(L, 2); /* Pop table, nil. */
167  return false;
168  } else {
169  lua_replace(L, -2); /* Replace cache table. */
170  return true;
171  }
172 }
173 
174 /* lupb_cacheset()
175  *
176  * Sets cache[key] = val, where "val" is the value at the top of the stack.
177  * Does not pop the value.
178  */
179 static void lupb_cacheset(lua_State* L, const void* key) {
180  lua_rawgetp(L, LUA_REGISTRYINDEX, &cache_key);
181  lua_pushvalue(L, -2);
182  lua_rawsetp(L, -2, key);
183  lua_pop(L, 1); /* Pop table. */
184 }
185 
186 /* lupb_Arena *****************************************************************/
187 
188 /* lupb_Arena only exists to wrap a upb_Arena. It is never exposed to users; it
189  * is an internal memory management detail. Other wrapper objects refer to this
190  * object from their userdata to keep the arena-owned data alive.
191  */
192 
193 typedef struct {
195 } lupb_Arena;
196 
197 static upb_Arena* lupb_Arena_check(lua_State* L, int narg) {
198  lupb_Arena* a = luaL_checkudata(L, narg, LUPB_ARENA);
199  return a->arena;
200 }
201 
204  a->arena = upb_Arena_New();
205  return a->arena;
206 }
207 
213 static void lupb_Arena_Fuse(lua_State* L, int to, int from) {
214  upb_Arena* to_arena = lupb_Arena_check(L, to);
215  upb_Arena* from_arena = lupb_Arena_check(L, from);
216  upb_Arena_Fuse(to_arena, from_arena);
217 }
218 
219 static void lupb_Arena_Fuseobjs(lua_State* L, int to, int from) {
222  lupb_Arena_Fuse(L, lua_absindex(L, -2), lua_absindex(L, -1));
223  lua_pop(L, 2);
224 }
225 
226 static int lupb_Arena_gc(lua_State* L) {
227  upb_Arena* a = lupb_Arena_check(L, 1);
228  upb_Arena_Free(a);
229  return 0;
230 }
231 
232 static const struct luaL_Reg lupb_Arena_mm[] = {{"__gc", lupb_Arena_gc},
233  {NULL, NULL}};
234 
235 /* lupb_Arenaget()
236  *
237  * Returns the arena from the given message, array, or map object.
238  */
239 static upb_Arena* lupb_Arenaget(lua_State* L, int narg) {
240  upb_Arena* arena;
242  arena = lupb_Arena_check(L, -1);
243  lua_pop(L, 1);
244  return arena;
245 }
246 
247 /* upb <-> Lua type conversion ************************************************/
248 
249 /* Whether string data should be copied into the containing arena. We can
250  * avoid a copy if the string data is only needed temporarily (like for a map
251  * lookup).
252  */
253 typedef enum {
254  LUPB_COPY, /* Copy string data into the arena. */
255  LUPB_REF /* Reference the Lua copy of the string data. */
256 } lupb_copy_t;
257 
263 static upb_MessageValue lupb_tomsgval(lua_State* L, upb_CType type, int narg,
264  int container, lupb_copy_t copy) {
266  switch (type) {
267  case kUpb_CType_Int32:
268  case kUpb_CType_Enum:
269  ret.int32_val = lupb_checkint32(L, narg);
270  break;
271  case kUpb_CType_Int64:
272  ret.int64_val = lupb_checkint64(L, narg);
273  break;
274  case kUpb_CType_UInt32:
275  ret.uint32_val = lupb_checkuint32(L, narg);
276  break;
277  case kUpb_CType_UInt64:
278  ret.uint64_val = lupb_checkuint64(L, narg);
279  break;
280  case kUpb_CType_Double:
281  ret.double_val = lupb_checkdouble(L, narg);
282  break;
283  case kUpb_CType_Float:
284  ret.float_val = lupb_checkfloat(L, narg);
285  break;
286  case kUpb_CType_Bool:
287  ret.bool_val = lupb_checkbool(L, narg);
288  break;
289  case kUpb_CType_String:
290  case kUpb_CType_Bytes: {
291  size_t len;
292  const char* ptr = lupb_checkstring(L, narg, &len);
293  switch (copy) {
294  case LUPB_COPY: {
296  char* data = upb_Arena_Malloc(arena, len);
297  memcpy(data, ptr, len);
299  break;
300  }
301  case LUPB_REF:
303  break;
304  }
305  break;
306  }
307  case kUpb_CType_Message:
308  ret.msg_val = lupb_msg_check(L, narg);
309  /* Typecheck message. */
312  luaL_argcheck(L, lua_rawequal(L, -1, -2), narg, "message type mismatch");
313  lua_pop(L, 2);
314  break;
315  }
316  return ret;
317 }
318 
319 void lupb_pushmsgval(lua_State* L, int container, upb_CType type,
320  upb_MessageValue val) {
321  switch (type) {
322  case kUpb_CType_Int32:
323  case kUpb_CType_Enum:
324  lupb_pushint32(L, val.int32_val);
325  return;
326  case kUpb_CType_Int64:
327  lupb_pushint64(L, val.int64_val);
328  return;
329  case kUpb_CType_UInt32:
331  return;
332  case kUpb_CType_UInt64:
334  return;
335  case kUpb_CType_Double:
336  lua_pushnumber(L, val.double_val);
337  return;
338  case kUpb_CType_Float:
339  lua_pushnumber(L, val.float_val);
340  return;
341  case kUpb_CType_Bool:
342  lua_pushboolean(L, val.bool_val);
343  return;
344  case kUpb_CType_String:
345  case kUpb_CType_Bytes:
346  lua_pushlstring(L, val.str_val.data, val.str_val.size);
347  return;
348  case kUpb_CType_Message:
349  assert(container);
350  if (!lupb_cacheget(L, val.msg_val)) {
352  }
353  return;
354  }
356 }
357 
358 /* lupb_array *****************************************************************/
359 
360 typedef struct {
363 } lupb_array;
364 
365 static lupb_array* lupb_array_check(lua_State* L, int narg) {
366  return luaL_checkudata(L, narg, LUPB_ARRAY);
367 }
368 
376 static int lupb_array_checkindex(lua_State* L, int narg, uint32_t max) {
377  uint32_t n = lupb_checkuint32(L, narg);
378  luaL_argcheck(L, n != 0 && n <= max, narg, "invalid array index");
379  return n - 1; /* Lua uses 1-based indexing. */
380 }
381 
382 /* lupb_array Public API */
383 
384 /* lupb_Array_New():
385  *
386  * Handles:
387  * Array(upb.TYPE_INT32)
388  * Array(message_type)
389  */
390 static int lupb_Array_New(lua_State* L) {
391  int arg_count = lua_gettop(L);
392  lupb_array* larray;
393  upb_Arena* arena;
394 
395  if (lua_type(L, 1) == LUA_TNUMBER) {
397  larray = lupb_newuserdata(L, sizeof(*larray), 1, LUPB_ARRAY);
398  larray->type = type;
399  } else {
401  larray = lupb_newuserdata(L, sizeof(*larray), 2, LUPB_ARRAY);
402  larray->type = kUpb_CType_Message;
403  lua_pushvalue(L, 1);
405  }
406 
409 
410  larray->arr = upb_Array_New(arena, larray->type);
411  lupb_cacheset(L, larray->arr);
412 
413  if (arg_count > 1) {
414  /* Set initial fields from table. */
415  int msg = arg_count + 1;
416  lua_pushnil(L);
417  while (lua_next(L, 2) != 0) {
418  lua_pushvalue(L, -2); /* now stack is key, val, key */
419  lua_insert(L, -3); /* now stack is key, key, val */
420  lua_settable(L, msg);
421  }
422  }
423 
424  return 1;
425 }
426 
427 /* lupb_Array_Newindex():
428  *
429  * Handles:
430  * array[idx] = val
431  *
432  * idx can be within the array or one past the end to extend.
433  */
434 static int lupb_Array_Newindex(lua_State* L) {
435  lupb_array* larray = lupb_array_check(L, 1);
436  size_t size = upb_Array_Size(larray->arr);
438  upb_MessageValue msgval = lupb_tomsgval(L, larray->type, 3, 1, LUPB_COPY);
439 
440  if (n == size) {
441  upb_Array_Append(larray->arr, msgval, lupb_Arenaget(L, 1));
442  } else {
443  upb_Array_Set(larray->arr, n, msgval);
444  }
445 
446  if (larray->type == kUpb_CType_Message) {
447  lupb_Arena_Fuseobjs(L, 1, 3);
448  }
449 
450  return 0; /* 1 for chained assignments? */
451 }
452 
453 /* lupb_array_index():
454  *
455  * Handles:
456  * array[idx] -> val
457  *
458  * idx must be within the array.
459  */
460 static int lupb_array_index(lua_State* L) {
461  lupb_array* larray = lupb_array_check(L, 1);
462  size_t size = upb_Array_Size(larray->arr);
464  upb_MessageValue val = upb_Array_Get(larray->arr, n);
465 
466  lupb_pushmsgval(L, 1, larray->type, val);
467 
468  return 1;
469 }
470 
471 /* lupb_array_len():
472  *
473  * Handles:
474  * #array -> len
475  */
476 static int lupb_array_len(lua_State* L) {
477  lupb_array* larray = lupb_array_check(L, 1);
478  lua_pushnumber(L, upb_Array_Size(larray->arr));
479  return 1;
480 }
481 
482 static const struct luaL_Reg lupb_array_mm[] = {
483  {"__index", lupb_array_index},
484  {"__len", lupb_array_len},
485  {"__newindex", lupb_Array_Newindex},
486  {NULL, NULL}};
487 
488 /* lupb_map *******************************************************************/
489 
490 typedef struct {
494 } lupb_map;
495 
496 #define MAP_MSGDEF_INDEX 1
497 
498 static lupb_map* lupb_map_check(lua_State* L, int narg) {
499  return luaL_checkudata(L, narg, LUPB_MAP);
500 }
501 
502 /* lupb_map Public API */
503 
511 static int lupb_Map_New(lua_State* L) {
512  upb_Arena* arena;
513  lupb_map* lmap;
514 
515  if (lua_type(L, 2) == LUA_TNUMBER) {
516  lmap = lupb_newuserdata(L, sizeof(*lmap), 1, LUPB_MAP);
517  lmap->value_type = lupb_checkfieldtype(L, 2);
518  } else {
520  lmap = lupb_newuserdata(L, sizeof(*lmap), 2, LUPB_MAP);
522  lua_pushvalue(L, 2);
524  }
525 
528 
529  lmap->key_type = lupb_checkfieldtype(L, 1);
530  lmap->map = upb_Map_New(arena, lmap->key_type, lmap->value_type);
531  lupb_cacheset(L, lmap->map);
532 
533  return 1;
534 }
535 
542 static int lupb_map_index(lua_State* L) {
543  lupb_map* lmap = lupb_map_check(L, 1);
545  upb_MessageValue val;
546 
547  if (upb_Map_Get(lmap->map, key, &val)) {
548  lupb_pushmsgval(L, 1, lmap->value_type, val);
549  } else {
550  lua_pushnil(L);
551  }
552 
553  return 1;
554 }
555 
562 static int lupb_map_len(lua_State* L) {
563  lupb_map* lmap = lupb_map_check(L, 1);
564  lua_pushnumber(L, upb_Map_Size(lmap->map));
565  return 1;
566 }
567 
575 static int lupb_Map_Newindex(lua_State* L) {
576  lupb_map* lmap = lupb_map_check(L, 1);
577  upb_Map* map = lmap->map;
579 
580  if (lua_isnil(L, 3)) {
582  } else {
583  upb_MessageValue val = lupb_tomsgval(L, lmap->value_type, 3, 1, LUPB_COPY);
584  upb_Map_Set(map, key, val, lupb_Arenaget(L, 1));
585  if (lmap->value_type == kUpb_CType_Message) {
586  lupb_Arena_Fuseobjs(L, 1, 3);
587  }
588  }
589 
590  return 0;
591 }
592 
593 static int lupb_MapIterator_Next(lua_State* L) {
594  int map = lua_upvalueindex(2);
595  size_t* iter = lua_touserdata(L, lua_upvalueindex(1));
596  lupb_map* lmap = lupb_map_check(L, map);
597 
598  if (upb_MapIterator_Next(lmap->map, iter)) {
601  lupb_pushmsgval(L, map, lmap->key_type, key);
602  lupb_pushmsgval(L, map, lmap->value_type, val);
603  return 2;
604  } else {
605  return 0;
606  }
607 }
608 
615 static int lupb_map_pairs(lua_State* L) {
616  size_t* iter = lua_newuserdata(L, sizeof(*iter));
617  lupb_map_check(L, 1);
618 
619  *iter = kUpb_Map_Begin;
620  lua_pushvalue(L, 1);
621 
622  /* Upvalues are [iter, lupb_map]. */
623  lua_pushcclosure(L, &lupb_MapIterator_Next, 2);
624 
625  return 1;
626 }
627 
628 /* upb_mapiter ]]] */
629 
630 static const struct luaL_Reg lupb_map_mm[] = {{"__index", lupb_map_index},
631  {"__len", lupb_map_len},
632  {"__newindex", lupb_Map_Newindex},
633  {"__pairs", lupb_map_pairs},
634  {NULL, NULL}};
635 
636 /* lupb_Message
637  * *******************************************************************/
638 
639 typedef struct {
641 } lupb_Message;
642 
643 /* lupb_Message helpers */
644 
645 static upb_Message* lupb_msg_check(lua_State* L, int narg) {
646  lupb_Message* msg = luaL_checkudata(L, narg, LUPB_MSG);
647  return msg->msg;
648 }
649 
650 static const upb_MessageDef* lupb_Message_Getmsgdef(lua_State* L, int msg) {
652  const upb_MessageDef* m = lupb_MessageDef_check(L, -1);
653  lua_pop(L, 1);
654  return m;
655 }
656 
657 static const upb_FieldDef* lupb_msg_tofield(lua_State* L, int msg, int field) {
658  size_t len;
659  const char* fieldname = luaL_checklstring(L, field, &len);
661  return upb_MessageDef_FindFieldByNameWithSize(m, fieldname, len);
662 }
663 
664 static const upb_FieldDef* lupb_msg_checkfield(lua_State* L, int msg,
665  int field) {
667  if (f == NULL) {
668  luaL_error(L, "no such field '%s'", lua_tostring(L, field));
669  }
670  return f;
671 }
672 
673 upb_Message* lupb_msg_pushnew(lua_State* L, int narg) {
674  const upb_MessageDef* m = lupb_MessageDef_check(L, narg);
675  lupb_Message* lmsg = lupb_newuserdata(L, sizeof(lupb_Message), 2, LUPB_MSG);
677 
679  lua_pushvalue(L, 1);
681 
682  lmsg->msg = upb_Message_New(m, arena);
683  lupb_cacheset(L, lmsg->msg);
684  return lmsg->msg;
685 }
686 
693 static void lupb_Message_Newmsgwrapper(lua_State* L, int narg,
694  upb_MessageValue val) {
695  lupb_Message* lmsg = lupb_newuserdata(L, sizeof(*lmsg), 2, LUPB_MSG);
696  lmsg->msg = (upb_Message*)val.msg_val; /* XXX: cast isn't great. */
697  lupb_cacheset(L, lmsg->msg);
698 
699  /* Copy both arena and msgdef into the wrapper. */
704 }
705 
712 static void* lupb_Message_Newud(lua_State* L, int narg, size_t size,
713  const char* type, const upb_FieldDef* f) {
715  /* Wrapper needs a reference to the msgdef. */
716  void* ud = lupb_newuserdata(L, size, 2, type);
720  return ud;
721  } else {
722  return lupb_newuserdata(L, size, 1, type);
723  }
724 }
725 
731 static void lupb_Message_Newwrapper(lua_State* L, int narg,
732  const upb_FieldDef* f,
734  if (upb_FieldDef_IsMap(f)) {
736  const upb_FieldDef* key_f =
738  const upb_FieldDef* val_f =
740  lupb_map* lmap =
741  lupb_Message_Newud(L, narg, sizeof(*lmap), LUPB_MAP, val_f);
742  lmap->key_type = upb_FieldDef_CType(key_f);
743  lmap->value_type = upb_FieldDef_CType(val_f);
744  lmap->map = val.map;
745  } else if (upb_FieldDef_IsRepeated(f)) {
746  lupb_array* larr =
747  lupb_Message_Newud(L, narg, sizeof(*larr), LUPB_ARRAY, f);
748  larr->type = upb_FieldDef_CType(f);
749  larr->arr = val.array;
750  } else {
751  lupb_Message* lmsg =
752  lupb_Message_Newud(L, narg, sizeof(*lmsg), LUPB_MSG, f);
753  lmsg->msg = val.msg;
754  }
755 
756  /* Copy arena ref to new wrapper. This may be a different arena than the
757  * underlying data was originally constructed from, but if so both arenas
758  * must be in the same group. */
761 
762  lupb_cacheset(L, val.msg);
763 }
764 
770 static void lupb_msg_typechecksubmsg(lua_State* L, int narg, int msgarg,
771  const upb_FieldDef* f) {
772  /* Typecheck this map's msgdef against this message field. */
776  luaL_argcheck(L, lua_rawequal(L, -1, -2), narg, "message type mismatch");
777  lua_pop(L, 2);
778 }
779 
780 /* lupb_Message Public API */
781 
789 int lupb_MessageDef_call(lua_State* L) {
790  int arg_count = lua_gettop(L);
791  lupb_msg_pushnew(L, 1);
792 
793  if (arg_count > 1) {
794  /* Set initial fields from table. */
795  int msg = arg_count + 1;
796  lua_pushnil(L);
797  while (lua_next(L, 2) != 0) {
798  lua_pushvalue(L, -2); /* now stack is key, val, key */
799  lua_insert(L, -3); /* now stack is key, key, val */
800  lua_settable(L, msg);
801  }
802  }
803 
804  return 1;
805 }
806 
815 static int lupb_msg_index(lua_State* L) {
817  const upb_FieldDef* f = lupb_msg_checkfield(L, 1, 2);
818 
820  /* Wrapped type; get or create wrapper. */
823  if (!lupb_cacheget(L, val.msg)) {
824  lupb_Message_Newwrapper(L, 1, f, val);
825  }
826  } else {
827  /* Value type, just push value and return .*/
830  }
831 
832  return 1;
833 }
834 
843 static int lupb_Message_Newindex(lua_State* L) {
845  const upb_FieldDef* f = lupb_msg_checkfield(L, 1, 2);
846  upb_MessageValue msgval;
847  bool merge_arenas = true;
848 
849  if (upb_FieldDef_IsMap(f)) {
850  lupb_map* lmap = lupb_map_check(L, 3);
852  const upb_FieldDef* key_f =
854  const upb_FieldDef* val_f =
858  luaL_argcheck(L, lmap->key_type == key_type, 3, "key type mismatch");
859  luaL_argcheck(L, lmap->value_type == value_type, 3, "value type mismatch");
861  lupb_msg_typechecksubmsg(L, 3, 1, val_f);
862  }
863  msgval.map_val = lmap->map;
864  } else if (upb_FieldDef_IsRepeated(f)) {
865  lupb_array* larr = lupb_array_check(L, 3);
867  luaL_argcheck(L, larr->type == type, 3, "array type mismatch");
868  if (type == kUpb_CType_Message) {
869  lupb_msg_typechecksubmsg(L, 3, 1, f);
870  }
871  msgval.array_val = larr->arr;
872  } else if (upb_FieldDef_IsSubMessage(f)) {
874  lupb_msg_typechecksubmsg(L, 3, 1, f);
875  msgval.msg_val = msg;
876  } else {
877  msgval = lupb_tomsgval(L, upb_FieldDef_CType(f), 3, 1, LUPB_COPY);
878  merge_arenas = false;
879  }
880 
881  if (merge_arenas) {
882  lupb_Arena_Fuseobjs(L, 1, 3);
883  }
884 
885  upb_Message_Set(msg, f, msgval, lupb_Arenaget(L, 1));
886 
887  /* Return the new value for chained assignments. */
888  lua_pushvalue(L, 3);
889  return 1;
890 }
891 
900 static int lupb_msg_tostring(lua_State* L) {
902  const upb_MessageDef* m;
903  char buf[1024];
904  size_t size;
905 
907  m = lupb_MessageDef_check(L, -1);
908 
909  size = upb_TextEncode(msg, m, NULL, 0, buf, sizeof(buf));
910 
911  if (size < sizeof(buf)) {
912  lua_pushlstring(L, buf, size);
913  } else {
914  char* ptr = malloc(size + 1);
915  upb_TextEncode(msg, m, NULL, 0, ptr, size + 1);
916  lua_pushlstring(L, ptr, size);
917  free(ptr);
918  }
919 
920  return 1;
921 }
922 
923 static const struct luaL_Reg lupb_msg_mm[] = {
924  {"__index", lupb_msg_index},
925  {"__newindex", lupb_Message_Newindex},
926  {"__tostring", lupb_msg_tostring},
927  {NULL, NULL}};
928 
929 /* lupb_Message toplevel
930  * **********************************************************/
931 
932 static int lupb_getoptions(lua_State* L, int narg) {
933  int options = 0;
934  if (lua_gettop(L) >= narg) {
935  size_t len = lua_rawlen(L, narg);
936  for (size_t i = 1; i <= len; i++) {
937  lua_rawgeti(L, narg, i);
938  options |= lupb_checkuint32(L, -1);
939  lua_pop(L, 1);
940  }
941  }
942  return options;
943 }
944 
951 static int lupb_decode(lua_State* L) {
952  size_t len;
954  const char* pb = lua_tolstring(L, 2, &len);
957  upb_Arena* arena = lupb_Arenaget(L, -1);
958  char* buf;
959 
960  /* Copy input data to arena, message will reference it. */
962  memcpy(buf, pb, len);
963 
966 
967  if (status != kUpb_DecodeStatus_Ok) {
968  lua_pushstring(L, "Error decoding protobuf.");
969  return lua_error(L);
970  }
971 
972  return 1;
973 }
974 
981 static int lupb_Encode(lua_State* L) {
982  const upb_Message* msg = lupb_msg_check(L, 1);
985  int options = lupb_getoptions(L, 2);
986  upb_Arena* arena;
987  size_t size;
988  char* result;
989 
991  result = upb_Encode(msg, (const void*)layout, options, arena, &size);
992 
993  if (!result) {
994  lua_pushstring(L, "Error encoding protobuf.");
995  return lua_error(L);
996  }
997 
998  lua_pushlstring(L, result, size);
999 
1000  return 1;
1001 }
1002 
1010 static int lupb_jsondecode(lua_State* L) {
1011  size_t len;
1012  const upb_MessageDef* m = lupb_MessageDef_check(L, 1);
1013  const char* json = lua_tolstring(L, 2, &len);
1014  int options = lupb_getoptions(L, 3);
1015  upb_Message* msg;
1016  upb_Arena* arena;
1018 
1019  msg = lupb_msg_pushnew(L, 1);
1020  arena = lupb_Arenaget(L, -1);
1022  upb_JsonDecode(json, len, msg, m, NULL, options, arena, &status);
1024 
1025  return 1;
1026 }
1027 
1034 static int lupb_jsonencode(lua_State* L) {
1037  int options = lupb_getoptions(L, 2);
1038  char buf[1024];
1039  size_t size;
1041 
1043  size = upb_JsonEncode(msg, m, NULL, options, buf, sizeof(buf), &status);
1045 
1046  if (size < sizeof(buf)) {
1047  lua_pushlstring(L, buf, size);
1048  } else {
1049  char* ptr = malloc(size + 1);
1050  upb_JsonEncode(msg, m, NULL, options, ptr, size + 1, &status);
1052  lua_pushlstring(L, ptr, size);
1053  free(ptr);
1054  }
1055 
1056  return 1;
1057 }
1058 
1065 static int lupb_textencode(lua_State* L) {
1068  int options = lupb_getoptions(L, 2);
1069  char buf[1024];
1070  size_t size;
1071 
1072  size = upb_TextEncode(msg, m, NULL, options, buf, sizeof(buf));
1073 
1074  if (size < sizeof(buf)) {
1075  lua_pushlstring(L, buf, size);
1076  } else {
1077  char* ptr = malloc(size + 1);
1078  upb_TextEncode(msg, m, NULL, options, ptr, size + 1);
1079  lua_pushlstring(L, ptr, size);
1080  free(ptr);
1081  }
1082 
1083  return 1;
1084 }
1085 
1086 static void lupb_setfieldi(lua_State* L, const char* field, int i) {
1087  lua_pushinteger(L, i);
1088  lua_setfield(L, -2, field);
1089 }
1090 
1091 static const struct luaL_Reg lupb_msg_toplevel_m[] = {
1092  {"Array", lupb_Array_New}, {"Map", lupb_Map_New},
1093  {"decode", lupb_decode}, {"encode", lupb_Encode},
1094  {"json_decode", lupb_jsondecode}, {"json_encode", lupb_jsonencode},
1095  {"text_encode", lupb_textencode}, {NULL, NULL}};
1096 
1097 void lupb_msg_registertypes(lua_State* L) {
1098  lupb_setfuncs(L, lupb_msg_toplevel_m);
1099 
1104 
1105  lupb_setfieldi(L, "TXTENC_SINGLELINE", UPB_TXTENC_SINGLELINE);
1106  lupb_setfieldi(L, "TXTENC_SKIPUNKNOWN", UPB_TXTENC_SKIPUNKNOWN);
1107  lupb_setfieldi(L, "TXTENC_NOSORT", UPB_TXTENC_NOSORT);
1108 
1109  lupb_setfieldi(L, "ENCODE_DETERMINISTIC", kUpb_Encode_Deterministic);
1110  lupb_setfieldi(L, "ENCODE_SKIPUNKNOWN", kUpb_Encode_SkipUnknown);
1111 
1112  lupb_setfieldi(L, "JSONENC_EMITDEFAULTS", upb_JsonEncode_EmitDefaults);
1113  lupb_setfieldi(L, "JSONENC_PROTONAMES", upb_JsonEncode_UseProtoNames);
1114 
1115  lupb_setfieldi(L, "JSONDEC_IGNOREUNKNOWN", upb_JsonDecode_IgnoreUnknown);
1116 
1117  lupb_cacheinit(L);
1118 }
lupb_Map_New
static int lupb_Map_New(lua_State *L)
Definition: bindings/lua/msg.c:511
upb_MutableMessageValue::array
upb_Array * array
Definition: upb/upb/reflection.h:57
lupb_map_mm
static const struct luaL_Reg lupb_map_mm[]
Definition: bindings/lua/msg.c:630
lupb_newuserdata
void * lupb_newuserdata(lua_State *L, size_t size, int n, const char *type)
Definition: upb/upb/bindings/lua/upb.c:80
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
UPB_TXTENC_NOSORT
@ UPB_TXTENC_NOSORT
Definition: text_encode.h:45
upb_Array_New
upb_Array * upb_Array_New(upb_Arena *a, upb_CType type)
Definition: reflection.c:358
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
upb_MessageValue::uint32_val
uint32_t uint32_val
Definition: upb/upb/reflection.h:46
kUpb_CType_String
@ kUpb_CType_String
Definition: upb/upb/upb.h:296
upb_MapIterator_Key
upb_MessageValue upb_MapIterator_Key(const upb_Map *map, size_t iter)
Definition: reflection.c:461
upb_MessageValue::int64_val
int64_t int64_val
Definition: upb/upb/reflection.h:45
kUpb_CType_UInt32
@ kUpb_CType_UInt32
Definition: upb/upb/upb.h:290
upb_CType
upb_CType
Definition: upb/upb/upb.h:286
kUpb_CType_Int32
@ kUpb_CType_Int32
Definition: upb/upb/upb.h:289
upb_Map_Size
size_t upb_Map_Size(const upb_Map *map)
Definition: reflection.c:430
lupb_map
Definition: bindings/lua/msg.c:490
LUPB_ARENA_INDEX
#define LUPB_ARENA_INDEX
Definition: bindings/lua/msg.c:118
lupb_Message_Getmsgdef
static const upb_MessageDef * lupb_Message_Getmsgdef(lua_State *L, int msg)
Definition: bindings/lua/msg.c:650
kUpb_Map_Begin
#define kUpb_Map_Begin
Definition: upb/upb/upb.h:329
lupb_Arena_check
static upb_Arena * lupb_Arena_check(lua_State *L, int narg)
Definition: bindings/lua/msg.c:197
kUpb_Encode_Deterministic
@ kUpb_Encode_Deterministic
Definition: encode.h:51
lupb_MessageDef_check
const upb_MessageDef * lupb_MessageDef_check(lua_State *L, int narg)
Definition: upb/upb/bindings/lua/def.c:322
upb_MessageDef_MiniTable
const upb_MiniTable * upb_MessageDef_MiniTable(const upb_MessageDef *m)
Definition: upb/upb/def.c:818
upb_MutableMessageValue::map
upb_Map * map
Definition: upb/upb/reflection.h:55
kUpb_Encode_SkipUnknown
@ kUpb_Encode_SkipUnknown
Definition: encode.h:54
lupb_Arena
Definition: bindings/lua/msg.c:193
LUPB_REF
@ LUPB_REF
Definition: bindings/lua/msg.c:255
lupb_array_mm
static const struct luaL_Reg lupb_array_mm[]
Definition: bindings/lua/msg.c:482
lupb_cacheget
static bool lupb_cacheget(lua_State *L, const void *key)
Definition: bindings/lua/msg.c:157
upb_StringView::data
const char * data
Definition: upb/upb/upb.h:73
upb_Decode
upb_DecodeStatus upb_Decode(const char *buf, size_t size, void *msg, const upb_MiniTable *l, const upb_ExtensionRegistry *extreg, int options, upb_Arena *arena)
Definition: decode.c:1076
upb_MessageDef
Definition: upb/upb/def.c:100
lupb_Arena_Fuse
static void lupb_Arena_Fuse(lua_State *L, int to, int from)
Definition: bindings/lua/msg.c:213
lupb_checkint32
int32_t lupb_checkint32(lua_State *L, int narg)
string.h
options
double_dict options[]
Definition: capstone_test.c:55
copy
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
Definition: message_compress.cc:145
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
kUpb_CType_Bytes
@ kUpb_CType_Bytes
Definition: upb/upb/upb.h:297
kUpb_DecodeStatus_Ok
@ kUpb_DecodeStatus_Ok
Definition: decode.h:72
lupb_checkuint64
uint64_t lupb_checkuint64(lua_State *L, int narg)
lupb_Arena_gc
static int lupb_Arena_gc(lua_State *L)
Definition: bindings/lua/msg.c:226
upb_MessageValue::str_val
upb_StringView str_val
Definition: upb/upb/reflection.h:51
status
absl::Status status
Definition: rls.cc:251
upb_MiniTable
Definition: msg_internal.h:185
upb_JsonEncode
size_t upb_JsonEncode(const upb_Message *msg, const upb_MessageDef *m, const upb_DefPool *ext_pool, int options, char *buf, size_t size, upb_Status *status)
Definition: json_encode.c:757
lupb_Arena::arena
upb_Arena * arena
Definition: bindings/lua/msg.c:194
lupb_Message_Newwrapper
static void lupb_Message_Newwrapper(lua_State *L, int narg, const upb_FieldDef *f, upb_MutableMessageValue val)
Definition: bindings/lua/msg.c:731
lupb_checkfieldtype
static upb_CType lupb_checkfieldtype(lua_State *L, int narg)
Definition: bindings/lua/msg.c:125
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
lupb_tomsgval
static upb_MessageValue lupb_tomsgval(lua_State *L, upb_CType type, int narg, int container, lupb_copy_t copy)
Definition: bindings/lua/msg.c:263
kUpb_MapEntry_ValueFieldNumber
#define kUpb_MapEntry_ValueFieldNumber
Definition: upb/upb/def.h:161
upb_MessageValue::int32_val
int32_t int32_val
Definition: upb/upb/reflection.h:44
to
size_t to
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1385
LUPB_COPY
@ LUPB_COPY
Definition: bindings/lua/msg.c:254
lupb_textencode
static int lupb_textencode(lua_State *L)
Definition: bindings/lua/msg.c:1065
upb_Array_Get
upb_MessageValue upb_Array_Get(const upb_Array *arr, size_t i)
Definition: reflection.c:364
lupb_Arenaget
static upb_Arena * lupb_Arenaget(lua_State *L, int narg)
Definition: bindings/lua/msg.c:239
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
upb_MutableMessageValue::msg
upb_Message * msg
Definition: upb/upb/reflection.h:56
json_encode.h
upb_Arena_New
UPB_INLINE upb_Arena * upb_Arena_New(void)
Definition: upb/upb/upb.h:267
kUpb_CType_Int64
@ kUpb_CType_Int64
Definition: upb/upb/upb.h:294
upb_Status_Clear
void upb_Status_Clear(upb_Status *status)
Definition: upb/upb/upb.c:44
upb_MessageValue::double_val
double double_val
Definition: upb/upb/reflection.h:43
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
json_decode.h
kUpb_MapEntry_KeyFieldNumber
#define kUpb_MapEntry_KeyFieldNumber
Definition: upb/upb/def.h:160
msg.h
upb_MessageValue::array_val
const upb_Array * array_val
Definition: upb/upb/reflection.h:50
lupb_checkstring
const char * lupb_checkstring(lua_State *L, int narg, size_t *len)
Definition: upb/upb/bindings/lua/upb.c:172
upb_MessageValue::bool_val
bool bool_val
Definition: upb/upb/reflection.h:41
upb_Message_New
upb_Message * upb_Message_New(const upb_MessageDef *m, upb_Arena *a)
Definition: reflection.c:95
lupb_pushuint32
void lupb_pushuint32(lua_State *L, uint32_t val)
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
upb_MessageValue
Definition: upb/upb/reflection.h:40
lupb_pushmsgval
void lupb_pushmsgval(lua_State *L, int container, upb_CType type, upb_MessageValue val)
Definition: bindings/lua/msg.c:319
lupb_pushuint64
void lupb_pushuint64(lua_State *L, uint64_t val)
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
lupb_msg_checkfield
static const upb_FieldDef * lupb_msg_checkfield(lua_State *L, int msg, int field)
Definition: bindings/lua/msg.c:664
lupb_Array_New
static int lupb_Array_New(lua_State *L)
Definition: bindings/lua/msg.c:390
lua_setiuservalue
int lua_setiuservalue(lua_State *L, int index, int n)
Definition: upb/upb/bindings/lua/upb.c:98
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
lupb_checkdouble
double lupb_checkdouble(lua_State *L, int narg)
Definition: upb/upb/bindings/lua/upb.c:215
lupb_array_checkindex
static int lupb_array_checkindex(lua_State *L, int narg, uint32_t max)
Definition: bindings/lua/msg.c:376
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
LUPB_ARRAY
#define LUPB_ARRAY
Definition: bindings/lua/msg.c:114
lupb_array::arr
upb_Array * arr
Definition: bindings/lua/msg.c:361
lupb_decode
static int lupb_decode(lua_State *L)
Definition: bindings/lua/msg.c:951
upb_FieldDef_IsMap
bool upb_FieldDef_IsMap(const upb_FieldDef *f)
Definition: upb/upb/def.c:659
lupb_array_check
static lupb_array * lupb_array_check(lua_State *L, int narg)
Definition: bindings/lua/msg.c:365
kUpb_CType_Double
@ kUpb_CType_Double
Definition: upb/upb/upb.h:293
lupb_pushint32
void lupb_pushint32(lua_State *L, int32_t val)
upb_MapIterator_Next
bool upb_MapIterator_Next(const upb_Map *map, size_t *iter)
Definition: reflection.c:448
lua_getiuservalue
int lua_getiuservalue(lua_State *L, int index, int n)
Definition: upb/upb/bindings/lua/upb.c:106
max
int max
Definition: bloaty/third_party/zlib/examples/enough.c:170
upb_StringView::size
size_t size
Definition: upb/upb/upb.h:74
lupb_map_index
static int lupb_map_index(lua_State *L)
Definition: bindings/lua/msg.c:542
lupb_jsonencode
static int lupb_jsonencode(lua_State *L)
Definition: bindings/lua/msg.c:1034
lupb_checkstatus
void lupb_checkstatus(lua_State *L, upb_Status *s)
Definition: upb/upb/bindings/lua/upb.c:72
lupb_msg_tostring
static int lupb_msg_tostring(lua_State *L)
Definition: bindings/lua/msg.c:900
lupb_map::key_type
upb_CType key_type
Definition: bindings/lua/msg.c:492
lupb_register_type
void lupb_register_type(lua_State *L, const char *name, const luaL_Reg *m, const luaL_Reg *mm)
Definition: upb/upb/bindings/lua/upb.c:132
lupb_pushint64
void lupb_pushint64(lua_State *L, int64_t val)
upb_Array
Definition: msg_internal.h:424
upb_Arena_Malloc
UPB_INLINE void * upb_Arena_Malloc(upb_Arena *a, size_t size)
Definition: upb/upb/upb.h:222
LUPB_MSGDEF_INDEX
#define LUPB_MSGDEF_INDEX
Definition: bindings/lua/msg.c:119
lupb_cacheset
static void lupb_cacheset(lua_State *L, const void *key)
Definition: bindings/lua/msg.c:179
upb_MessageValue::uint64_val
uint64_t uint64_val
Definition: upb/upb/reflection.h:47
lupb_Message_Newmsgwrapper
static void lupb_Message_Newmsgwrapper(lua_State *L, int narg, upb_MessageValue val)
Definition: bindings/lua/msg.c:693
lupb_checkint64
int64_t lupb_checkint64(lua_State *L, int narg)
lupb_Array_Newindex
static int lupb_Array_Newindex(lua_State *L)
Definition: bindings/lua/msg.c:434
kUpb_DecodeOption_AliasString
@ kUpb_DecodeOption_AliasString
Definition: decode.h:47
reflection.h
absl::compare_internal::value_type
int8_t value_type
Definition: abseil-cpp/absl/types/compare.h:45
lupb_msg_typechecksubmsg
static void lupb_msg_typechecksubmsg(lua_State *L, int narg, int msgarg, const upb_FieldDef *f)
Definition: bindings/lua/msg.c:770
lupb_checkfloat
float lupb_checkfloat(lua_State *L, int narg)
Definition: upb/upb/bindings/lua/upb.c:227
upb_Status
Definition: upb/upb/upb.h:52
lupb_array
Definition: bindings/lua/msg.c:360
upb.h
lupb_map::value_type
upb_CType value_type
Definition: bindings/lua/msg.c:493
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
upb_MessageValue::msg_val
const upb_Message * msg_val
Definition: upb/upb/reflection.h:49
upb_Array_Append
bool upb_Array_Append(upb_Array *arr, upb_MessageValue val, upb_Arena *arena)
Definition: reflection.c:380
lupb_Message
Definition: bindings/lua/msg.c:639
MAP_MSGDEF_INDEX
#define MAP_MSGDEF_INDEX
Definition: bindings/lua/msg.c:496
upb_FieldDef_CType
upb_CType upb_FieldDef_CType(const upb_FieldDef *f)
Definition: upb/upb/def.c:500
lupb_checkbool
bool lupb_checkbool(lua_State *L, int narg)
Definition: upb/upb/bindings/lua/upb.c:163
lupb_msg_pushnew
upb_Message * lupb_msg_pushnew(lua_State *L, int narg)
Definition: bindings/lua/msg.c:673
layout
MessageLayout * layout
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:809
lupb_Map_Newindex
static int lupb_Map_Newindex(lua_State *L)
Definition: bindings/lua/msg.c:575
lupb_Message_Newindex
static int lupb_Message_Newindex(lua_State *L)
Definition: bindings/lua/msg.c:843
upb_Message
void upb_Message
Definition: msg.h:49
lupb_copy_t
lupb_copy_t
Definition: bindings/lua/msg.c:253
upb_FieldDef_MessageSubDef
const upb_MessageDef * upb_FieldDef_MessageSubDef(const upb_FieldDef *f)
Definition: upb/upb/def.c:619
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
upb_JsonEncode_UseProtoNames
@ upb_JsonEncode_UseProtoNames
Definition: json_encode.h:43
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
upb_Map_Set
bool upb_Map_Set(upb_Map *map, upb_MessageValue key, upb_MessageValue val, upb_Arena *arena)
Definition: reflection.c:439
lupb_msg_tofield
static const upb_FieldDef * lupb_msg_tofield(lua_State *L, int msg, int field)
Definition: bindings/lua/msg.c:657
lupb_Encode
static int lupb_Encode(lua_State *L)
Definition: bindings/lua/msg.c:981
upb_FieldDef
Definition: upb/upb/def.c:56
upb_DecodeStatus
upb_DecodeStatus
Definition: decode.h:71
upb_MessageValue::map_val
const upb_Map * map_val
Definition: upb/upb/reflection.h:48
upb_Array_Size
size_t upb_Array_Size(const upb_Array *arr)
Definition: reflection.c:362
LUPB_UNREACHABLE
#define LUPB_UNREACHABLE()
Definition: upb/upb/bindings/lua/upb.h:126
kUpb_CType_Float
@ kUpb_CType_Float
Definition: upb/upb/upb.h:288
upb_Array_Set
void upb_Array_Set(upb_Array *arr, size_t i, upb_MessageValue val)
Definition: reflection.c:373
lupb_cacheinit
static void lupb_cacheinit(lua_State *L)
Definition: bindings/lua/msg.c:138
LUPB_MSG
#define LUPB_MSG
Definition: bindings/lua/msg.c:116
cache_key
char cache_key
Definition: bindings/lua/msg.c:132
upb_TextEncode
size_t upb_TextEncode(const upb_Message *msg, const upb_MessageDef *m, const upb_DefPool *ext_pool, int options, char *buf, size_t size)
Definition: text_encode.c:455
upb_Encode
char * upb_Encode(const void *msg, const upb_MiniTable *l, int options, upb_Arena *arena, size_t *size)
Definition: encode.c:573
lupb_msg_index
static int lupb_msg_index(lua_State *L)
Definition: bindings/lua/msg.c:815
lupb_map_len
static int lupb_map_len(lua_State *L)
Definition: bindings/lua/msg.c:562
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
upb_JsonDecode_IgnoreUnknown
@ upb_JsonDecode_IgnoreUnknown
Definition: json_decode.h:37
lupb_msg_toplevel_m
static const struct luaL_Reg lupb_msg_toplevel_m[]
Definition: bindings/lua/msg.c:1091
upb_Map_Delete
bool upb_Map_Delete(upb_Map *map, upb_MessageValue key)
Definition: reflection.c:444
lupb_array::type
upb_CType type
Definition: bindings/lua/msg.c:362
upb_Message_Mutable
upb_MutableMessageValue upb_Message_Mutable(upb_Message *msg, const upb_FieldDef *f, upb_Arena *a)
Definition: reflection.c:164
upb_Message_Get
upb_MessageValue upb_Message_Get(const upb_Message *msg, const upb_FieldDef *f)
Definition: reflection.c:146
upb_FieldDef_IsRepeated
bool upb_FieldDef_IsRepeated(const upb_FieldDef *f)
Definition: upb/upb/def.c:651
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
upb_JsonDecode
bool upb_JsonDecode(const char *buf, size_t size, upb_Message *msg, const upb_MessageDef *m, const upb_DefPool *symtab, int options, upb_Arena *arena, upb_Status *status)
Definition: json_decode.c:1486
lupb_Arena_pushnew
upb_Arena * lupb_Arena_pushnew(lua_State *L)
Definition: bindings/lua/msg.c:202
L
lua_State * L
Definition: upb/upb/bindings/lua/main.c:35
upb_JsonEncode_EmitDefaults
@ upb_JsonEncode_EmitDefaults
Definition: json_encode.h:39
lupb_map_pairs
static int lupb_map_pairs(lua_State *L)
Definition: bindings/lua/msg.c:615
upb_StringView_FromDataAndSize
UPB_INLINE upb_StringView upb_StringView_FromDataAndSize(const char *data, size_t size)
Definition: upb/upb/upb.h:77
lupb_setfieldi
static void lupb_setfieldi(lua_State *L, const char *field, int i)
Definition: bindings/lua/msg.c:1086
lupb_msg_check
static upb_Message * lupb_msg_check(lua_State *L, int narg)
Definition: bindings/lua/msg.c:645
upb_MessageValue::float_val
float float_val
Definition: upb/upb/reflection.h:42
ok
bool ok
Definition: async_end2end_test.cc:197
lupb_checkuint32
uint32_t lupb_checkuint32(lua_State *L, int narg)
UPB_TXTENC_SKIPUNKNOWN
@ UPB_TXTENC_SKIPUNKNOWN
Definition: text_encode.h:42
lupb_msg_mm
static const struct luaL_Reg lupb_msg_mm[]
Definition: bindings/lua/msg.c:923
upb_MutableMessageValue
Definition: upb/upb/reflection.h:54
lupb_array_index
static int lupb_array_index(lua_State *L)
Definition: bindings/lua/msg.c:460
upb_Map_Get
bool upb_Map_Get(const upb_Map *map, upb_MessageValue key, upb_MessageValue *val)
Definition: reflection.c:432
lupb_MessageDef_pushsubmsgdef
void lupb_MessageDef_pushsubmsgdef(lua_State *L, const upb_FieldDef *f)
Definition: upb/upb/bindings/lua/def.c:89
upb_FieldDef_IsSubMessage
bool upb_FieldDef_IsSubMessage(const upb_FieldDef *f)
Definition: upb/upb/def.c:642
kUpb_CType_Bool
@ kUpb_CType_Bool
Definition: upb/upb/upb.h:287
LUPB_ARENA
#define LUPB_ARENA
Definition: bindings/lua/msg.c:113
lupb_jsondecode
static int lupb_jsondecode(lua_State *L)
Definition: bindings/lua/msg.c:1010
kUpb_CType_Enum
@ kUpb_CType_Enum
Definition: upb/upb/upb.h:291
upb_Map
Definition: msg_internal.h:581
iter
Definition: test_winkernel.cpp:47
upb_Map_New
upb_Map * upb_Map_New(upb_Arena *a, upb_CType key_type, upb_CType value_type)
Definition: reflection.c:425
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
kUpb_CType_UInt64
@ kUpb_CType_UInt64
Definition: upb/upb/upb.h:295
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
key_type
upb_fieldtype_t key_type
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1071
lupb_array_len
static int lupb_array_len(lua_State *L)
Definition: bindings/lua/msg.c:476
regress.m
m
Definition: regress/regress.py:25
upb_Message_Set
bool upb_Message_Set(upb_Message *msg, const upb_FieldDef *f, upb_MessageValue val, upb_Arena *a)
Definition: reflection.c:202
lupb_msg_registertypes
void lupb_msg_registertypes(lua_State *L)
Definition: bindings/lua/msg.c:1097
LUPB_MAP
#define LUPB_MAP
Definition: bindings/lua/msg.c:115
lupb_MessageDef_call
int lupb_MessageDef_call(lua_State *L)
Definition: bindings/lua/msg.c:789
upb_MapIterator_Value
upb_MessageValue upb_MapIterator_Value(const upb_Map *map, size_t iter)
Definition: reflection.c:470
lupb_Arena_mm
static const struct luaL_Reg lupb_Arena_mm[]
Definition: bindings/lua/msg.c:232
upb_MessageDef_FindFieldByNumber
const upb_FieldDef * upb_MessageDef_FindFieldByNumber(const upb_MessageDef *m, uint32_t i)
Definition: upb/upb/def.c:721
lupb_Message::msg
upb_Message * msg
Definition: bindings/lua/msg.c:640
text_encode.h
lupb_Message_Newud
static void * lupb_Message_Newud(lua_State *L, int narg, size_t size, const char *type, const upb_FieldDef *f)
Definition: bindings/lua/msg.c:712
upb_Arena
Definition: upb_internal.h:36
lupb_Arena_Fuseobjs
static void lupb_Arena_Fuseobjs(lua_State *L, int to, int from)
Definition: bindings/lua/msg.c:219
upb_MessageDef_FindFieldByNameWithSize
const upb_FieldDef * upb_MessageDef_FindFieldByNameWithSize(const upb_MessageDef *m, const char *name, size_t len)
Definition: upb/upb/def.c:728
upb_Arena_Fuse
bool upb_Arena_Fuse(upb_Arena *a1, upb_Arena *a2)
Definition: upb/upb/upb.c:299
upb_Arena_Free
void upb_Arena_Free(upb_Arena *a)
Definition: upb/upb/upb.c:273
kUpb_CType_Message
@ kUpb_CType_Message
Definition: upb/upb/upb.h:292
container
static struct async_container * container
Definition: benchmark-million-async.c:33
lupb_map_check
static lupb_map * lupb_map_check(lua_State *L, int narg)
Definition: bindings/lua/msg.c:498
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
lupb_MapIterator_Next
static int lupb_MapIterator_Next(lua_State *L)
Definition: bindings/lua/msg.c:593
UPB_TXTENC_SINGLELINE
@ UPB_TXTENC_SINGLELINE
Definition: text_encode.h:39
lupb_getoptions
static int lupb_getoptions(lua_State *L, int narg)
Definition: bindings/lua/msg.c:932
lupb_map::map
upb_Map * map
Definition: bindings/lua/msg.c:491


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:30