xrootd
Utils.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #ifndef UTILS_HH
20 #define UTILS_HH
21 
22 #include <unistd.h>
23 #include <stdint.h>
24 #include <zlib.h>
25 #include <string>
26 
27 namespace XrdClTests {
28 
29 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 class Utils
33 {
34  public:
35  //--------------------------------------------------------------------------
41  //--------------------------------------------------------------------------
42  static bool CRC32TextToInt( uint32_t &result, const std::string &text );
43 
44  //--------------------------------------------------------------------------
50  //--------------------------------------------------------------------------
51  static ssize_t GetRandomBytes( char *buffer, size_t size );
52 
53  //--------------------------------------------------------------------------
55  //--------------------------------------------------------------------------
56  static uint32_t GetInitialCRC32()
57  {
58  return crc32( 0L, Z_NULL, 0 );
59  }
60 
61  //--------------------------------------------------------------------------
66  //--------------------------------------------------------------------------
67  static uint32_t ComputeCRC32( const void *buffer, uint64_t len )
68  {
69  return crc32( GetInitialCRC32(), (const Bytef*)buffer, len );
70  }
71 
72  //--------------------------------------------------------------------------
78  //--------------------------------------------------------------------------
79  static uint32_t UpdateCRC32( uint32_t crc, const void *buffer, uint64_t len )
80  {
81  return crc32( crc, (const Bytef*)buffer, len );
82  }
83 
84  //--------------------------------------------------------------------------
90  //--------------------------------------------------------------------------
91  static uint32_t CombineCRC32( uint32_t crc1, uint32_t crc2, uint64_t len2 )
92  {
93  return crc32_combine( crc1, crc2, len2 );
94  }
95 };
96 };
97 
98 #endif // UTILS_HH