• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SRC_TRACING_CORE_SLICED_PROTOBUF_INPUT_STREAM_H_
18 #define SRC_TRACING_CORE_SLICED_PROTOBUF_INPUT_STREAM_H_
19 
20 #include "perfetto/tracing/core/slice.h"
21 
22 #include <stdint.h>
23 
24 #include "google/protobuf/io/zero_copy_stream.h"
25 
26 namespace perfetto {
27 
28 // Wraps a sequence of Slice(s) in a protobuf ZeroCopyInputStream that can be
29 // passed to protobuf::Message::ParseFromZeroCopyStream().
30 class SlicedProtobufInputStream
31     : public google::protobuf::io::ZeroCopyInputStream {
32  public:
33   explicit SlicedProtobufInputStream(const Slices*);
34   ~SlicedProtobufInputStream() override;
35 
36   // ZeroCopyInputStream implementation. See zero_copy_stream.h for the API
37   // contract of the methods below.
38   bool Next(const void** data, int* size) override;
39   void BackUp(int count) override;
40   bool Skip(int count) override;
41   google::protobuf::int64 ByteCount() const override;
42 
43  private:
44   bool Validate() const;
45 
46   const Slices* const slices_;
47   Slices::const_iterator cur_slice_;
48   size_t pos_in_cur_slice_ = 0;
49 };
50 
51 }  // namespace perfetto
52 
53 #endif  // SRC_TRACING_CORE_SLICED_PROTOBUF_INPUT_STREAM_H_
54