OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_DER_INPUT_H_ | 5 #ifndef NET_DER_INPUT_H_ |
6 #define NET_DER_INPUT_H_ | 6 #define NET_DER_INPUT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... | |
34 // input: A ByteReader is copied and then is used to read some number of | 34 // input: A ByteReader is copied and then is used to read some number of |
35 // bytes into the input, based on the content it is reading. A Mark can then be | 35 // bytes into the input, based on the content it is reading. A Mark can then be |
36 // set using the temporary ByteReader to indicate how far it read into the | 36 // set using the temporary ByteReader to indicate how far it read into the |
37 // Input. The original ByteReader can then be synchronized with how far the | 37 // Input. The original ByteReader can then be synchronized with how far the |
38 // temporary ByteReader read, by using either AdvanceToMark() or ReadToMark(). | 38 // temporary ByteReader read, by using either AdvanceToMark() or ReadToMark(). |
39 class NET_EXPORT_PRIVATE Input { | 39 class NET_EXPORT_PRIVATE Input { |
40 public: | 40 public: |
41 // Creates an empty Input, one from which no data can be read. | 41 // Creates an empty Input, one from which no data can be read. |
42 Input(); | 42 Input(); |
43 | 43 |
44 // Creates an Input from a constant array |data|. | |
45 template <size_t N> | |
46 explicit Input(const uint8_t(&data)[N]) | |
47 : data_(data), len_(N) {} | |
48 | |
44 // Creates an Input from the given |data| and |len|. | 49 // Creates an Input from the given |data| and |len|. |
45 Input(const uint8_t* data, size_t len); | 50 Input(const uint8_t* data, size_t len); |
46 | 51 |
47 // Creates an Input from the given string |s|. | 52 // Creates an Input from the given string |s|. |
48 explicit Input(const std::string& s); | 53 explicit Input(const std::string& s); |
mattm
2015/05/21 01:31:10
It occurs to me that this constructor is kinda dan
Ryan Sleevi
2015/05/21 01:38:13
Holy crap! You're totally right, and in fact all t
| |
49 | 54 |
50 // Returns the length in bytes of an Input's data. | 55 // Returns the length in bytes of an Input's data. |
51 size_t Length() const { return len_; } | 56 size_t Length() const { return len_; } |
52 | 57 |
53 // Return true if the Input's data and |other|'s data are byte-wise equal. | 58 // Return true if the Input's data and |other|'s data are byte-wise equal. |
54 bool Equals(const Input& other) const; | 59 bool Equals(const Input& other) const; |
55 | 60 |
56 // Returns a pointer to the Input's data. This method is marked as "unsafe" | 61 // Returns a pointer to the Input's data. This method is marked as "unsafe" |
57 // because access to the Input's data should be done through ByteReader | 62 // because access to the Input's data should be done through ByteReader |
58 // instead. This method should only be used where using a ByteReader truly | 63 // instead. This method should only be used where using a ByteReader truly |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 explicit Mark(const uint8_t* ptr); | 151 explicit Mark(const uint8_t* ptr); |
147 Mark(); | 152 Mark(); |
148 const uint8_t* ptr_; | 153 const uint8_t* ptr_; |
149 }; | 154 }; |
150 | 155 |
151 } // namespace der | 156 } // namespace der |
152 | 157 |
153 } // namespace net | 158 } // namespace net |
154 | 159 |
155 #endif // NET_DER_INPUT_H_ | 160 #endif // NET_DER_INPUT_H_ |
OLD | NEW |