summaryrefslogtreecommitdiff
path: root/src/upb.c
blob: 2412be3065ef49d86ed5d0530dd857cfa028c0dd (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
/*
 * upb - a minimalist implementation of protocol buffers.
 *
 * Copyright (c) 2009 Joshua Haberman.  See LICENSE for details.
 *
 */

#include <stdarg.h>
#include <stddef.h>

#include "upb.h"

#define alignof(t) offsetof(struct { char c; t x; }, x)
#define TYPE_INFO(proto_type, wire_type, ctype) \
    [GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_ ## proto_type] = \
    {alignof(ctype), sizeof(ctype), wire_type, #ctype},

struct upb_type_info upb_type_info[] = {
  TYPE_INFO(DOUBLE,   UPB_WIRE_TYPE_64BIT,       double)
  TYPE_INFO(FLOAT,    UPB_WIRE_TYPE_32BIT,       float)
  TYPE_INFO(INT64,    UPB_WIRE_TYPE_VARINT,      int64_t)
  TYPE_INFO(UINT64,   UPB_WIRE_TYPE_VARINT,      uint64_t)
  TYPE_INFO(INT32,    UPB_WIRE_TYPE_VARINT,      int32_t)
  TYPE_INFO(FIXED64,  UPB_WIRE_TYPE_64BIT,       uint64_t)
  TYPE_INFO(FIXED32,  UPB_WIRE_TYPE_32BIT,       uint32_t)
  TYPE_INFO(BOOL,     UPB_WIRE_TYPE_VARINT,      bool)
  TYPE_INFO(MESSAGE,  UPB_WIRE_TYPE_DELIMITED,   void*)
  TYPE_INFO(GROUP,    UPB_WIRE_TYPE_START_GROUP, void*)
  TYPE_INFO(UINT32,   UPB_WIRE_TYPE_VARINT,      uint32_t)
  TYPE_INFO(ENUM,     UPB_WIRE_TYPE_VARINT,      uint32_t)
  TYPE_INFO(SFIXED32, UPB_WIRE_TYPE_32BIT,       int32_t)
  TYPE_INFO(SFIXED64, UPB_WIRE_TYPE_64BIT,       int64_t)
  TYPE_INFO(SINT32,   UPB_WIRE_TYPE_VARINT,      int32_t)
  TYPE_INFO(SINT64,   UPB_WIRE_TYPE_VARINT,      int64_t)
  TYPE_INFO(STRING,   UPB_WIRE_TYPE_DELIMITED,   union upb_string*)
  TYPE_INFO(BYTES,    UPB_WIRE_TYPE_DELIMITED,   union upb_string*)
};

void upb_seterr(struct upb_status *status, enum upb_status_code code,
                const char *msg, ...)
{
  if(upb_ok(status)) {  // The first error is the most interesting.
    status->code = code;
    va_list args;
    va_start(args, msg);
    vsnprintf(status->msg, UPB_ERRORMSG_MAXLEN, msg, args);
    va_end(args);
  }
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback