RZ

01: // ExtractRemoteCon.hh # rz offsets table for analysis and synthesis
02:
03: #ifndef _ExtractRemoteCon_HH
04: #define _ExtractRemoteCon_HH 1
05:
06: #include <vector>
07:
08: #include "RZMagic.hh"
09: #include "RZNetOrder.hh"
10: #include "ExtractIntermediate.hh"
11:
12: /****** rz offsets extracted from wrapper ******/
13:
14: namespace RZ {
15:     struct RemoteWrapper {
16:         unsigned int n_blks, rz_end, rz_off, wrapper_size, file_size;
17:
18:         template< typename ByteIter > void extractor_header(ByteIter buf);
19:
20:         RemoteWrapper() {};
21:         RemoteWrapper(RZStreamStructure const &);
22:         void extract_header(RZStreamStructure const &);
23:         void operator=(RZStreamStructure const &ss) { extract_header(ss); }
24:     };
25:
26:     struct ConTable: RemoteWrapper {
27:         std::vector< unsigned int >::iterator rz_at, rz_to;
28:         unsigned int rz_size(int const bk)
29:         const {
30:             return rz_to[bk] - rz_at[bk];
31:         }
32:         int rz_at_begin; // lower bound for block numbers
33:         int rz_at_end;   // past-the-end upper bound for block numbers
34:
35:         template< typename ByteIter > void extractor_rz_tab(ByteIter buf);
36:         void extract_rz_tab(RZSignatureTable::Signature const &);
37:
38:         ConTable() {}
39:         ConTable(RZWrapper const &wrapper): RemoteWrapper(wrapper)
40:         {
41:             extract_rz_tab(wrapper.signature_table);
42:         }
43:         void operator=(RZWrapper const &wrapper)
44:         {
45:             RemoteWrapper::extract_header(wrapper);
46:             extract_rz_tab(wrapper.signature_table);
47:         }
48:
49:         void extract_rz_tab(std::FILE *);
50:         ConTable(struct IntermediateWrapper const &interwrap)
51:         {
52:             extractor_header(interwrap.rz_header);
53:             extract_rz_tab(interwrap.RZ_WRAPPER);
54:         }
55:     private:
56:         std::vector< unsigned int > rz_tab;
57:     };
58: }
59:         
60: template< typename ByteIter >
61: void RZ::RemoteWrapper::extractor_header(ByteIter const buffer)
62: {
63:     n_blks = net_in(buffer + 32);
64:     rz_end = net_in(buffer + 44);
65:     rz_off = net_in(buffer + 60);
66:
67:     wrapper_size = 64 + 16 * n_blks;
68:     file_size = wrapper_size + rz_end;
69: }
70:
71: template< typename ByteIter >
72: void RZ::ConTable::extractor_rz_tab(ByteIter const buffer)
73: {
74:     rz_tab.push_back(0);
75:     rz_at_begin = 0;
76:     if (rz_off) { rz_tab.push_back(rz_off); --rz_at_begin; }
77:     {
78:         ByteIter b = buffer + 64;
79:         for (unsigned int i = 0; i < n_blks; ++i) {
80:             rz_tab.push_back(net_in(b + 12));
81:             b += 16;
82:         }
83:     }
84:     rz_at_end = n_blks;
85:     if (rz_end - rz_tab.back()) { rz_tab.push_back(rz_end); ++rz_at_end; }
86:
87:     rz_to = rz_tab.begin();
88:     if (rz_off) ++rz_to;
89:     rz_at = rz_to++;
90: }
91:
92: // ExtractRemoteCon.hh # rz offsets table for analysis and synthesis
93:
94: #endif