diff options
author | Joshua Haberman <joshua@reverberate.org> | 2009-08-01 23:13:20 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2009-08-01 23:13:20 -0700 |
commit | 62dbeee8f69902b87ef11d13cef54ae261d74e6f (patch) | |
tree | bfcb16adcbe9d85a542c65b03eaa15831b4fe803 | |
parent | e8c58eb78dbd7fc161a82da321dad028a0acbb3d (diff) |
Add upb_serialize.c.
-rw-r--r-- | src/upb_serialize.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/upb_serialize.c b/src/upb_serialize.c new file mode 100644 index 0000000..a1d4718 --- /dev/null +++ b/src/upb_serialize.c @@ -0,0 +1,34 @@ +/* + * upb - a minimalist implementation of protocol buffers. + * + * Copyright (c) 2009 Joshua Haberman. See LICENSE for details. + */ + +#include "upb_serialize.h" +#include "descriptor.h" + +upb_status_t upb_serialize_value(uint8_t *buf, uint8_t *end, upb_field_type_t ft, + union upb_value_ptr v, uint8_t **outbuf) +{ +#define CASE(t, member_name) \ + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_ ## t: \ + return upb_put_ ## t(buf, end, *v.member_name, outbuf); + switch(ft) { + CASE(DOUBLE, _double) + CASE(FLOAT, _float) + CASE(INT32, int32) + CASE(INT64, int64) + CASE(UINT32, uint32) + CASE(UINT64, uint64) + CASE(SINT32, int32) + CASE(SINT64, int64) + CASE(FIXED32, uint32) + CASE(FIXED64, uint64) + CASE(SFIXED32, int32) + CASE(SFIXED64, int64) + CASE(BOOL, _bool) + CASE(ENUM, int32) + default: return UPB_ERROR_ILLEGAL; + } +#undef CASE +} |