• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MEMINPUTSTREAM_H_
17 #define _IO_STREAM_MEMINPUTSTREAM_H_
18 
19 #include "InputStream.h"
20 
21 namespace parselib {
22 
23 /**
24  * A concrete implementation of InputStream for a memory buffer data source
25  */
26 class MemInputStream : public InputStream {
27 public:
28     /** constructor. Caller is presumed to have allocated and filled the memory buffer */
MemInputStream(unsigned char * buff,int32_t len)29     MemInputStream(unsigned char *buff, int32_t len) : mBuffer(buff), mBufferLen(len), mPos(0) {}
~MemInputStream()30     virtual ~MemInputStream() {}
31 
32     virtual int32_t read(void *buff, int32_t numBytes);
33 
34     virtual int32_t peek(void *buff, int32_t numBytes);
35 
36     virtual void advance(int32_t numBytes);
37 
38     virtual int32_t getPos();
39 
40     virtual void setPos(int32_t pos);
41 
42 private:
43     /** Points to the data buffer to stream from. */
44     unsigned char *mBuffer;
45 
46     /** Total number of bytes in the memory buffer */
47     int32_t mBufferLen;
48 
49     /** The index of the next byte to read */
50     int32_t mPos;
51 };
52 
53 } // namespace parselib
54 
55 #endif // _IO_STREAM_MEMINPUTSTREAM_H_
56