index_util.h 1.7 KB
Newer Older
dengyihao's avatar
dengyihao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef __INDEX_UTIL_H__
#define __INDEX_UTIL_H__

#ifdef __cplusplus
extern "C" {
#endif

dengyihao's avatar
dengyihao 已提交
22 23 24 25
#define SERIALIZE_MEM_TO_BUF(buf, key, mem)                   \
  do {                                                        \
    memcpy((void*)buf, (void*)(&key->mem), sizeof(key->mem)); \
    buf += sizeof(key->mem);                                  \
dengyihao's avatar
dengyihao 已提交
26 27 28
  } while (0)

#define SERIALIZE_STR_MEM_TO_BUF(buf, key, mem, len) \
29
  do {                                               \
dengyihao's avatar
dengyihao 已提交
30
    memcpy((void*)buf, (void*)key->mem, len);        \
31
    buf += len;                                      \
dengyihao's avatar
dengyihao 已提交
32 33
  } while (0)

dengyihao's avatar
dengyihao 已提交
34 35 36
#define SERIALIZE_VAR_TO_BUF(buf, var, type)  \
  do {                                        \
    type c = var;                             \
dengyihao's avatar
dengyihao 已提交
37
    assert(sizeof(type) == sizeof(c));        \
dengyihao's avatar
dengyihao 已提交
38 39
    memcpy((void*)buf, (void*)&c, sizeof(c)); \
    buf += sizeof(c);                         \
dengyihao's avatar
dengyihao 已提交
40 41 42
  } while (0)

#define SERIALIZE_STR_VAR_TO_BUF(buf, var, len) \
43
  do {                                          \
dengyihao's avatar
dengyihao 已提交
44
    memcpy((void*)buf, (void*)var, len);        \
45
    buf += len;                                 \
dengyihao's avatar
dengyihao 已提交
46 47 48 49 50 51 52
  } while (0)

#ifdef __cplusplus
}
#endif

#endif