MtpStringBuffer.h revision 7850ef999740f214a1990a9c090d3f3865d435aa
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 22namespace android { 23 24class MtpDataPacket; 25 26// Represents a utf8 string, with a maximum of 255 characters 27class MtpStringBuffer { 28 29private: 30 // maximum 3 bytes/character, with 1 extra for zero termination 31 uint8_t mBuffer[255 * 3 + 1]; 32 int mCharCount; 33 int mByteCount; 34 35public: 36 MtpStringBuffer(); 37 MtpStringBuffer(const char* src); 38 MtpStringBuffer(const MtpStringBuffer& src); 39 virtual ~MtpStringBuffer(); 40 41 void set(const char* src); 42 43 void readFromPacket(MtpDataPacket* packet); 44 void writeToPacket(MtpDataPacket* packet) const; 45 46 inline int getCharCount() const { return mCharCount; } 47 inline int getByteCount() const { return mByteCount; } 48 49 inline operator const char*() const { return (const char *)mBuffer; } 50}; 51 52}; // namespace android 53 54#endif // _MTP_STRING_BUFFER_H 55