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/count_field.h"
18 
19 #include "util.h"
20 
21 const std::string CountField::kFieldType = "CountField";
22 
CountField(std::string name,int size,ParseLocation loc)23 CountField::CountField(std::string name, int size, ParseLocation loc)
24     : ScalarField(name + "_count", size, loc), sized_field_name_(name) {}
25 
GetFieldType() const26 const std::string& CountField::GetFieldType() const { return CountField::kFieldType; }
27 
GenGetter(std::ostream & s,Size start_offset,Size end_offset) const28 void CountField::GenGetter(std::ostream& s, Size start_offset, Size end_offset) const {
29   s << "protected:";
30   ScalarField::GenGetter(s, start_offset, end_offset);
31   s << "public:\n";
32 }
33 
GenBuilderParameter(std::ostream &) const34 bool CountField::GenBuilderParameter(std::ostream&) const {
35   // There is no builder parameter for a size field
36   return false;
37 }
38 
HasParameterValidator() const39 bool CountField::HasParameterValidator() const { return false; }
40 
GenParameterValidator(std::ostream &) const41 void CountField::GenParameterValidator(std::ostream&) const {
42   // There is no builder parameter for a size field
43   // TODO: Check if the payload fits in the packet?
44 }
45 
GenInserter(std::ostream &) const46 void CountField::GenInserter(std::ostream&) const {
47   ERROR(this) << __func__ << ": This should not be called for count fields";
48 }
49 
GenValidator(std::ostream &) const50 void CountField::GenValidator(std::ostream&) const {
51   // Do nothing since the fixed count fields will be handled specially.
52 }
53 
GetSizedFieldName() const54 std::string CountField::GetSizedFieldName() const { return sized_field_name_; }
55