Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 _MTP_STRING_BUFFER_H |
| 18 | #define _MTP_STRING_BUFFER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
Mike Lockwood | 8d3257a | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 22 | namespace android { |
| 23 | |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 24 | class MtpDataPacket; |
| 25 | |
| 26 | // Represents a utf8 string, with a maximum of 255 characters |
| 27 | class MtpStringBuffer { |
| 28 | |
| 29 | private: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame] | 30 | // mBuffer contains string in UTF8 format |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 31 | // maximum 3 bytes/character, with 1 extra for zero termination |
| 32 | uint8_t mBuffer[255 * 3 + 1]; |
| 33 | int mCharCount; |
| 34 | int mByteCount; |
| 35 | |
| 36 | public: |
| 37 | MtpStringBuffer(); |
| 38 | MtpStringBuffer(const char* src); |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame] | 39 | MtpStringBuffer(const uint16_t* src); |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 40 | MtpStringBuffer(const MtpStringBuffer& src); |
| 41 | virtual ~MtpStringBuffer(); |
| 42 | |
| 43 | void set(const char* src); |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame] | 44 | void set(const uint16_t* src); |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 45 | |
| 46 | void readFromPacket(MtpDataPacket* packet); |
| 47 | void writeToPacket(MtpDataPacket* packet) const; |
| 48 | |
| 49 | inline int getCharCount() const { return mCharCount; } |
| 50 | inline int getByteCount() const { return mByteCount; } |
| 51 | |
| 52 | inline operator const char*() const { return (const char *)mBuffer; } |
| 53 | }; |
| 54 | |
Mike Lockwood | 8d3257a | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 55 | }; // namespace android |
| 56 | |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 57 | #endif // _MTP_STRING_BUFFER_H |