blob: e43a2037fc15c28948af58f5ec34975f2b78bf4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/*
* upb - a minimalist implementation of protocol buffers.
*
* Copyright (c) 2009 Joshua Haberman. See LICENSE for details.
*
* upb_enum is a simple object that allows run-time reflection over the values
* defined within an enum. */
#ifndef UPB_ENUM_H_
#define UPB_ENUM_H_
#include <stdint.h>
#include "upb_atomic.h"
#include "upb_context.h"
#include "upb_table.h"
#include "descriptor.h"
struct upb_enum {
upb_atomic_refcount_t refcount;
struct upb_context *context;
struct google_protobuf_EnumDescriptorProto *descriptor;
struct upb_strtable nametoint;
struct upb_inttable inttoname;
};
struct upb_enum_ntoi_entry {
struct upb_strtable_entry e;
uint32_t value;
};
struct upb_enum_iton_entry {
struct upb_inttable_entry e;
struct upb_string *string;
};
INLINE void upb_enum_ref(struct upb_enum *e) {
if(upb_atomic_ref(&e->refcount)) upb_context_ref(e->context);
}
INLINE void upb_enum_unref(struct upb_enum *e) {
if(upb_atomic_unref(&e->refcount)) upb_context_unref(e->context);
}
/* Initializes and frees an enum, respectively. Caller retains ownership of
* ed, but it must outlive e. */
void upb_enum_init(struct upb_enum *e,
struct google_protobuf_EnumDescriptorProto *ed,
struct upb_context *c);
void upb_enum_free(struct upb_enum *e);
#endif /* UPB_ENUM_H_ */
|