2 * Copyright (c) 2011 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 * @file binary_queue.h
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the header file of binary queue
22 #ifndef CENT_KEY_BINARY_QUEUE_H
23 #define CENT_KEY_BINARY_QUEUE_H
25 #include <dpl/exception.h>
28 #include <symbol-visibility.h>
33 * Binary stream implemented as constant size bucket list
35 class COMMON_API BinaryQueue final {
39 DECLARE_EXCEPTION_TYPE(CKM::Exception, Base)
40 DECLARE_EXCEPTION_TYPE(Base, OutOfData)
44 typedef std::vector<unsigned char> Bucket;
46 typedef std::list<Bucket> BucketList;
52 * Construct empty binary queue
56 BinaryQueue(const BinaryQueue &other) = delete;
59 * Construct binary queue by moving data from other binary queue
61 * @param[in] other Other binary queue to move from
63 BinaryQueue(BinaryQueue &&) = default;
66 * Append copy of @a bufferSize bytes from memory pointed by @a buffer
67 * to the end of binary queue. Uses default deleter based on free.
70 * @param[in] buffer Pointer to buffer to copy data from
71 * @param[in] bufferSize Number of bytes to copy
72 * @exception std::bad_alloc Cannot allocate memory to hold additional data
74 void AppendCopy(const void *buffer, size_t bufferSize);
77 * Retrieve total size of all data contained in binary queue
79 * @return Number of bytes in binary queue
84 * Retrieve @a bufferSize bytes from beginning of binary queue, copy them
85 * to user supplied buffer, and remove from binary queue
88 * @param[in] buffer Pointer to user buffer to receive bytes
89 * @param[in] bufferSize Size of user buffer pointed by @a buffer
90 * @exception BinaryQueue::Exception::OutOfData Number of bytes to flatten
91 * is larger than available bytes in binary queue
93 void FlattenConsume(void *buffer, size_t bufferSize);
98 #endif // CENT_KEY_BINARY_QUEUE_H