1/*
2** Data structures for message tables, used for parsing and serialization.
3** This are much lighter-weight than full reflection, but they are do not
4** have enough information to convert to text format, JSON, etc.
5**
6** The definitions in this file are internal to upb.
7**/
8
9#ifndef UPB_MSG_H_
10#define UPB_MSG_H_
11
12#include <stdint.h>
13#include <string.h>
14#include "upb/upb.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20typedef void upb_msg;
21
22/** upb_msglayout *************************************************************/
23
24/* upb_msglayout represents the memory layout of a given upb_msgdef. The
25 * members are public so generated code can initialize them, but users MUST NOT
26 * read or write any of its members. */
27
28typedef struct {
29 uint32_t number;
30 uint16_t offset;
31 int16_t presence; /* If >0, hasbit_index+1. If <0, oneof_index+1. */
32 uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */
33 uint8_t descriptortype;
34 uint8_t label;
35} upb_msglayout_field;
36
37typedef struct upb_msglayout {
38 const struct upb_msglayout *const* submsgs;
39 const upb_msglayout_field *fields;
40 /* Must be aligned to sizeof(void*). Doesn't include internal members like
41 * unknown fields, extension dict, pointer to msglayout, etc. */
42 uint16_t size;
43 uint16_t field_count;
44 bool extendable;
45} upb_msglayout;
46
47/** Message internal representation *******************************************/
48
49/* Our internal representation for repeated fields. */
50typedef struct {
51 void *data; /* Each element is element_size. */
52 size_t len; /* Measured in elements. */
53 size_t size; /* Measured in elements. */
54} upb_array;
55
56upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a);
57upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a);
58
59void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len,
60 upb_arena *arena);
61const char *upb_msg_getunknown(const upb_msg *msg, size_t *len);
62
63upb_array *upb_array_new(upb_arena *a);
64
65#ifdef __cplusplus
66} /* extern "C" */
67#endif
68
69#endif /* UPB_MSG_H_ */
70