日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

redis源碼筆記-endian

系統(tǒng) 2824 0

對于目標(biāo)機是大端字節(jié)序的機器,進行字節(jié)碼的轉(zhuǎn)換,提供了16byte、32byte、64byte字節(jié)的轉(zhuǎn)換。在intset\ziplist\zipmap三種數(shù)據(jù)結(jié)構(gòu)中使用,使得不同字節(jié)序機器生成的rdb文件格式都是統(tǒng)一的(小端字節(jié)序),便于兼容。

代碼實在是太簡單了,貼上來,不多說了。

endian.h

      
         1
      
      
        #ifndef __ENDIAN_H

      
      
         2
      
      
        #define
      
       __ENDIAN_H

      
         3
      
      
         4
      
      
        void
      
       memrev16(
      
        void
      
       *
      
        p);

      
      
         5
      
      
        void
      
       memrev32(
      
        void
      
       *
      
        p);

      
      
         6
      
      
        void
      
       memrev64(
      
        void
      
       *
      
        p);

      
      
         7
      
      
         8
      
      
        /*
      
      
         variants of the function doing the actual convertion only if the target

      
      
         9
      
      
         * host is big endian 
      
      
        */
      
      
        10
      
      
        #if
      
       (BYTE_ORDER == LITTLE_ENDIAN)

      
        11
      
      
        #define
      
       memrev16ifbe(p)

      
        12
      
      
        #define
      
       memrev32ifbe(p)

      
        13
      
      
        #define
      
       memrev64ifbe(p)

      
        14
      
      
        #else
      
      
        15
      
      
        #define
      
       memrev16ifbe(p) memrev16(p)

      
        16
      
      
        #define
      
       memrev32ifbe(p) memrev32(p)

      
        17
      
      
        #define
      
       memrev64ifbe(p) memrev64(p)

      
        18
      
      
        #endif
      
      
        19
      
      
        20
      
      
        #endif
      
    

endian.c

      
         1
      
      
        /*
      
      
         Toggle the 16 bit unsigned integer pointed by *p from little endian to

      
      
         2
      
      
         * big endian 
      
      
        */
      
      
         3
      
      
        void
      
       memrev16(
      
        void
      
       *
      
        p) {

      
      
         4
      
           unsigned 
      
        char
      
       *x =
      
         p, t;

      
      
         5
      
      
         6
      
           t = x[
      
        0
      
      
        ];

      
      
         7
      
           x[
      
        0
      
      ] = x[
      
        1
      
      
        ];

      
      
         8
      
           x[
      
        1
      
      ] =
      
         t;

      
      
         9
      
      
        }

      
      
        10
      
      
        11
      
      
        /*
      
      
         Toggle the 32 bit unsigned integer pointed by *p from little endian to

      
      
        12
      
      
         * big endian 
      
      
        */
      
      
        13
      
      
        void
      
       memrev32(
      
        void
      
       *
      
        p) {

      
      
        14
      
           unsigned 
      
        char
      
       *x =
      
         p, t;

      
      
        15
      
      
        16
      
           t = x[
      
        0
      
      
        ];

      
      
        17
      
           x[
      
        0
      
      ] = x[
      
        3
      
      
        ];

      
      
        18
      
           x[
      
        3
      
      ] =
      
         t;

      
      
        19
      
           t = x[
      
        1
      
      
        ];

      
      
        20
      
           x[
      
        1
      
      ] = x[
      
        2
      
      
        ];

      
      
        21
      
           x[
      
        2
      
      ] =
      
         t;

      
      
        22
      
      
        }

      
      
        23
      
      
        24
      
      
        /*
      
      
         Toggle the 64 bit unsigned integer pointed by *p from little endian to

      
      
        25
      
      
         * big endian 
      
      
        */
      
      
        26
      
      
        void
      
       memrev64(
      
        void
      
       *
      
        p) {

      
      
        27
      
           unsigned 
      
        char
      
       *x =
      
         p, t;

      
      
        28
      
      
        29
      
           t = x[
      
        0
      
      
        ];

      
      
        30
      
           x[
      
        0
      
      ] = x[
      
        7
      
      
        ];

      
      
        31
      
           x[
      
        7
      
      ] =
      
         t;

      
      
        32
      
           t = x[
      
        1
      
      
        ];

      
      
        33
      
           x[
      
        1
      
      ] = x[
      
        6
      
      
        ];

      
      
        34
      
           x[
      
        6
      
      ] =
      
         t;

      
      
        35
      
           t = x[
      
        2
      
      
        ];

      
      
        36
      
           x[
      
        2
      
      ] = x[
      
        5
      
      
        ];

      
      
        37
      
           x[
      
        5
      
      ] =
      
         t;

      
      
        38
      
           t = x[
      
        3
      
      
        ];

      
      
        39
      
           x[
      
        3
      
      ] = x[
      
        4
      
      
        ];

      
      
        40
      
           x[
      
        4
      
      ] =
      
         t;

      
      
        41
      
      
        }

      
      
        42
      
      
        43
      
      
        #ifdef TESTMAIN

      
      
        44
      
       #include <stdio.h>

      
        45
      
      
        46
      
      
        int
      
       main(
      
        void
      
      
        ) {

      
      
        47
      
      
        char
      
       buf[
      
        32
      
      
        ];

      
      
        48
      
      
        49
      
           sprintf(buf,
      
        "
      
      
        ciaoroma
      
      
        "
      
      
        );

      
      
        50
      
      
            memrev16(buf);

      
      
        51
      
           printf(
      
        "
      
      
        %s\n
      
      
        "
      
      
        , buf);

      
      
        52
      
      
        53
      
           sprintf(buf,
      
        "
      
      
        ciaoroma
      
      
        "
      
      
        );

      
      
        54
      
      
            memrev32(buf);

      
      
        55
      
           printf(
      
        "
      
      
        %s\n
      
      
        "
      
      
        , buf);

      
      
        56
      
      
        57
      
           sprintf(buf,
      
        "
      
      
        ciaoroma
      
      
        "
      
      
        );

      
      
        58
      
      
            memrev64(buf);

      
      
        59
      
           printf(
      
        "
      
      
        %s\n
      
      
        "
      
      
        , buf);

      
      
        60
      
      
        61
      
      
        return
      
      
        0
      
      
        ;

      
      
        62
      
      
        }

      
      
        63
      
      
        #endif
      
    

redis源碼筆記-endian


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 和田县| 墨脱县| 石门县| 汉寿县| 长春市| 长子县| 陈巴尔虎旗| 侯马市| 桑日县| 天柱县| 加查县| 光山县| 依兰县| 保康县| 周宁县| 剑川县| 长武县| 郓城县| 武乡县| 佛冈县| 万荣县| 屏南县| 荆州市| 定边县| 延庆县| 泰州市| 新乡县| 库车县| 义乌市| 翁源县| 湖南省| 两当县| 南和县| 大英县| 佛山市| 郓城县| 和林格尔县| 奉节县| 容城县| 常宁市| 陵川县|