chunk.h 1.6 KB
Newer Older
D
"init"  
dzhwinter 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//   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
D
dongzhihong 已提交
16
#include <forward_list>
D
"init"  
dzhwinter 已提交
17 18
#include <string>

D
dongzhihong 已提交
19 20 21 22 23 24 25
#include "paddle/fluid/recordio/header.h"
#include "paddle/fluid/recordio/io.h"

namespace paddle {
namespace recordio {

// A Chunk contains the Header and optionally compressed records.
D
"init"  
dzhwinter 已提交
26 27
class Chunk {
public:
28
  Chunk() : num_bytes_(0) {}
D
dongzhihong 已提交
29 30 31 32 33
  void Add(const char* record, size_t size);
  // dump the chunk into w, and clears the chunk and makes it ready for
  // the next add invocation.
  bool Dump(Stream* fo, Compressor ct);
  void Parse(Stream* fi, size_t offset);
D
dongzhihong 已提交
34
  size_t NumBytes() { return num_bytes_; }
35
  const std::string Record(int i) { return records_[i]; }
D
"init"  
dzhwinter 已提交
36 37

private:
38
  std::forward_list<const std::string> records_;
D
dongzhihong 已提交
39
  // sum of record lengths in bytes.
D
"init"  
dzhwinter 已提交
40
  size_t num_bytes_;
D
dongzhihong 已提交
41
  DISABLE_COPY_AND_ASSIGN(Chunk);
D
"init"  
dzhwinter 已提交
42 43
};

D
dongzhihong 已提交
44
size_t CompressData(const char* in, size_t in_length, Compressor ct, char* out);
D
"init"  
dzhwinter 已提交
45

D
dongzhihong 已提交
46
void DeflateData(const char* in, size_t in_length, Compressor ct, char* out);
D
"init"  
dzhwinter 已提交
47

D
dongzhihong 已提交
48 49
}  // namespace recordio
}  // namespace paddle