Beispiel #1
0
static void lupb_pushmsgval(lua_State *L, upb_fieldtype_t type,
                            upb_msgval val) {
  switch (type) {
    case UPB_TYPE_INT32:
    case UPB_TYPE_ENUM:
      lupb_pushint32(L, upb_msgval_getint32(val));
      return;
    case UPB_TYPE_INT64:
      lupb_pushint64(L, upb_msgval_getint64(val));
      return;
    case UPB_TYPE_UINT32:
      lupb_pushuint32(L, upb_msgval_getuint32(val));
      return;
    case UPB_TYPE_UINT64:
      lupb_pushuint64(L, upb_msgval_getuint64(val));
      return;
    case UPB_TYPE_DOUBLE:
      lupb_pushdouble(L, upb_msgval_getdouble(val));
      return;
    case UPB_TYPE_FLOAT:
      lupb_pushfloat(L, upb_msgval_getfloat(val));
      return;
    case UPB_TYPE_BOOL:
      lua_pushboolean(L, upb_msgval_getbool(val));
      return;
    case UPB_TYPE_STRING:
    case UPB_TYPE_BYTES:
    case UPB_TYPE_MESSAGE:
      break;  /* Shouldn't call this function. */
  }
  UPB_UNREACHABLE();
}
Beispiel #2
0
static upb_msgval lupb_tomsgval(lua_State *L, upb_fieldtype_t type, int narg,
                                const lupb_msgclass *lmsgclass) {
  switch (type) {
    case UPB_TYPE_INT32:
    case UPB_TYPE_ENUM:
      return upb_msgval_int32(lupb_checkint32(L, narg));
    case UPB_TYPE_INT64:
      return upb_msgval_int64(lupb_checkint64(L, narg));
    case UPB_TYPE_UINT32:
      return upb_msgval_uint32(lupb_checkuint32(L, narg));
    case UPB_TYPE_UINT64:
      return upb_msgval_uint64(lupb_checkuint64(L, narg));
    case UPB_TYPE_DOUBLE:
      return upb_msgval_double(lupb_checkdouble(L, narg));
    case UPB_TYPE_FLOAT:
      return upb_msgval_float(lupb_checkfloat(L, narg));
    case UPB_TYPE_BOOL:
      return upb_msgval_bool(lupb_checkbool(L, narg));
    case UPB_TYPE_STRING:
    case UPB_TYPE_BYTES: {
      size_t len;
      const char *ptr = lupb_checkstring(L, narg, &len);
      return upb_msgval_str(ptr, len);
    }
    case UPB_TYPE_MESSAGE:
      UPB_ASSERT(lmsgclass);
      return upb_msgval_msg(lupb_msg_checkmsg(L, narg, lmsgclass));
  }
  UPB_UNREACHABLE();
}
Beispiel #3
0
static void upb_map_tokey(upb_fieldtype_t type, upb_msgval *key,
                          const char **out_key, size_t *out_len) {
  switch (type) {
    case UPB_TYPE_STRING:
      /* Point to string data of the input key. */
      *out_key = key->str.data;
      *out_len = key->str.size;
      return;
    case UPB_TYPE_BOOL:
    case UPB_TYPE_INT32:
    case UPB_TYPE_UINT32:
    case UPB_TYPE_INT64:
    case UPB_TYPE_UINT64:
      /* Point to the key itself.  XXX: big-endian. */
      *out_key = (const char*)key;
      *out_len = upb_msgval_sizeof(type);
      return;
    case UPB_TYPE_BYTES:
    case UPB_TYPE_DOUBLE:
    case UPB_TYPE_ENUM:
    case UPB_TYPE_FLOAT:
    case UPB_TYPE_MESSAGE:
      break;  /* Cannot be a map key. */
  }
  UPB_UNREACHABLE();
}
Beispiel #4
0
static upb_msgval upb_map_fromkey(upb_fieldtype_t type, const char *key,
                                  size_t len) {
  switch (type) {
    case UPB_TYPE_STRING:
      return upb_msgval_makestr(key, len);
    case UPB_TYPE_BOOL:
    case UPB_TYPE_INT32:
    case UPB_TYPE_UINT32:
    case UPB_TYPE_INT64:
    case UPB_TYPE_UINT64:
      return upb_msgval_read(key, 0, upb_msgval_sizeof(type));
    case UPB_TYPE_BYTES:
    case UPB_TYPE_DOUBLE:
    case UPB_TYPE_ENUM:
    case UPB_TYPE_FLOAT:
    case UPB_TYPE_MESSAGE:
      break;  /* Cannot be a map key. */
  }
  UPB_UNREACHABLE();
}
Beispiel #5
0
static size_t upb_msgval_sizeof(upb_fieldtype_t type) {
  switch (type) {
    case UPB_TYPE_DOUBLE:
    case UPB_TYPE_INT64:
    case UPB_TYPE_UINT64:
      return 8;
    case UPB_TYPE_ENUM:
    case UPB_TYPE_INT32:
    case UPB_TYPE_UINT32:
    case UPB_TYPE_FLOAT:
      return 4;
    case UPB_TYPE_BOOL:
      return 1;
    case UPB_TYPE_MESSAGE:
      return sizeof(void*);
    case UPB_TYPE_BYTES:
    case UPB_TYPE_STRING:
      return sizeof(upb_strview);
  }
  UPB_UNREACHABLE();
}