1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#include "net_packet.h"
17c29fa5a6Sopenharmony_ci
18c29fa5a6Sopenharmony_ci#include "mmi_log.h"
19c29fa5a6Sopenharmony_ci
20c29fa5a6Sopenharmony_cinamespace OHOS {
21c29fa5a6Sopenharmony_cinamespace MMI {
22c29fa5a6Sopenharmony_ciNetPacket::NetPacket(MmiMessageId msgId) : msgId_(msgId) {}
23c29fa5a6Sopenharmony_ci
24c29fa5a6Sopenharmony_ciNetPacket::NetPacket(const NetPacket &pkt) : NetPacket(pkt.GetMsgId())
25c29fa5a6Sopenharmony_ci{
26c29fa5a6Sopenharmony_ci    Clone(pkt);
27c29fa5a6Sopenharmony_ci}
28c29fa5a6Sopenharmony_ciNetPacket::~NetPacket() {}
29c29fa5a6Sopenharmony_ci
30c29fa5a6Sopenharmony_civoid NetPacket::MakeData(StreamBuffer &buf) const
31c29fa5a6Sopenharmony_ci{
32c29fa5a6Sopenharmony_ci    PACKHEAD head = { msgId_, wPos_ };
33c29fa5a6Sopenharmony_ci    buf << head;
34c29fa5a6Sopenharmony_ci    if (wPos_ > 0) {
35c29fa5a6Sopenharmony_ci        if (!buf.Write(&szBuff_[0], wPos_)) {
36c29fa5a6Sopenharmony_ci            MMI_HILOGE("Write data to stream failed, errCode:%{public}d", STREAM_BUF_WRITE_FAIL);
37c29fa5a6Sopenharmony_ci            return;
38c29fa5a6Sopenharmony_ci        }
39c29fa5a6Sopenharmony_ci    }
40c29fa5a6Sopenharmony_ci}
41c29fa5a6Sopenharmony_ci} // namespace MMI
42c29fa5a6Sopenharmony_ci} // namespace OHOS
43