1 /*
2 * Copyright 2019 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include "fields/reserved_field.h"
18 #include "util.h"
19
20 int ReservedField::unique_id_ = 0;
21
22 const std::string ReservedField::kFieldType = "ReservedField";
23
ReservedField(int size,ParseLocation loc)24 ReservedField::ReservedField(int size, ParseLocation loc)
25 : PacketField("ReservedScalar" + std::to_string(unique_id_++), loc), size_(size) {}
26
GetFieldType() const27 const std::string& ReservedField::GetFieldType() const {
28 return ReservedField::kFieldType;
29 }
30
GetSize() const31 Size ReservedField::GetSize() const {
32 return size_;
33 }
34
GetDataType() const35 std::string ReservedField::GetDataType() const {
36 return util::GetTypeForSize(size_);
37 }
38
GenExtractor(std::ostream &,int,bool) const39 void ReservedField::GenExtractor(std::ostream&, int, bool) const {}
40
GetGetterFunctionName() const41 std::string ReservedField::GetGetterFunctionName() const {
42 return "";
43 }
44
GenGetter(std::ostream &,Size,Size) const45 void ReservedField::GenGetter(std::ostream&, Size, Size) const {
46 // There is no Getter for a reserved field
47 }
48
GetBuilderParameterType() const49 std::string ReservedField::GetBuilderParameterType() const {
50 // There is no builder parameter for a reserved field
51 return "";
52 }
53
HasParameterValidator() const54 bool ReservedField::HasParameterValidator() const {
55 return false;
56 }
57
GenParameterValidator(std::ostream &) const58 void ReservedField::GenParameterValidator(std::ostream&) const {
59 // There is no builder parameter for a reserved field
60 }
61
GenInserter(std::ostream & s) const62 void ReservedField::GenInserter(std::ostream& s) const {
63 s << "insert(static_cast<" << util::GetTypeForSize(GetSize().bits()) << ">(0) /* Reserved */, i, " << GetSize().bits()
64 << " );\n";
65 }
66
GenValidator(std::ostream &) const67 void ReservedField::GenValidator(std::ostream&) const {
68 // There is no need to validate the value of a reserved field
69 }
70
GetRustDataType() const71 std::string ReservedField::GetRustDataType() const {
72 return util::GetRustTypeForSize(size_);
73 }
74
GenRustGetter(std::ostream &,Size,Size) const75 void ReservedField::GenRustGetter(std::ostream&, Size, Size) const {
76 }
77
GenRustWriter(std::ostream &,Size,Size) const78 void ReservedField::GenRustWriter(std::ostream&, Size, Size) const {}
79