0%

ARST打卡第91周[91/521]

Algorithm

LeetCode/839_相似字符串组

Review

SERIALIZATION (ENCODE/DECODE)

Tips

Python结合OpenCV视频处理、逐帧修改图片

Share

Ceph的encoding宏定义妙用

  1. 宏定义do_while(false)套娃

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    #define ENCODE_START(A) \
    int a = A; \
    printf("hello a=%d\n", a); \
    do {

    // 这中间还套娃了很多层do,while,这是我没有想到了

    #define DECODE_FINISH() \
    } while(false);

    int main() {
    cout << "hello world" << endl;
    ENCODE_START(100)
    DECODE_FINISH()
    return 0;
    }
  2. 震惊宏定义缩短定义的方法

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    // -----------------------------------
    // int types

    #define WRITE_INTTYPE_ENCODER(type, etype) \
    inline void encode(type v, bufferlist& bl, uint64_t features=0) { \
    ceph_##etype e; \
    e = v; \
    encode_raw(e, bl); \
    } \
    inline void decode(type &v, bufferlist::iterator& p) { \
    ceph_##etype e; \
    decode_raw(e, p); \
    v = e; \
    }

    WRITE_INTTYPE_ENCODER(uint64_t, le64)
    WRITE_INTTYPE_ENCODER(int64_t, le64)
    WRITE_INTTYPE_ENCODER(uint32_t, le32)
    WRITE_INTTYPE_ENCODER(int32_t, le32)
    WRITE_INTTYPE_ENCODER(uint16_t, le16)
    WRITE_INTTYPE_ENCODER(int16_t, le16)