1 /* 2 * Copyright 2019 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 #ifndef _IO_STREAM_INPUTSTREAM_H_ 17 #define _IO_STREAM_INPUTSTREAM_H_ 18 19 #include <cstdint> 20 21 namespace parselib { 22 23 /** 24 * An interface declaration for a stream of bytes. Concrete implements for File and Memory Buffers 25 */ 26 class InputStream { 27 public: InputStream()28 InputStream() {} ~InputStream()29 virtual ~InputStream() {} 30 31 /** 32 * Retrieve the specified number of bytes and advance the read position. 33 * Returns: The number of bytes actually retrieved. May be less than requested 34 * if attempt to read beyond the end of the stream. 35 */ 36 virtual int32_t read(void *buff, int32_t numBytes) = 0; 37 38 /** 39 * Retrieve the specified number of bytes. DOES NOT advance the read position. 40 * Returns: The number of bytes actually retrieved. May be less than requested 41 * if attempt to read beyond the end of the stream. 42 */ 43 virtual int32_t peek(void *buff, int32_t numBytes) = 0; 44 45 /** 46 * Moves the read position forward the (positive) number of bytes specified. 47 */ 48 virtual void advance(int32_t numBytes) = 0; 49 50 /** 51 * Returns the read position of the stream 52 */ 53 virtual int32_t getPos() = 0; 54 55 /** 56 * Sets the read position of the stream to the 0 or positive position. 57 */ 58 virtual void setPos(int32_t pos) = 0; 59 }; 60 61 } // namespace parselib 62 63 #endif // _IO_STREAM_INPUTSTREAM_H_ 64