2 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Bumjin Im <bj.im@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
19 * @file secket-buffer.h
20 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
21 * @author Zofia Abramowska (z.abramowska@samsung.com)
23 * @brief Implementatin of MessageBuffer.
26 #ifndef _CENT_KEY_MNG_SOCKET_BUFFER_
27 #define _CENT_KEY_MNG_SOCKET_BUFFER_
29 #include <dpl/binary_queue.h>
30 #include <dpl/exception.h>
31 #include <dpl/serialization.h>
32 #include <dpl/raw-buffer.h>
33 #include <symbol-visibility.h>
37 class COMMON_API MessageBuffer : public CKM::IStream {
41 DECLARE_EXCEPTION_TYPE(CKM::Exception, Base)
42 DECLARE_EXCEPTION_TYPE(Base, OutOfData)
45 MessageBuffer() : m_bytesLeft(0) {}
47 MessageBuffer(MessageBuffer &&) = default;
48 MessageBuffer &operator=(MessageBuffer &&) = default;
50 void Push(const RawBuffer &data);
56 virtual void Read(size_t num, void *bytes);
58 virtual void Write(size_t num, const void *bytes);
60 // generic serialization
61 template <typename... Args>
62 static MessageBuffer Serialize(const Args &... args)
65 Serializer<Args...>::Serialize(buffer, args...);
69 // generic deserialization
70 template <typename... Args>
71 void Deserialize(Args &... args)
73 Deserializer<Args...>::Deserialize(*this, args...);
77 inline void CountBytesLeft()
80 return; // we already counted m_bytesLeft nothing to do
82 if (m_buffer.Size() < sizeof(size_t))
83 return; // we cannot count m_bytesLeft because buffer is too small
85 m_buffer.FlattenConsume(&m_bytesLeft, sizeof(size_t));
89 CKM::BinaryQueue m_buffer;
94 #endif // _CENT_KEY_MNG_SOCKET_BUFFER_