00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _UT_BUFFER_VALUES_H_
00026 #define _UT_BUFFER_VALUES_H_
00027
00028
00029
00030
00031
00032 #include "UT.h"
00033
00034
00035
00036
00037
00038
00039 EXTERN_C_BEGIN
00040
00043 extern UT_EXPORT void pack_uint16_little_endian( uint16 value, byte* buffer );
00044
00045
00046 #if !(TARGET_CPU_BIG_ENDIAN || TARGET_CPU_LITTLE_ENDIAN)
00047 #error "UT target platform header must define TARGET_CPU_BIG_ENDIAN or TARGET_CPU_LITTLE_ENDIAN"
00048 #endif
00049
00050
00051 #if TARGET_CPU_LITTLE_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00052 #if __cplusplus
00053 #define pack_uint16_little_endian( val, buf ) *reinterpret_cast<uint16*>(buf) = (val)
00054 #else
00055 #define pack_uint16_little_endian( val, buf ) *(uint16*)(buf) = (val)
00056 #endif
00057 #endif
00058
00059
00062 extern UT_EXPORT void pack_uint16_big_endian( uint16 value, byte* buffer );
00063
00064
00065 #if TARGET_CPU_BIG_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00066 #if __cplusplus
00067 #define pack_uint16_big_endian( val, buf ) *reinterpret_cast<uint16*>(buf) = (val)
00068 #else
00069 #define pack_uint16_big_endian( val, buf ) *(uint16*)(buf) = (val)
00070 #endif
00071 #endif
00072
00073
00076 extern UT_EXPORT void pack_uint16_native_endian( uint16 value, byte* buffer );
00077
00078
00079 #if TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00080 #if __cplusplus
00081 #define pack_uint16_native_endian( val, buf ) *reinterpret_cast<uint16*>(buf) = (val)
00082 #else
00083 #define pack_uint16_native_endian( val, buf ) *(uint16*)(buf) = (val)
00084 #endif
00085 #endif
00086
00087
00090 extern UT_EXPORT void pack_uint32_little_endian( uint32 value, byte* buffer );
00091
00092
00093 #if TARGET_CPU_LITTLE_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00094 #if __cplusplus
00095 #define pack_uint32_little_endian( val, buf ) *reinterpret_cast<uint32*>(buf) = (val)
00096 #else
00097 #define pack_uint32_little_endian( val, buf ) *(uint32*)(buf) = (val)
00098 #endif
00099 #endif
00100
00101
00104 extern UT_EXPORT void pack_uint32_big_endian( uint32 value, byte* buffer );
00105
00106
00107 #if TARGET_CPU_BIG_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00108 #if __cplusplus
00109 #define pack_uint32_big_endian( val, buf ) *reinterpret_cast<uint32*>(buf) = (val)
00110 #else
00111 #define pack_uint32_big_endian( val, buf ) *(uint32*)(buf) = (val)
00112 #endif
00113 #endif
00114
00115
00118 extern UT_EXPORT void pack_uint32_native_endian( uint32 value, byte* buffer );
00119
00120
00121 #if TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00122 #if __cplusplus
00123 #define pack_uint32_native_endian( val, buf ) *reinterpret_cast<uint32*>(buf) = (val)
00124 #else
00125 #define pack_uint32_native_endian( val, buf ) *(uint32*)(buf) = (val)
00126 #endif
00127 #endif
00128
00129
00132 extern UT_EXPORT void pack_uint64_little_endian( uint64 value, byte* buffer );
00133
00134
00135 #if TARGET_CPU_LITTLE_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00136 #if __cplusplus
00137 #define pack_uint64_little_endian( val, buf ) *reinterpret_cast<uint64*>(buf) = (val)
00138 #else
00139 #define pack_uint64_little_endian( val, buf ) *(uint64*)(buf) = (val)
00140 #endif
00141 #endif
00142
00143
00146 extern UT_EXPORT void pack_uint64_big_endian( uint64 value, byte* buffer );
00147
00148
00149 #if TARGET_CPU_BIG_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00150 #if __cplusplus
00151 #define pack_uint64_big_endian( val, buf ) *reinterpret_cast<uint64*>(buf) = (val)
00152 #else
00153 #define pack_uint64_big_endian( val, buf ) *(uint64*)(buf) = (val)
00154 #endif
00155 #endif
00156
00157
00160 extern UT_EXPORT void pack_uint64_native_endian( uint64 value, byte* buffer );
00161
00162
00163 #if TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00164 #if __cplusplus
00165 #define pack_uint64_native_endian( val, buf ) *reinterpret_cast<uint64*>(buf) = (val)
00166 #else
00167 #define pack_uint64_native_endian( val, buf ) *(uint64*)(buf) = (val)
00168 #endif
00169 #endif
00170
00171
00174 extern UT_EXPORT uint16 extract_uint16_little_endian(const byte* buffer);
00175
00176
00177 #if TARGET_CPU_LITTLE_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00178 #if __cplusplus
00179 #define extract_uint16_little_endian(buf) ( *reinterpret_cast<const uint16*>(buf) )
00180 #else
00181 #define extract_uint16_little_endian(buf) ( *(uint16*)(buf) )
00182 #endif
00183 #endif
00184
00185
00188 extern UT_EXPORT uint16 extract_uint16_big_endian(const byte* buffer);
00189
00190
00191 #if TARGET_CPU_BIG_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00192 #if __cplusplus
00193 #define extract_uint16_big_endian(buf) ( *reinterpret_cast<const uint16*>(buf) )
00194 #else
00195 #define extract_uint16_big_endian(buf) ( *(uint16*)(buf) )
00196 #endif
00197 #endif
00198
00199
00202 extern UT_EXPORT uint16 extract_uint16_native_endian(const byte* buffer);
00203
00204
00205 #if TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00206 #if __cplusplus
00207 #define extract_uint16_native_endian(buf) ( *reinterpret_cast<const uint16*>(buf) )
00208 #else
00209 #define extract_uint16_native_endian(buf) ( *(uint16*)(buf) )
00210 #endif
00211 #endif
00212
00213
00216 extern UT_EXPORT uint32 extract_uint32_little_endian(const byte* buffer);
00217
00218
00219 #if TARGET_CPU_LITTLE_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00220 #if __cplusplus
00221 #define extract_uint32_little_endian(buf) ( *reinterpret_cast<const uint32*>(buf) )
00222 #else
00223 #define extract_uint32_little_endian(buf) ( *(uint32*)(buf) )
00224 #endif
00225 #endif
00226
00227
00230 extern UT_EXPORT uint32 extract_uint32_big_endian(const byte* buffer);
00231
00232
00233 #if TARGET_CPU_BIG_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00234 #if __cplusplus
00235 #define extract_uint32_big_endian(buf) ( *reinterpret_cast<const uint32*>(buf) )
00236 #else
00237 #define extract_uint32_big_endian(buf) ( *(uint32*)(buf) )
00238 #endif
00239 #endif
00240
00241
00244 extern UT_EXPORT uint32 extract_uint32_native_endian(const byte* buffer);
00245
00246
00247 #if TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00248 #if __cplusplus
00249 #define extract_uint32_native_endian(buf) ( *reinterpret_cast<const uint32*>(buf) )
00250 #else
00251 #define extract_uint32_native_endian(buf) ( *(uint32*)(buf) )
00252 #endif
00253 #endif
00254
00255
00258 extern UT_EXPORT uint64 extract_uint64_little_endian(const byte* buffer);
00259
00260
00261 #if TARGET_CPU_LITTLE_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00262 #if __cplusplus
00263 #define extract_uint64_little_endian(buf) ( *reinterpret_cast<const uint64*>(buf) )
00264 #else
00265 #define extract_uint64_little_endian(buf) ( *(uint64*)(buf) )
00266 #endif
00267 #endif
00268
00269
00272 extern UT_EXPORT uint64 extract_uint64_big_endian(const byte* buffer);
00273
00274
00275 #if TARGET_CPU_BIG_ENDIAN && TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00276 #if __cplusplus
00277 #define extract_uint64_big_endian(buf) ( *reinterpret_cast<const uint64*>(buf) )
00278 #else
00279 #define extract_uint64_big_endian(buf) ( *(uint64*)(buf) )
00280 #endif
00281 #endif
00282
00283
00286 extern UT_EXPORT uint64 extract_uint64_native_endian(const byte* buffer);
00287
00288
00289 #if TARGET_CPU_ALLOW_UNALIGNED_ACCESS
00290 #if __cplusplus
00291 #define extract_uint64_native_endian(buf) ( *reinterpret_cast<const uint64*>(buf) )
00292 #else
00293 #define extract_uint64_native_endian(buf) ( *(uint64*)(buf) )
00294 #endif
00295 #endif
00296
00297
00304 extern UT_EXPORT int get_hex_byte( const utf8* text, out byte* value );
00305
00306
00307 #if __cplusplus
00308 EXTERN_C_END
00309
00316 inline int
00317 get_hex_byte( stringliteral* text, out byte* value )
00318 {
00319 return get_hex_byte( reinterpret_cast<const utf8*>(text), value );
00320 }
00321
00322 EXTERN_C_BEGIN
00323 #endif
00324
00325
00328 extern UT_EXPORT void put_hex_byte( byte value, out utf8* buffer );
00329
00330
00336 extern UT_EXPORT bool get_hex_nibble( utf8 c, out byte* value );
00337
00338
00342 extern UT_EXPORT void put_hex_nibble( byte value, out utf8* buffer );
00343
00344
00353 extern UT_EXPORT int convert_string_to_uint8( const utf8* string, out uint8* value );
00354
00355
00356 #if __cplusplus
00357 EXTERN_C_END
00358
00367 inline int
00368 convert_string_to_uint8( const stringliteral* string, out uint8* value )
00369 {
00370 return convert_string_to_uint8( reinterpret_cast<const utf8*>(string), value );
00371 }
00372
00373 EXTERN_C_BEGIN
00374 #endif
00375
00376
00385 extern UT_EXPORT int convert_wstring_to_uint8( const wchar_t* string, out uint8* value );
00386
00387
00396 extern UT_EXPORT int convert_string_to_int8( const utf8* string, out int8* value );
00397
00398
00399 #if __cplusplus
00400 EXTERN_C_END
00401
00410 inline int
00411 convert_string_to_int8( const stringliteral* string, out int8* value )
00412 {
00413 return convert_string_to_int8( reinterpret_cast<const utf8*>(string), value );
00414 }
00415
00416 EXTERN_C_BEGIN
00417 #endif
00418
00419
00428 extern UT_EXPORT int convert_wstring_to_int8( const wchar_t* string, out int8* value );
00429
00430
00439 extern UT_EXPORT int convert_string_to_int16( const utf8* string, out int16* value );
00440
00441
00442 #if __cplusplus
00443 EXTERN_C_END
00444
00453 inline int
00454 convert_string_to_int16( const stringliteral* string, out int16* value )
00455 {
00456 return convert_string_to_int16( reinterpret_cast<const utf8*>(string), value );
00457 }
00458
00459 EXTERN_C_BEGIN
00460 #endif
00461
00462
00471 extern UT_EXPORT int convert_wstring_to_int16( const wchar_t* string, out int16* value );
00472
00473
00482 extern UT_EXPORT int convert_string_to_uint16( const utf8* string, out uint16* value );
00483
00484
00485 #if __cplusplus
00486 EXTERN_C_END
00487
00496 inline int
00497 convert_string_to_uint16( const stringliteral* string, out uint16* value )
00498 {
00499 return convert_string_to_uint16( reinterpret_cast<const utf8*>(string), value );
00500 }
00501
00502 EXTERN_C_BEGIN
00503 #endif
00504
00505
00514 extern UT_EXPORT int convert_wstring_to_uint16( const wchar_t* string, out uint16* value );
00515
00516
00525 extern UT_EXPORT int convert_string_to_uint32( const utf8* string, out uint32* value );
00526
00527
00528 #if __cplusplus
00529 EXTERN_C_END
00530
00539 inline int
00540 convert_string_to_uint32( const stringliteral* string, out uint32* value )
00541 {
00542 return convert_string_to_uint32( reinterpret_cast<const utf8*>(string), value );
00543 }
00544
00545 EXTERN_C_BEGIN
00546 #endif
00547
00548
00557 extern UT_EXPORT int convert_wstring_to_uint32( const wchar_t* string, out uint32* value );
00558
00559
00568 extern UT_EXPORT int convert_string_to_int32( const utf8* string, out int32* value );
00569
00570
00571 #if __cplusplus
00572 EXTERN_C_END
00573
00582 inline int
00583 convert_string_to_int32( const stringliteral* string, out int32* value )
00584 {
00585 return convert_string_to_int32( reinterpret_cast<const utf8*>(string), value );
00586 }
00587
00588 EXTERN_C_BEGIN
00589 #endif
00590
00591
00600 extern UT_EXPORT int convert_wstring_to_int32( const wchar_t* string, out int32* value );
00601
00602
00611 extern UT_EXPORT int convert_string_to_uint64( const utf8* string, out uint64* value );
00612
00613
00614 #if __cplusplus
00615 EXTERN_C_END
00616
00625 inline int
00626 convert_string_to_uint64( const stringliteral* string, out uint64* value )
00627 {
00628 return convert_string_to_uint64( reinterpret_cast<const utf8*>(string), value );
00629 }
00630
00631 EXTERN_C_BEGIN
00632 #endif
00633
00634
00643 extern UT_EXPORT int convert_wstring_to_uint64( const wchar_t* string, out uint64* value );
00644
00645
00654 extern UT_EXPORT int convert_string_to_int64( const utf8* string, out int64* value );
00655
00656
00657 #if __cplusplus
00658 EXTERN_C_END
00659
00668 inline int
00669 convert_string_to_int64( const stringliteral* string, out int64* value )
00670 {
00671 return convert_string_to_int64( reinterpret_cast<const utf8*>(string), value );
00672 }
00673
00674 EXTERN_C_BEGIN
00675 #endif
00676
00677
00686 extern UT_EXPORT int convert_wstring_to_int64( const wchar_t* string, out int64* value );
00687
00688
00689 EXTERN_C_END
00690
00691 #endif // _UT_BUFFER_VALUES_H_