Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | * Expanding byte buffer, with primitives for appending basic data types. |
| 18 | */ |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 19 | #ifndef ART_RUNTIME_JDWP_JDWP_EXPAND_BUF_H_ |
| 20 | #define ART_RUNTIME_JDWP_JDWP_EXPAND_BUF_H_ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 21 | |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 22 | #include <string> |
| 23 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 24 | #include <stddef.h> |
| 25 | #include <stdint.h> |
| 26 | |
| 27 | namespace art { |
| 28 | |
| 29 | namespace JDWP { |
| 30 | |
| 31 | struct ExpandBuf; /* private */ |
Elliott Hughes | 6e9d22c | 2012-06-22 15:02:37 -0700 | [diff] [blame] | 32 | struct JdwpLocation; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 33 | |
| 34 | /* create a new struct */ |
| 35 | ExpandBuf* expandBufAlloc(); |
| 36 | /* free storage */ |
| 37 | void expandBufFree(ExpandBuf* pBuf); |
| 38 | |
| 39 | /* |
| 40 | * Accessors. The buffer pointer and length will only be valid until more |
| 41 | * data is added. |
| 42 | */ |
| 43 | uint8_t* expandBufGetBuffer(ExpandBuf* pBuf); |
| 44 | size_t expandBufGetLength(ExpandBuf* pBuf); |
| 45 | |
| 46 | /* |
| 47 | * The "add" operations allocate additional storage and append the data. |
| 48 | * |
| 49 | * There are no "get" operations included with this "class", other than |
| 50 | * GetBuffer(). If you want to get or set data from a position other |
| 51 | * than the end, get a pointer to the buffer and use the inline functions |
| 52 | * defined elsewhere. |
| 53 | * |
| 54 | * expandBufAddSpace() returns a pointer to the *start* of the region |
| 55 | * added. |
| 56 | */ |
| 57 | uint8_t* expandBufAddSpace(ExpandBuf* pBuf, int gapSize); |
| 58 | void expandBufAdd1(ExpandBuf* pBuf, uint8_t val); |
| 59 | void expandBufAdd2BE(ExpandBuf* pBuf, uint16_t val); |
| 60 | void expandBufAdd4BE(ExpandBuf* pBuf, uint32_t val); |
| 61 | void expandBufAdd8BE(ExpandBuf* pBuf, uint64_t val); |
Elliott Hughes | 4740cdf | 2011-12-07 14:07:12 -0800 | [diff] [blame] | 62 | void expandBufAddUtf8String(ExpandBuf* pBuf, const char* s); |
| 63 | void expandBufAddUtf8String(ExpandBuf* pBuf, const std::string& s); |
Elliott Hughes | 6e9d22c | 2012-06-22 15:02:37 -0700 | [diff] [blame] | 64 | void expandBufAddLocation(ExpandBuf* pReply, const JdwpLocation& location); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 65 | |
| 66 | } // namespace JDWP |
| 67 | |
| 68 | } // namespace art |
| 69 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 70 | #endif // ART_RUNTIME_JDWP_JDWP_EXPAND_BUF_H_ |