header.h 2.0 KB
Newer Older
D
"init"  
dzhwinter 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//   Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <sstream>

D
dongzhihong 已提交
19 20
#include "paddle/fluid/recordio/io.h"

D
"init"  
dzhwinter 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
namespace paddle {
namespace recordio {

// Default ChunkSize
constexpr size_t kDefaultMaxChunkSize = 32 * 1024 * 1024;
// MagicNumber for memory checking
constexpr uint32_t kMagicNumber = 0x01020304;

enum class Compressor {
  // NoCompression means writing raw chunk data into files.
  // With other choices, chunks are compressed before written.
  kNoCompress = 0,
  // Snappy had been the default compressing algorithm widely
  // used in Google.  It compromises between speech and
  // compression ratio.
  kSnappy = 1,
  // Gzip is a well-known compression algorithm.  It is
  // recommmended only you are looking for compression ratio.
  kGzip = 2,
};

// Header is the metadata of Chunk
class Header {
public:
  Header();
  Header(uint32_t num, uint32_t sum, Compressor ct, uint32_t cs);

D
dongzhihong 已提交
48 49
  void Write(Stream* os);
  void Parse(Stream* iss);
D
"init"  
dzhwinter 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

  uint32_t NumRecords() const { return num_records_; }
  uint32_t Checksum() const { return checksum_; }
  Compressor CompressType() const { return compressor_; }
  uint32_t CompressSize() const { return compress_size_; }

private:
  uint32_t num_records_;
  uint32_t checksum_;
  Compressor compressor_;
  uint32_t compress_size_;
};

// Allow Header Loggable
std::ostream& operator<<(std::ostream& os, Header h);
bool operator==(Header l, Header r);

}  // namespace recordio
}  // namespace paddle