Fix svace issue
[platform/core/multimedia/esplusplayer.git] / src / plusplayer-core / src / serializer.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "core/serializer.h"
18 // LCOV_EXCL_START
19 namespace esplusplayer {
20 using Offset = Serializer::Offset;
21 using Byte = Serializer::Byte;
22
23 Offset Serializer::Put(const std::vector<unsigned char> &vector) {
24   Offset offset = static_cast<unsigned int>(size_);
25   if (vector.size() == 0) return offset;
26   const size_t size = vector.size();
27   const Byte *data_bytes = reinterpret_cast<const Byte *>(vector.data());
28   Put_(data_bytes, size);
29   return offset;
30 }
31
32 Offset Serializer::Put(const std::string &data) {
33   Offset offset = static_cast<unsigned int>(size_);
34   if (data.length() == 0) return offset;
35   const size_t size = data.length();
36   const Byte *data_bytes = reinterpret_cast<const Byte *>(data.c_str());
37   Put_(data_bytes, size);
38   return offset;
39 }
40
41 Offset Serializer::Put(const Byte *data, size_t size) {
42   Offset offset = static_cast<unsigned int>(size_);
43   if (size == 0) return offset;
44   Put_(data, size);
45   return offset;
46 }
47
48 size_t Serializer::Serialize(Byte *serialized) {
49   buf_.sgetn(serialized, static_cast<std::streamsize>(size_));
50   return size_;
51 }
52
53 const size_t Serializer::GetSize() { return size_; }
54
55 void Serializer::Put_(const Byte *data_bytes, const size_t size) {
56   buf_.sputn(data_bytes, static_cast<std::streamsize>(size));
57   size_ += size;
58 }
59 }
60 // LCOV_EXCL_STOP
61 // namespace esplusplayer