chunk.h 1.5 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_; }
D
"init"  
dzhwinter 已提交
35 36

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

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

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

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