Changeset 128 in libcf for trunk/src/cf_codec.c
- Timestamp:
- 06/22/13 12:03:53 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cf_codec.c
r119 r128 1 1 /** 2 * \file cf_codec.c 3 * \author myusgun <myusgun@gmail.com> 2 * \file cf_codec.c 3 * 4 * \author myusgun <myusgun@gmail.com> 4 5 * 5 6 * \brief 데이터 변환 구현 6 7 */ 7 8 #include "cf_codec.h" 9 #include "cf_type.h" 8 10 #include "cf_error.h" 9 11 … … 15 17 return CF_ERROR_CODEC_INVALID_ARGS 16 18 17 const static unsigned charg_ascii_HexDecode[] = {19 const static cf_byte g_ascii_HexDecode[] = { 18 20 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00 - 15 */ 19 21 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 16 - 31 */ … … 48 50 }; 49 51 50 const static unsigned charg_ascii_Base64Decode[] = {52 const static cf_byte g_ascii_Base64Decode[] = { 51 53 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 00 - 15 */ 52 54 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 16 - 31 */ … … 82 84 */ 83 85 int 84 CF_Codec_Hex_Encode (const unsigned char* bin,85 const size_t 86 char 86 CF_Codec_Hex_Encode (const cf_byte * bin, 87 const size_t len, 88 char * hex) 87 89 { 88 90 size_t iter = 0; 89 91 size_t hexlen = len * 2 + 1; 90 92 91 const unsigned char* ptr = bin;93 const cf_byte * ptr = bin; 92 94 93 95 const static char hexchar[] = {'0', '1', '2', '3', … … 122 124 */ 123 125 int 124 CF_Codec_Hex_Decode (const char 125 unsigned char* bin,126 size_t 126 CF_Codec_Hex_Decode (const char * hex, 127 cf_byte * bin, 128 size_t * len) 127 129 { 128 size_t length = 0; /* absolutely even-number */129 size_t iter = 0;130 size_t binlen = 0;131 132 const char 133 char 134 unsigned charval = 0;135 unsigned charasciiHex = 0;130 size_t length = 0; /* absolutely even-number */ 131 size_t iter = 0; 132 size_t binlen = 0; 133 134 const char * ptr = hex; 135 char buf = 0; 136 cf_byte val = 0; 137 cf_byte asciiHex = 0; 136 138 137 139 ASSERT_ARGS (hex == NULL); … … 156 158 do { \ 157 159 buf = *(x); \ 158 val = ( unsigned char)(val << 4); \160 val = (cf_byte)(val << 4); \ 159 161 asciiHex = g_ascii_HexDecode[(int)buf]; \ 160 162 \ 161 val |= ( unsigned char) \163 val |= (cf_byte) \ 162 164 (buf - asciiHex + (asciiHex == '0' ? 0 : 10)); \ 163 165 } while (0) … … 188 190 */ 189 191 int 190 CF_Codec_Base64_Encode (const unsigned char* bin,192 CF_Codec_Base64_Encode (const cf_byte * bin, 191 193 const size_t len, 192 194 char * base64) 193 195 { 194 const unsigned char* src = bin;195 char 196 const cf_byte * src = bin; 197 char * dst = base64; 196 198 197 199 ASSERT_ARGS (src == NULL); … … 252 254 int 253 255 CF_Codec_Base64_Decode (const char * base64, 254 unsigned char* bin,256 cf_byte * bin, 255 257 size_t * len) 256 258 { 257 const char 258 unsigned char* dst = bin;259 int 260 int 259 const char * src = base64; 260 cf_byte * dst = bin; 261 int remain = 0; 262 int binlen = 0; 261 263 262 264 ASSERT_ARGS (src == NULL); … … 283 285 for (src = base64 ; remain > 4 ; remain -= 4, src += 4) 284 286 { 285 *dst++ = ( unsigned char)(SEXTUPLE_D_1 (src) | SEXTUPLE_D_2 (src));286 *dst++ = ( unsigned char)(SEXTUPLE_D_3 (src) | SEXTUPLE_D_4 (src));287 *dst++ = ( unsigned char)(SEXTUPLE_D_5 (src) | SEXTUPLE_D_6 (src));287 *dst++ = (cf_byte)(SEXTUPLE_D_1 (src) | SEXTUPLE_D_2 (src)); 288 *dst++ = (cf_byte)(SEXTUPLE_D_3 (src) | SEXTUPLE_D_4 (src)); 289 *dst++ = (cf_byte)(SEXTUPLE_D_5 (src) | SEXTUPLE_D_6 (src)); 288 290 } 289 291 290 292 if (remain > 1) 291 *dst++ = ( unsigned char)(SEXTUPLE_D_1 (src) | SEXTUPLE_D_2 (src));293 *dst++ = (cf_byte)(SEXTUPLE_D_1 (src) | SEXTUPLE_D_2 (src)); 292 294 if (remain > 2) 293 *dst++ = ( unsigned char)(SEXTUPLE_D_3 (src) | SEXTUPLE_D_4 (src));295 *dst++ = (cf_byte)(SEXTUPLE_D_3 (src) | SEXTUPLE_D_4 (src)); 294 296 if (remain > 3) 295 *dst++ = ( unsigned char)(SEXTUPLE_D_5 (src) | SEXTUPLE_D_6 (src));297 *dst++ = (cf_byte)(SEXTUPLE_D_5 (src) | SEXTUPLE_D_6 (src)); 296 298 297 299 return binlen - (4 - remain);
Note:
See TracChangeset
for help on using the changeset viewer.