-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef AUL_SOCKET_PARCEL_HH_
-#define AUL_SOCKET_PARCEL_HH_
-
-#include <vector>
-
-namespace aul {
-
-class Parcel {
- public:
- Parcel() = default;
- Parcel(const unsigned char* buf, unsigned int size);
-
- void Write(const unsigned char* buf, unsigned int size);
- void Read(unsigned char* buf, unsigned int size);
- void WriteInt32(int i);
- int ReadInt32();
- const std::vector<unsigned char>& GetRaw();
-
- private:
- template<typename T>
- void Write(T d) {
- unsigned char* p = reinterpret_cast<unsigned char*>(&d);
- std::copy(p, p + sizeof(T), std::back_inserter(data_));
- }
-
- template<typename T>
- T Read() {
- T d = 0;
- unsigned char* p = reinterpret_cast<unsigned char*>(&d);
- if (reader_ + sizeof(T) > data_.size())
- return d;
-
- std::copy(&data_[reader_], &data_[reader_] + sizeof(T), p);
- reader_ += sizeof(T);
- return d;
- }
-
- private:
- std::vector<unsigned char> data_;
- unsigned int reader_ = 0;
-};
-
-} // namespace aul
-
-#endif // AUL_SOCKET_PARCEL_HH_