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/size_field.h"
18
19 #include "util.h"
20
21 const std::string SizeField::kFieldType = "SizeField";
22
SizeField(std::string name,int size,ParseLocation loc)23 SizeField::SizeField(std::string name, int size, ParseLocation loc)
24 : ScalarField(name + "_size", size, loc), sized_field_name_(name) {}
25
GetFieldType() const26 const std::string& SizeField::GetFieldType() const { return SizeField::kFieldType; }
27
GenGetter(std::ostream & s,Size start_offset,Size end_offset) const28 void SizeField::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
GetBuilderParameterType() const34 std::string SizeField::GetBuilderParameterType() const { return ""; }
35
GenBuilderParameter(std::ostream &) const36 bool SizeField::GenBuilderParameter(std::ostream&) const {
37 // There is no builder parameter for a size field
38 return false;
39 }
40
HasParameterValidator() const41 bool SizeField::HasParameterValidator() const { return false; }
42
GenParameterValidator(std::ostream &) const43 void SizeField::GenParameterValidator(std::ostream&) const {
44 // There is no builder parameter for a size field
45 // TODO: Check if the payload fits in the packet?
46 }
47
GenInserter(std::ostream &) const48 void SizeField::GenInserter(std::ostream&) const {
49 ERROR(this) << __func__ << ": This should not be called for size fields";
50 }
51
GenValidator(std::ostream &) const52 void SizeField::GenValidator(std::ostream&) const {
53 // Do nothing since the fixed size fields will be handled specially.
54 }
55
GetSizedFieldName() const56 std::string SizeField::GetSizedFieldName() const { return sized_field_name_; }
57
GenStringRepresentation(std::ostream & s,std::string accessor) const58 void SizeField::GenStringRepresentation(std::ostream& s, std::string accessor) const {
59 s << accessor;
60 }
61