• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "box_base.h"
17 #include "ans_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace Notification {
21 namespace {
22 const int32_t CURRENT_VERSION = 1000;
23 }
BoxBase()24 BoxBase::BoxBase()
25 {
26     box_ = std::make_shared<TlvBox>();
27     if (box_ == nullptr) {
28         ANS_LOGW("Create tlv box failed.");
29         return;
30     }
31 }
32 
BoxBase(std::shared_ptr<TlvBox> box)33 BoxBase::BoxBase(std::shared_ptr<TlvBox> box)
34 {
35     box_ = box;
36 }
37 
GetByteBuffer()38 unsigned char* BoxBase::GetByteBuffer()
39 {
40     return box_->byteBuffer_;
41 }
42 
GetByteLength()43 uint32_t BoxBase::GetByteLength()
44 {
45     return box_->bytesLength_;
46 }
47 
Serialize()48 bool BoxBase::Serialize()
49 {
50     if (box_ == nullptr) {
51         return false;
52     }
53     box_->PutValue(std::make_shared<TlvItem>(LOCAL_VERSION, CURRENT_VERSION));
54     return box_->Serialize();
55 }
56 }
57 }
58