parent
62be5969a1
commit
aecbfe4224
7 changed files with 52 additions and 26 deletions
@ -0,0 +1,31 @@ |
|||||||
|
/*
|
||||||
|
* upb - a minimalist implementation of protocol buffers. |
||||||
|
* |
||||||
|
* Copyright (c) 2009 Joshua Haberman. See LICENSE for details. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "descriptor.h" |
||||||
|
#include "upb_enum.h" |
||||||
|
|
||||||
|
void upb_enum_init(struct upb_enum *e, |
||||||
|
struct google_protobuf_EnumDescriptorProto *ed) { |
||||||
|
int num_values = ed->set_flags.has.value ? ed->value->len : 0; |
||||||
|
e->descriptor = ed; |
||||||
|
upb_strtable_init(&e->nametoint, num_values, sizeof(struct upb_enum_ntoi_entry)); |
||||||
|
upb_inttable_init(&e->inttoname, num_values, sizeof(struct upb_enum_iton_entry)); |
||||||
|
|
||||||
|
for(int i = 0; i < num_values; i++) { |
||||||
|
google_protobuf_EnumValueDescriptorProto *value = ed->value->elements[i]; |
||||||
|
struct upb_enum_ntoi_entry ntoi_entry = {.e = {.key = *value->name}, |
||||||
|
.value = value->number}; |
||||||
|
struct upb_enum_iton_entry iton_entry = {.e = {.key = value->number}, |
||||||
|
.string = value->name}; |
||||||
|
upb_strtable_insert(&e->nametoint, &ntoi_entry.e); |
||||||
|
upb_inttable_insert(&e->inttoname, &iton_entry.e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void upb_enum_free(struct upb_enum *e) { |
||||||
|
upb_strtable_free(&e->nametoint); |
||||||
|
upb_inttable_free(&e->inttoname); |
||||||
|
} |
@ -1,10 +1,19 @@ |
|||||||
/*
|
/*
|
||||||
* upb - a minimalist implementation of protocol buffers. |
* upb - a minimalist implementation of protocol buffers. |
||||||
* |
* |
||||||
|
* This file, if compiled, will contain standalone (non-inlined) versions of |
||||||
|
* all inline functions defined in header files. We don't generally use this |
||||||
|
* file since we use "static inline" for inline functions (which will put a |
||||||
|
* standalone version of the function in any .o file that needs it, but |
||||||
|
* compiling this file and dumping the object file will let us inspect how |
||||||
|
* inline functions are compiled, so we keep it around. |
||||||
|
* |
||||||
* Copyright (c) 2009 Joshua Haberman. See LICENSE for details. |
* Copyright (c) 2009 Joshua Haberman. See LICENSE for details. |
||||||
*/ |
*/ |
||||||
|
|
||||||
#define INLINE |
#define INLINE |
||||||
#include "upb_parse.h" |
#include "upb_context.h" |
||||||
|
#include "upb_enum.h" |
||||||
#include "upb_msg.h" |
#include "upb_msg.h" |
||||||
|
#include "upb_parse.h" |
||||||
#include "upb_table.h" |
#include "upb_table.h" |
||||||
|
Loading…
Reference in new issue