-
Notifications
You must be signed in to change notification settings - Fork 8
/
FilesystemMetadataExtractor.cpp
46 lines (40 loc) · 1.49 KB
/
FilesystemMetadataExtractor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
#include "FilesystemMetadataExtractor.h"
#include <boost/filesystem/operations.hpp>
#include <boost/optional.hpp>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <fstream>
namespace
{
class FilesystemMetadata : public MetadataExtractor::Metadata
{
public:
explicit FilesystemMetadata(std::string id) : Metadata(std::move(id))
{
}
std::shared_ptr<google::protobuf::io::CodedInputStream> CreateCodedInputStream() const override
{
struct Data
{
std::ifstream in;
boost::optional<google::protobuf::io::IstreamInputStream> zeroCopyInput;
boost::optional<google::protobuf::io::CodedInputStream> decoder;
};
std::shared_ptr<Data> data = std::make_shared<Data>();
data->in.open(_id.c_str(), std::ios::binary | std::ios::in);
if (!data->in.good())
return nullptr;
data->zeroCopyInput.emplace(&data->in);
data->decoder.emplace(&data->zeroCopyInput.get());
return { data, data->decoder.get_ptr() };
}
};
}
void FilesystemMetadataExtractor::Parse(boost::filesystem::path const& path)
{
boost::filesystem::directory_iterator end;
for (boost::filesystem::directory_iterator itr(path); itr != end; ++itr)
if (is_regular_file(itr->status()))
if (itr->path().extension().string().find(".protoc") != std::string::npos)
_metadatas.emplace_back(new FilesystemMetadata(itr->path().string()));
}