提交 090c6f81 编写于 作者: Y yuqing

add function short2buff and buff2short

上级 0dd3d17c
Version 1.06 2014-05-28
Version 1.06 2014-05-30
* update source code from FastDFS V5.02
* add function short2buff and buff2short
Version 1.05 2012-07-08
* update source code from FastDFS V3.09
......
......@@ -1140,6 +1140,20 @@ int safeWriteToFile(const char *filename, const char *buff, \
return 0;
}
void short2buff(const short n, char *buff)
{
unsigned char *p;
p = (unsigned char *)buff;
*p++ = (n >> 8) & 0xFF;
*p++ = n & 0xFF;
}
short buff2short(const char *buff)
{
return (short)((((unsigned char)(*(buff))) << 8) | \
((unsigned char)(*(buff+1))));
}
void int2buff(const int n, char *buff)
{
unsigned char *p;
......
......@@ -147,6 +147,21 @@ char *hex2bin(const char *s, char *szBinBuff, int *nDestLen);
*/
void printBuffHex(const char *s, const int len);
/** 16 bits int convert to buffer (big-endian)
* parameters:
* n: 16 bits int value
* buff: the buffer, at least 2 bytes space, no tail \0
* return: none
*/
void short2buff(const short n, char *buff);
/** buffer convert to 16 bits int
* parameters:
* buff: big-endian 2 bytes buffer
* return: 16 bits int value
*/
short buff2short(const char *buff);
/** 32 bits int convert to buffer (big-endian)
* parameters:
* n: 32 bits int value
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册