ProteoWizard
BinaryDataEncoder.hpp
Go to the documentation of this file.
1 //
2 // $Id: BinaryDataEncoder.hpp 3071 2011-10-21 17:40:37Z pcbrefugee $
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2007 Spielberg Family Center for Applied Proteomics
8 // Cedars Sinai Medical Center, Los Angeles, California 90048
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 
24 #ifndef _BINARYDATAENCODER_HPP_
25 #define _BINARYDATAENCODER_HPP_
26 
27 
29 #include "boost/shared_ptr.hpp"
30 #include <string>
31 #include <vector>
32 #include <map>
33 #include "pwiz/data/common/cv.hpp"
34 
35 
36 namespace pwiz {
37 namespace msdata {
38 
39 
40 /// binary-to-text encoding
42 {
43  public:
44 
45  enum Precision {Precision_32, Precision_64};
46  enum ByteOrder {ByteOrder_LittleEndian, ByteOrder_BigEndian};
47  enum Compression {Compression_None, Compression_Zlib};
48 
49  /// encoding/decoding configuration
51  {
55 
56  std::map<cv::CVID, Precision> precisionOverrides;
57 
59  : precision(Precision_64),
60  byteOrder(ByteOrder_LittleEndian),
61  compression(Compression_None)
62  {}
63  };
64 
65  BinaryDataEncoder(const Config& config = Config());
66 
67  /// encode binary data as a text string
68  void encode(const std::vector<double>& data, std::string& result, size_t* binaryByteCount = NULL) const;
69 
70  /// encode binary data as a text string
71  void encode(const double* data, size_t dataSize, std::string& result, size_t* binaryByteCount = NULL) const;
72 
73  /// decode text-encoded data as binary
74  void decode(const char *encodedData, size_t len, std::vector<double>& result) const;
75  void decode(const std::string& encodedData, std::vector<double>& result) const
76  {
77  decode(encodedData.c_str(),encodedData.length(),result);
78  }
79 
80  private:
81  class Impl;
82  boost::shared_ptr<Impl> impl_;
84  BinaryDataEncoder& operator=(const BinaryDataEncoder&);
85 };
86 
87 
88 PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const BinaryDataEncoder::Config& config);
89 
90 
91 } // namespace msdata
92 } // namespace pwiz
93 
94 
95 #endif // _BINARYDATAENCODER_HPP_
96