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/body_field.h"
18 
19 const std::string BodyField::kFieldType = "BodyField";
20 
BodyField(ParseLocation loc)21 BodyField::BodyField(ParseLocation loc) : PacketField("body", loc) {}
22 
SetSizeField(const SizeField * size_field)23 void BodyField::SetSizeField(const SizeField* size_field) {
24   if (size_field_ != nullptr) {
25     ERROR(this, size_field_, size_field)
26             << "The size field for the body has already been assigned.";
27   }
28   size_field_ = size_field;
29 }
30 
GetFieldType() const31 const std::string& BodyField::GetFieldType() const { return BodyField::kFieldType; }
32 
GetSize() const33 Size BodyField::GetSize() const {
34   if (size_field_ == nullptr) {
35     return Size(0);
36   }
37   std::string dynamic_size = "(" + size_field_->GetName() + " * 8)";
38   return dynamic_size;
39 }
40 
GetDataType() const41 std::string BodyField::GetDataType() const {
42   ERROR(this) << "No need to know the type of a body field.";
43   return "BodyType";
44 }
45 
GenExtractor(std::ostream &,int,bool) const46 void BodyField::GenExtractor(std::ostream&, int, bool) const {}
47 
GetGetterFunctionName() const48 std::string BodyField::GetGetterFunctionName() const { return ""; }
49 
GenGetter(std::ostream &,Size,Size) const50 void BodyField::GenGetter(std::ostream&, Size, Size) const {}
51 
GetBuilderParameterType() const52 std::string BodyField::GetBuilderParameterType() const { return ""; }
53 
HasParameterValidator() const54 bool BodyField::HasParameterValidator() const { return false; }
55 
GenParameterValidator(std::ostream &) const56 void BodyField::GenParameterValidator(std::ostream&) const {
57   // There is no validation needed for a payload
58 }
59 
GenInserter(std::ostream &) const60 void BodyField::GenInserter(std::ostream&) const {
61   // Do nothing
62 }
63 
GenValidator(std::ostream &) const64 void BodyField::GenValidator(std::ostream&) const {
65   // Do nothing
66 }
67 
GenStringRepresentation(std::ostream & s,std::string accessor) const68 void BodyField::GenStringRepresentation(std::ostream& s, std::string accessor) const {
69   s << "\"BODY REPRESENTATION_UNIMPLEMENTED " << accessor << " \"";
70 }
71