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.
20 /* standard library header */
25 /* SLP library header */
28 //#include "Serializable.h"
30 #define ARRAY_AND_SIZE(x) (uint8_t *)(&x), sizeof(x)
34 namespace smartcard_service_api
36 class ByteArray //: public Serializable
42 bool _assign(uint8_t *array, size_t size);
43 void save(const char *filePath);
46 static ByteArray EMPTY;
49 ByteArray(const uint8_t *array, size_t size);
50 ByteArray(const ByteArray &T);
53 // ByteArray serialize();
54 // void deserialize(ByteArray buffer);
56 bool assign(const uint8_t *array, size_t size);
57 inline bool setBuffer(const uint8_t *array, size_t size) { return assign(array, size); }
61 inline size_t getLength() const { return size(); }
63 const uint8_t *getBuffer() const;
64 uint8_t *getBuffer(size_t offset);
65 const uint8_t *getBuffer(size_t offset) const;
67 uint8_t at(size_t index) const;
68 uint8_t reverseAt(size_t index) const;
70 size_t extract(uint8_t *array, size_t size) const;
72 const ByteArray sub(size_t offset, size_t size) const;
74 /* operator overloading */
75 ByteArray &operator =(const ByteArray &T);
76 ByteArray operator +(const ByteArray &T);
77 ByteArray &operator +=(const ByteArray &T);
78 bool operator ==(const ByteArray &T) const;
79 bool operator !=(const ByteArray &T) const;
80 bool operator <(const ByteArray &T) const;
81 bool operator >(const ByteArray &T) const;
82 uint8_t operator[](size_t index) const;
84 inline bool isEmpty() const { return (buffer == (void *)0 || length == 0); }
85 const string toString(bool entire) const;
86 const string toString() const;
89 } /* namespace smartcard_service_api */
90 #endif /* BYTEARRAY_H_ */