1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "tlv_object.h"
16 
17 namespace OHOS {
18 namespace UDMF {
TLVObject(std::vector<std::uint8_t> &buffer)19 TLVObject::TLVObject(std::vector<std::uint8_t> &buffer)
20 {
21     total_ += buffer.size();
22     buffer_ = &buffer;
23     cursor_ = 0;
24     file_ = nullptr;
25 }
26 
SetFile(std::FILE *file)27 void TLVObject::SetFile(std::FILE *file)
28 {
29     file_ = file;
30 }
31 
UpdateSize()32 void TLVObject::UpdateSize()
33 {
34     if (file_ != nullptr) {
35         return;
36     }
37     buffer_->resize(total_);
38 }
39 
GetBuffer()40 std::vector<std::uint8_t> TLVObject::GetBuffer()
41 {
42     return *buffer_;
43 }
44 
GetTotal()45 size_t TLVObject::GetTotal()
46 {
47     return total_;
48 }
49 
GetCursor()50 size_t TLVObject::GetCursor()
51 {
52     return cursor_;
53 }
54 
OffsetHead()55 size_t TLVObject::OffsetHead()
56 {
57     if (file_ != nullptr) {
58         fseek(file_, sizeof(TLVHead), SEEK_CUR);
59     }
60     cursor_ += sizeof(TLVHead);
61     return cursor_;
62 }
63 
ResetCursor()64 void TLVObject::ResetCursor()
65 {
66     cursor_ = 0;
67     if (file_ != nullptr) {
68         fseek(file_, 0, SEEK_SET);
69     }
70 }
71 
Count(const std::string &value)72 size_t TLVObject::Count(const std::string &value)
73 {
74     return sizeof(TLVHead);
75 }
76 
Count(const std::vector<uint8_t> &value)77 size_t TLVObject::Count(const std::vector<uint8_t> &value)
78 {
79     return sizeof(TLVHead);
80 }
81 
Count(const OHOS::AAFwk::Want &value)82 size_t TLVObject::Count(const OHOS::AAFwk::Want &value)
83 {
84     return sizeof(TLVHead);
85 }
86 
Count(const std::monostate &value)87 size_t TLVObject::Count(const std::monostate &value)
88 {
89     return sizeof(TLVHead);
90 }
91 
Count(const void *value)92 size_t TLVObject::Count(const void *value)
93 {
94     return sizeof(TLVHead);
95 }
96 
Write(TAG tag, const std::string &value)97 bool TLVObject::Write(TAG tag, const std::string &value)
98 {
99     return true;
100 }
101 
Read(std::string &value, const TLVHead &head)102 bool TLVObject::Read(std::string &value, const TLVHead &head)
103 {
104     return true;
105 }
106 
Write(TAG tag, const std::vector<uint8_t> &value)107 bool TLVObject::Write(TAG tag, const std::vector<uint8_t> &value)
108 {
109     return true;
110 }
111 
112 
Read(std::vector<uint8_t> &value, const TLVHead &head)113 bool TLVObject::Read(std::vector<uint8_t> &value, const TLVHead &head)
114 {
115     return true;
116 }
117 
Write(TAG tag, const OHOS::AAFwk::Want &value)118 bool TLVObject::Write(TAG tag, const OHOS::AAFwk::Want &value)
119 {
120     return true;
121 }
122 
Read(OHOS::AAFwk::Want &value, const TLVHead &head)123 bool TLVObject::Read(OHOS::AAFwk::Want &value, const TLVHead &head)
124 {
125     return true;
126 }
127 
Write(TAG tag, const std::monostate &value)128 bool TLVObject::Write(TAG tag, const std::monostate &value)
129 {
130     return true;
131 }
132 
Read(std::monostate &value, const TLVHead &head)133 bool TLVObject::Read(std::monostate &value, const TLVHead &head)
134 {
135     return true;
136 }
137 
Write(TAG tag, const void *value)138 bool TLVObject::Write(TAG tag, const void *value)
139 {
140     return true;
141 }
142 
143 
Read(void *value, const TLVHead &head)144 bool TLVObject::Read(void *value, const TLVHead &head)
145 {
146     return true;
147 }
148 
CountHead()149 size_t TLVObject::CountHead()
150 {
151     return true;
152 }
153 
WriteHead(uint16_t type, uint32_t len)154 bool TLVObject::WriteHead(uint16_t type, uint32_t len)
155 {
156     return true;
157 }
158 
WriteBackHead(uint16_t tag, size_t tagCursor, uint32_t len)159 bool TLVObject::WriteBackHead(uint16_t tag, size_t tagCursor, uint32_t len)
160 {
161     return true;
162 }
163 
ReadHead(TLVHead &head)164 bool TLVObject::ReadHead(TLVHead &head)
165 {
166     return true;
167 }
168 
Skip(TLVHead &head)169 bool TLVObject::Skip(TLVHead &head)
170 {
171     return true;
172 }
173 
HasExpectBuffer(const uint32_t expectLen) const174 bool TLVObject::HasExpectBuffer(const uint32_t expectLen) const
175 {
176     return true;
177 }
178 
PrepareBufferForFile(size_t size)179 void TLVObject::PrepareBufferForFile(size_t size) { }
180 
GetStartCursor()181 std::uint8_t *TLVObject::GetStartCursor()
182 {
183     return 0;
184 }
185 
SaveBufferToFile()186 bool TLVObject::SaveBufferToFile()
187 {
188     return true;
189 }
190 
SaveBufferToFileFront(size_t tagCursor, uint32_t len)191 bool TLVObject::SaveBufferToFileFront(size_t tagCursor, uint32_t len)
192 {
193     return true;
194 }
195 
LoadBufferFormFile(size_t size)196 bool TLVObject::LoadBufferFormFile(size_t size)
197 {
198     return true;
199 }
200 } // namespace UDMF
201 } // namespace OHOS
202