atlas
Data.h
1 /*
2  * (C) Copyright 2020 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation
8  * nor does it submit to any jurisdiction.
9  */
10 
11 #pragma once
12 
13 #include "eckit/io/Buffer.h"
14 
15 namespace atlas {
16 namespace io {
17 
18 class Stream;
19 
20 //---------------------------------------------------------------------------------------------------------------------
21 
22 class Data {
23 public:
24  Data() = default;
25  Data( void*, size_t );
26  Data( Data&& ) = default;
27  Data& operator=( Data&& ) = default;
28 
29  operator const void*() const { return data(); }
30  const void* data() const { return buffer_.data(); }
31  size_t size() const { return size_; }
32 
33  void assign( const Data& other );
34  void assign( const void*, size_t );
35  void clear();
36 
37  std::uint64_t write( Stream& out ) const;
38  std::uint64_t read( Stream& in, size_t size );
39  void compress( const std::string& compression );
40  void decompress( const std::string& compression, size_t uncompressed_size );
41  std::string checksum( const std::string& algorithm = "" ) const;
42 
43 private:
44  eckit::Buffer buffer_;
45  size_t size_{0};
46 };
47 
48 //---------------------------------------------------------------------------------------------------------------------
49 
50 void encode_data( const Data&, Data& out );
51 
52 //---------------------------------------------------------------------------------------------------------------------
53 
54 } // namespace io
55 } // namespace atlas
Handle to a shared eckit::DataHandle.
Definition: Stream.h:31
Definition: Data.h:22
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33