NCBI C++ ToolKit
Cache_blob.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: Cache_blob.cpp 94920 2021-09-21 20:02:25Z vasilche $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'cache_blob.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
42 
43 #include <corelib/rwstream.hpp>
44 #include <util/compress/stream.hpp>
45 #include <util/compress/zlib.hpp>
46 
47 #include "md5_writer.hpp"
48 
49 #include <serial/serial.hpp>
50 #include <serial/objostrasnb.hpp>
51 #include <serial/objistrasnb.hpp>
52 
54 #include <strstream>
55 
56 // generated classes
57 
59 
60 BEGIN_objects_SCOPE // namespace ncbi::objects::
61 
62 
63 // constructor
65 {
66 }
67 
68 
69 // destructor
71 {
72 }
73 
74 
75 void CCache_blob::Pack(const CSeq_entry& entry)
76 {
77  CMD5StreamWriter<TBlob> md5_buffer(SetBlob());
78 
79  {{
80  CWStream flatten_stream(&md5_buffer);
82  CCompressionOStream compress_stream(flatten_stream, &comp);
83  CObjectOStreamAsnBinary asn_stream(compress_stream);
84  asn_stream << entry;
85  asn_stream.Flush();
86  compress_stream.flush();
87  md5_buffer.Flush();
88  }}
89 
90  vector<unsigned char> md5_digest(md5_buffer.GetMD5Sum() );
91  vector<char>& blob_md5_digest = SetMd5_digest();
92  blob_md5_digest.resize(md5_digest.size());
93  memcpy(&blob_md5_digest[0], &md5_digest[0], md5_digest.size());
95 }
96 
97 
98 void CCache_blob::UnPack(CSeq_entry& entry) const
99 {
100  const TBlob& raw_data = GetBlob();
101 
102  istrstream istr(&raw_data[0], raw_data.size() );
103 
104  CZipStreamDecompressor decomp;
105  CCompressionIStream decomp_str(istr, &decomp);
106  CObjectIStreamAsnBinary asn_str(decomp_str);
107  asn_str >> entry;
108 }
109 
110 
111 void CCache_blob::UnPack(vector<unsigned char>& raw_bytes) const
112 {
113  const TBlob& raw_data = GetBlob();
114 
115  istrstream istr(&raw_data[0], raw_data.size() );
116 
117  CZipStreamDecompressor decomp;
118  CCompressionIStream decomp_str(istr, &decomp);
119 
120  raw_bytes.clear();
121  raw_bytes.reserve(raw_data.size() * 4);
122  unsigned char buf[1024];
123  for (;;) {
124  decomp_str.read((char*)buf, sizeof(buf));
125  size_t size = decomp_str.gcount();
126  if ( !size ) {
127  break;
128  }
129  raw_bytes.insert(raw_bytes.end(),
130  buf, buf + size);
131  }
132 }
133 
134 
135 
136 
137 END_objects_SCOPE // namespace ncbi::objects::
138 
140 
141 /* Original file checksum: lines: 57, chars: 1743, CRC32: 66964205 */
User-defined methods of the data storage class.
void UnPack(CSeq_entry &entry) const
Definition: Cache_blob.cpp:98
void Pack(const CSeq_entry &entry)
Definition: Cache_blob.cpp:75
~CCache_blob(void)
Definition: Cache_blob.cpp:70
CCache_blob(void)
Definition: Cache_blob.cpp:64
Stream hook that calculates the MD5 digest of the data passed to a CBufferWriter.
Definition: md5_writer.hpp:53
virtual ERW_Result Flush()
Flush pending data (if any) down to the output device.
Definition: md5_writer.hpp:69
std::vector< unsigned char > GetMD5Sum() const
Definition: md5_writer.hpp:74
CObjectIStreamAsnBinary –.
Definition: objistrasnb.hpp:59
CObjectOStreamAsnBinary –.
Definition: objostrasnb.hpp:58
Definition: Seq_entry.hpp:56
Writer-based output stream.
Definition: rwstream.hpp:171
CZipStreamCompressor – zlib based compression stream processor.
Definition: zlib.hpp:763
CZipStreamDecompressor – zlib based decompression stream processor.
Definition: zlib.hpp:817
void Flush(void)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TBlob & SetBlob(void)
Assign a value to Blob data member.
vector< char > TBlob
Definition: Cache_blob_.hpp:87
TMagic & SetMagic(void)
Assign a value to Magic data member.
TMd5_digest & SetMd5_digest(void)
Assign a value to Md5_digest data member.
const TBlob & GetBlob(void) const
Get the Blob member data.
char * buf
const struct ncbi::grid::netcache::search::fields::SIZE size
Reader-writer based streams.
ZLib Compression API.
Modified on Fri Sep 20 14:57:32 2024 by modify_doxy.py rev. 669887