QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_crc.h
Go to the documentation of this file.
1/* $NoKeywords: $ */
2/*
3//
4// Copyright (c) 1993-2007 Robert McNeel & Associates. All rights reserved.
5// Rhinoceros is a registered trademark of Robert McNeel & Assoicates.
6//
7// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
8// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
9// MERCHANTABILITY ARE HEREBY DISCLAIMED.
10//
11// For complete openNURBS copyright information see <http://www.opennurbs.org>.
12//
14*/
15
16#if !defined(OPENNURBS_CRC_INC_)
17#define OPENNURBS_CRC_INC_
18
20
21/*
22Description:
23 Continues 16 bit CRC calulation to include the buffer.
24
25Parameters:
26 current_remainder - [in]
27 sizeof_buffer - [in] number of bytes in buffer
28 buffer - [in]
29
30Example:
31 16 bit CRC calculations are typically done something like this:
32
33 const ON__UINT16 crc_seed = 0; // or 1, or your favorite starting value
34
35 // Compute CRC on "good" data
36 unsigned ON__UINT16 first_crc = crc_seed;
37 first_crc = ON_CRC16( first_crc, size1, buffer1 );
38 ...
39 first_crc = ON_CRC16( first_crc, sizeN, bufferN );
40 unsigned char two_zero_bytes[2] = (0,0);
41 first_crc = ON_CRC16( first_crc, 2, two_zero_bytes );
42
43 // make sure 16 bit CRC calculation is valid
44 ON__UINT16 check_crc_calculation = ON_CRC16( first_crc, 2, &first_crc );
45 if ( check_crc_calculation != 0 )
46 {
47 printf("ON_CRC16() calculated a bogus 16 bit CRC\n");
48 }
49
50 // Do something that may potentially change the values in
51 // the buffers (like storing them on a faulty disk).
52
53 // Compute CRC on "suspect" data
54 ON__UINT16 second_crc = crc_seed;
55 second_crc = ON_CRC16( second_crc, size1, buffer1 );
56 ...
57 second_crc = ON_CRC16( second_crc, sizeN, bufferN );
58 if ( 0 != ON_CRC16( second_crc, 2, &first_crc ) )
59 {
60 printf( "The value of at least one byte has changed.\n" );
61 }
62*/
65 ON__UINT16 current_remainder,
66 size_t sizeof_buffer,
67 const void* buffer
68 );
69
70/*
71Description:
72 Continues 32 bit CRC calulation to include the buffer
73
74 ON_CRC32() is a slightly altered version of zlib 1.3.3's crc32()
75 and the zlib "legal stuff" is reproduced below.
76
77 ON_CRC32() and zlib's crc32() compute the same values. ON_CRC32()
78 was renamed so it wouldn't clash with the other crc32()'s that are
79 out there and the argument order was switched to match that used by
80 the legacy ON_CRC16().
81
82Parameters:
83 current_remainder - [in]
84 sizeof_buffer - [in] number of bytes in buffer
85 buffer - [in]
86
87Example:
88 32 bit CRC calculations are typically done something like this:
89
90 const ON__UINT32 crc_seed = 0; // or 1, or your favorite starting value
91
92 //Compute CRC on "good" data
93 ON__UINT32 first_crc = crc_seed;
94 first_crc = ON_CRC32( first_crc, size1, buffer1 );
95 ...
96 first_crc = ON_CRC32( first_crc, sizeN, bufferN );
97
98 // Do something that may potentially change the values in
99 // the buffers (like storing them on a faulty disk).
100
101 // Compute CRC on "suspect" data
102 ON__UINT32 second_crc = crc_seed;
103 second_crc = ON_CRC32( second_crc, size1, buffer1 );
104 ...
105 second_crc = ON_CRC32( second_crc, sizeN, bufferN );
106 if ( second_crc != first_crc )
107 {
108 printf( "The value of at least one byte has changed.\n" );
109 }
110*/
113 ON__UINT32 current_remainder,
114 size_t sizeof_buffer,
115 const void* buffer
116 );
117
118/*
119zlib.h -- interface of the 'zlib' general purpose compression library
120version 1.1.3, July 9th, 1998
121
122Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
123
124This software is provided 'as-is', without any express or implied
125warranty. In no event will the authors be held liable for any damages
126arising from the use of this software.
127
128Permission is granted to anyone to use this software for any purpose,
129including commercial applications, and to alter it and redistribute it
130freely, subject to the following restrictions:
131
1321. The origin of this software must not be misrepresented; you must not
133 claim that you wrote the original software. If you use this software
134 in a product, an acknowledgment in the product documentation would be
135 appreciated but is not required.
1362. Altered source versions must be plainly marked as such, and must not be
137 misrepresented as being the original software.
1383. This notice may not be removed or altered from any source distribution.
139
140Jean-loup Gailly Mark Adler
142
143The data format used by the zlib library is described by RFCs (Request for
144Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
145(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
146
147*/
148
150
151#endif
ON_BEGIN_EXTERNC ON_DECL ON__UINT16 ON_CRC16(ON__UINT16 current_remainder, size_t sizeof_buffer, const void *buffer)
Definition opennurbs_crc.cpp:18
ON_DECL ON__UINT32 ON_CRC32(ON__UINT32 current_remainder, size_t sizeof_buffer, const void *buffer)
Definition opennurbs_crc.cpp:109
#define ON_BEGIN_EXTERNC
Definition opennurbs_defines.h:40
#define ON_DECL
Definition opennurbs_defines.h:92
#define ON_END_EXTERNC
Definition opennurbs_defines.h:41
unsigned short ON__UINT16
Definition opennurbs_system.h:320
unsigned int ON__UINT32
Definition opennurbs_system.h:326