1 /******************************************************************************
2
3 CRC-32 generator, uses LZO's built-in CRC-32 calculator
4
5 Copyright:
6 Copyright (c) 2009-2016 dunnhumby Germany GmbH.
7 All rights reserved.
8
9 License:
10 Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
11 Alternatively, this file may be distributed under the terms of the Tango
12 3-Clause BSD License (see LICENSE_BSD.txt for details).
13
14 ******************************************************************************/
15
16 module ocean.io.compress.lzo.LzoCrc;
17
18
19 import ocean.io.compress.lzo.c.lzoconf: lzo_crc32, lzo_crc32_init;
20
21 import ocean.meta.types.Qualifiers;
22 import ocean.core.TypeConvert;
23
24 /******************************************************************************
25
26 LzoCrc structure; contains only static methods
27
28 ******************************************************************************/
29
30 struct LzoCrc
31 {
32 static:
33
34 /**************************************************************************
35
36 Calculates a 32-bit CRC value from data.
37
38 Params:
39 crc32_in = initial 32-bit CRC value (for iteration)
40 data = data to calculate 32-bit CRC value of
41
42 Returns:
43 resulting 32-bit CRC value
44
45 **************************************************************************/
46
47 uint crc32 ( uint crc32_in, in void[] data )
48 {
49 return lzo_crc32(crc32_in, cast (const(ubyte)*) data.ptr,
50 castFrom!(size_t).to!(int)(data.length));
51 }
52
53 /**************************************************************************
54
55 Calculates a 32-bit CRC value from data.
56
57 Params:
58 data = data to calculate 32-bit CRC value of
59
60 Returns:
61 resulting 32-bit CRC value
62
63 **************************************************************************/
64
65 uint crc32 ( in void[] data )
66 {
67 return crc32(lzo_crc32_init(), data);
68 }
69 }