2 * Copyright (c) 2023 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 #include "core/serializer.h"
19 namespace esplusplayer {
20 using Offset = Serializer::Offset;
21 using Byte = Serializer::Byte;
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);
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);
41 Offset Serializer::Put(const Byte *data, size_t size) {
42 Offset offset = static_cast<unsigned int>(size_);
43 if (size == 0) return offset;
48 size_t Serializer::Serialize(Byte *serialized) {
49 buf_.sgetn(serialized, size_);
53 const size_t Serializer::GetSize() { return size_; }
55 void Serializer::Put_(const Byte *data_bytes, const size_t size) {
56 buf_.sputn(data_bytes, size);
61 // namespace esplusplayer