2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 #define ARRAY_AND_SIZE(x) (uint8_t *)(&x), sizeof(x)
30 namespace smartcard_service_api
32 class EXPORT ByteArray //: public Serializable
38 bool _assign(uint8_t *array, size_t size);
39 void save(const char *filePath);
42 static ByteArray EMPTY;
45 ByteArray(const uint8_t *array, size_t size);
46 ByteArray(const ByteArray &T);
49 // ByteArray serialize();
50 // void deserialize(ByteArray buffer);
52 bool assign(const uint8_t *array, size_t size);
53 inline bool setBuffer(const uint8_t *array, size_t size) { return assign(array, size); }
57 inline size_t getLength() const { return size(); }
59 const uint8_t *getBuffer() const;
60 uint8_t *getBuffer(size_t offset);
61 const uint8_t *getBuffer(size_t offset) const;
63 uint8_t at(size_t index) const;
64 uint8_t reverseAt(size_t index) const;
66 size_t extract(uint8_t *array, size_t size) const;
68 const ByteArray sub(size_t offset, size_t size) const;
70 /* operator overloading */
71 ByteArray &operator =(const ByteArray &T);
72 ByteArray operator +(const ByteArray &T);
73 ByteArray &operator +=(const ByteArray &T);
74 bool operator ==(const ByteArray &T) const;
75 bool operator !=(const ByteArray &T) const;
76 bool operator <(const ByteArray &T) const;
77 bool operator >(const ByteArray &T) const;
78 uint8_t operator [](size_t index) const;
80 inline bool isEmpty() const { return (buffer == (void *)0 || length == 0); }
81 const string toString() const;
84 } /* namespace smartcard_service_api */
85 #endif /* BYTEARRAY_H_ */