blob: e5150dffa4fa3c04fc1cb2523fe6e16ee19aae86 [file] [log] [blame]
Mike Lockwood16864ba2010-05-11 17:16:59 -04001/*
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
Yin Liu014897f2012-12-04 09:19:53 +010022// Max Character number of a MTP String
23#define MTP_STRING_MAX_CHARACTER_NUMBER 255
24
Mike Lockwood7850ef92010-05-14 10:10:36 -040025namespace android {
26
Mike Lockwood16864ba2010-05-11 17:16:59 -040027class MtpDataPacket;
28
29// Represents a utf8 string, with a maximum of 255 characters
30class MtpStringBuffer {
31
32private:
Mike Lockwooddde37202010-09-25 21:21:05 -040033 // mBuffer contains string in UTF8 format
Mike Lockwood16864ba2010-05-11 17:16:59 -040034 // maximum 3 bytes/character, with 1 extra for zero termination
Yin Liu014897f2012-12-04 09:19:53 +010035 uint8_t mBuffer[MTP_STRING_MAX_CHARACTER_NUMBER * 3 + 1];
Mike Lockwood16864ba2010-05-11 17:16:59 -040036 int mCharCount;
37 int mByteCount;
38
39public:
40 MtpStringBuffer();
41 MtpStringBuffer(const char* src);
Mike Lockwooddde37202010-09-25 21:21:05 -040042 MtpStringBuffer(const uint16_t* src);
Mike Lockwood16864ba2010-05-11 17:16:59 -040043 MtpStringBuffer(const MtpStringBuffer& src);
44 virtual ~MtpStringBuffer();
45
46 void set(const char* src);
Mike Lockwooddde37202010-09-25 21:21:05 -040047 void set(const uint16_t* src);
Mike Lockwood16864ba2010-05-11 17:16:59 -040048
49 void readFromPacket(MtpDataPacket* packet);
50 void writeToPacket(MtpDataPacket* packet) const;
51
52 inline int getCharCount() const { return mCharCount; }
53 inline int getByteCount() const { return mByteCount; }
54
55 inline operator const char*() const { return (const char *)mBuffer; }
56};
57
Mike Lockwood7850ef92010-05-14 10:10:36 -040058}; // namespace android
59
Mike Lockwood16864ba2010-05-11 17:16:59 -040060#endif // _MTP_STRING_BUFFER_H