blob: 78950bb19eb40fafdca28540ac317216a03b6e34 [file] [log] [blame]
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -07001// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_PROTOBUF_LITE_STREAMS_H_
6#define SHILL_PROTOBUF_LITE_STREAMS_H_
7
8#include <string>
9
10#include <base/file_util.h>
11#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
12
13// Some basic input/output streams are not implemented for protobuf-lite.
14
15namespace shill {
16
17// Attempts to create a |google::protobuf::io::CopyingInputStreamAdaptor| using
18// a |shill::ProtobufLiteCopyingFileInputStream|. Returns a new instance on
19// success. The caller owns the new instance, and must free it when done.
20// Returns NULL on failure.
21google::protobuf::io::CopyingInputStreamAdaptor *
22protobuf_lite_file_input_stream(const std::string &file_path);
23
24
25class ProtobufLiteCopyingFileInputStream :
26 public google::protobuf::io::CopyingInputStream {
27 public:
28 // Takes ownership of |fd| and closes it when the object is deleted.
29 explicit ProtobufLiteCopyingFileInputStream(int fd);
30 virtual ~ProtobufLiteCopyingFileInputStream();
31 virtual int Read(void *buffer, int size);
32 virtual int Skip(int count);
33 private:
34 int fd_;
35 file_util::ScopedFD scoped_fd_closer_;
36 bool previous_seek_failed_;
37
38 DISALLOW_COPY_AND_ASSIGN(ProtobufLiteCopyingFileInputStream);
39};
40
41} // namespace shill
42
43#endif // SHILL_PROTOBUF_LITE_STREAMS_H_