• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "util.h"
19 
20 const std::string SizeField::kFieldType = "SizeField";
21 
SizeField(std::string name,int size,ParseLocation loc)22 SizeField::SizeField(std::string name, int size, ParseLocation loc)
23     : ScalarField(name + "_size", size, loc), sized_field_name_(name) {}
24 
GetFieldType() const25 const std::string& SizeField::GetFieldType() const {
26   return SizeField::kFieldType;
27 }
28 
GenGetter(std::ostream & s,Size start_offset,Size end_offset) const29 void SizeField::GenGetter(std::ostream& s, Size start_offset, Size end_offset) const {
30   s << "protected:";
31   ScalarField::GenGetter(s, start_offset, end_offset);
32   s << "public:\n";
33 }
34 
GetBuilderParameterType() const35 std::string SizeField::GetBuilderParameterType() const {
36   return "";
37 }
38 
GenBuilderParameter(std::ostream &) const39 bool SizeField::GenBuilderParameter(std::ostream&) const {
40   // There is no builder parameter for a size field
41   return false;
42 }
43 
HasParameterValidator() const44 bool SizeField::HasParameterValidator() const {
45   return false;
46 }
47 
GenParameterValidator(std::ostream &) const48 void SizeField::GenParameterValidator(std::ostream&) const {
49   // There is no builder parameter for a size field
50   // TODO: Check if the payload fits in the packet?
51 }
52 
GenInserter(std::ostream &) const53 void SizeField::GenInserter(std::ostream&) const {
54   ERROR(this) << __func__ << ": This should not be called for size fields";
55 }
56 
GenValidator(std::ostream &) const57 void SizeField::GenValidator(std::ostream&) const {
58   // Do nothing since the fixed size fields will be handled specially.
59 }
60 
GetSizedFieldName() const61 std::string SizeField::GetSizedFieldName() const {
62   return sized_field_name_;
63 }
64 
GenStringRepresentation(std::ostream & s,std::string accessor) const65 void SizeField::GenStringRepresentation(std::ostream& s, std::string accessor) const {
66   s << accessor;
67 }
68