• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022 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 "assemblyRecordProto.h"
17 
18 namespace panda::proto {
Serialize(const panda::pandasm::Record & record,protoPanda::Record & protoRecord)19 void Record::Serialize(const panda::pandasm::Record &record, protoPanda::Record &protoRecord)
20 {
21     protoRecord.set_name(record.name);
22     protoRecord.set_conflict(record.conflict);
23     protoRecord.set_language(static_cast<uint32_t>(record.language));
24     auto *proto_record_meta = protoRecord.mutable_metadata();
25     RecordMetadata::Serialize(*record.metadata, *proto_record_meta);
26 
27     for (const auto &field : record.field_list) {
28         auto *proto_field = protoRecord.add_fieldlist();
29         Field::Serialize(field, *proto_field);
30     }
31 
32     protoRecord.set_paramsnum(record.params_num);
33     protoRecord.set_bodypresence(record.body_presence);
34     protoRecord.set_sourcefile(record.source_file);
35 
36     const auto &location = record.file_location;
37     if (location.has_value()) {
38         auto *proto_location = protoRecord.mutable_filelocation();
39         FileLocation::Serialize(location.value(), *proto_location);
40     }
41 }
42 
Deserialize(const protoPanda::Record & protoRecord,panda::pandasm::Record & record,panda::ArenaAllocator * allocator)43 void Record::Deserialize(const protoPanda::Record &protoRecord, panda::pandasm::Record &record,
44                          panda::ArenaAllocator *allocator)
45 {
46     record.conflict = protoRecord.conflict();
47     RecordMetadata::Deserialize(protoRecord.metadata(), record.metadata, allocator);
48     record.field_list.reserve(protoRecord.fieldlist_size());
49     for (const auto &protoField : protoRecord.fieldlist()) {
50         auto recordField = panda::pandasm::Field(panda::panda_file::SourceLang::ECMASCRIPT);
51         Field::Deserialize(protoField, recordField, allocator);
52         record.field_list.emplace_back(std::move(recordField));
53     }
54     record.params_num = protoRecord.paramsnum();
55     record.body_presence = protoRecord.bodypresence();
56     record.source_file = protoRecord.sourcefile();
57     if (protoRecord.has_filelocation()) {
58         const auto &protoLocation = protoRecord.filelocation();
59         FileLocation::Deserialize(protoLocation, record.file_location);
60     }
61 }
62 } // panda::proto
63