xrootd
Utils.hh
Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
00003 // Author: Lukasz Janyst <ljanyst@cern.ch>
00004 //------------------------------------------------------------------------------
00005 // XRootD is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // XRootD is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
00017 //------------------------------------------------------------------------------
00018 
00019 #ifndef UTILS_HH
00020 #define UTILS_HH
00021 
00022 #include <unistd.h>
00023 #include <stdint.h>
00024 #include <zlib.h>
00025 #include <string>
00026 
00027 namespace XrdClTests {
00028 
00029 //------------------------------------------------------------------------------
00031 //------------------------------------------------------------------------------
00032 class Utils
00033 {
00034   public:
00035     //--------------------------------------------------------------------------
00041     //--------------------------------------------------------------------------
00042     static bool CRC32TextToInt( uint32_t &result, const std::string &text  );
00043 
00044     //--------------------------------------------------------------------------
00050     //--------------------------------------------------------------------------
00051     static ssize_t GetRandomBytes( char *buffer, size_t size );
00052 
00053     //--------------------------------------------------------------------------
00055     //--------------------------------------------------------------------------
00056     static uint32_t GetInitialCRC32()
00057     {
00058       return crc32( 0L, Z_NULL, 0 );
00059     }
00060 
00061     //--------------------------------------------------------------------------
00066     //--------------------------------------------------------------------------
00067     static uint32_t ComputeCRC32( const void *buffer, uint64_t len )
00068     {
00069       return crc32( GetInitialCRC32(), (const Bytef*)buffer, len );
00070     }
00071 
00072     //--------------------------------------------------------------------------
00078     //--------------------------------------------------------------------------
00079     static uint32_t UpdateCRC32( uint32_t crc, const void *buffer, uint64_t len )
00080     {
00081       return crc32( crc, (const Bytef*)buffer, len );
00082     }
00083 
00084     //--------------------------------------------------------------------------
00090     //--------------------------------------------------------------------------
00091     static uint32_t CombineCRC32( uint32_t crc1, uint32_t crc2, uint64_t len2 )
00092     {
00093       return crc32_combine( crc1, crc2, len2 );
00094     }
00095 };
00096 };
00097 
00098 #endif // UTILS_HH