RZ

01: // ExtractWrapper.hh # rz offsets table for analysis and synthesis
02:
03: #ifndef _ExtractWrapper_HH
04: #define _ExtractWrapper_HH 1
05:
06: #include "RZError.hh"
07: #include "RZMagic.hh"
08: #include "RZNetOrder.hh"
09:
10: namespace RZ {
11:     struct FullWrapper: RZWrapper {
12:         template< typename ByteIter > void extractor_header(ByteIter buf);
13:         template< typename ByteIter > void extractor_signatures(ByteIter buf);
14:     };
15: }
16:         
17: template< typename ByteIter >
18: void RZ::FullWrapper::extractor_header(ByteIter const buffer)
19: {
20:     if (!std::equal(buffer, buffer + 16, file_magic))
21:         throw ContentError("The remote file is not an rz file\n");
22:         // The magic goes away
23:         
24:     modulus_a = net_in(buffer + 16);
25:     modulus_b = net_in(buffer + 20);
26:     modulus_c = net_in(buffer + 24);
27:     blocks_of = net_in(buffer + 28);
28:
29:     if (blocks_of & 7) throw ContentError(
30:         "The remote file blocks are not byte-aligned\n");
31:
32:     n_blks = net_in(buffer + 32); // num complete 8192K src blks
33:     rz_crc = net_in(buffer + 36); // crc of the compressed stream
34:     sc_end = net_in(buffer + 40); // end (size) source stream
35:     rz_end = net_in(buffer + 44); // end (size) compressed stream
36:
37:     n_cont = net_in(buffer + 48); // num blks before comp reinits
38:     rz_czr = net_in(buffer + 52); // init (zero) crc value
39:     sc_off = net_in(buffer + 56); // init offset src before blk 0
40:     rz_off = net_in(buffer + 60); // init offset comprs bef blk 0
41:
42:     if (sc_end < sc_off || rz_end < rz_off) throw ContentError(
43:         "The remote file has an impossibly long initial offset\n");
44:
45:     wrapper_size = 64 + 16 * n_blks;
46:     block_size = blocks_of >> 3;
47:     file_size = wrapper_size + rz_end;
48:
49:     if ((sc_end - sc_off)/block_size != n_blks) throw ContentError(
50:         "The remote file has the wrong number of blocks");
51:         // Quotient is wrong
52: }
53:         
54: template< typename ByteIter >
55: void RZ::FullWrapper::extractor_signatures(ByteIter const buffer)
56: {
57:     unsigned int rzj = rz_off;
58:     ByteIter b = buffer + 64;
59:     for (unsigned int i = 0; i < n_blks; ++i) {
60:         struct RZSignatureTable::SignatureEntry entry;
61:         entry.sig_a = net_in(b); b += 4;
62:         entry.sig_b = net_in(b); b += 4;
63:         entry.sig_c = net_in(b); b += 4;
64:         entry.rz_to = net_in(b); b += 4;
65:
66:         if (rzj > entry.rz_to)
67:             throw ContentError("Invalid signature table\n");
68:         rzj = entry.rz_to;
69:
70:         signature_table.push_back(entry);
71:     }
72: }
73:         
74: // ExtractWrapper.hh # rz offsets table for analysis and synthesis
75:
76: #endif