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) << "The size field for the body has already been assigned.";
26 }
27 size_field_ = size_field;
28 }
29
GetFieldType() const30 const std::string& BodyField::GetFieldType() const {
31 return BodyField::kFieldType;
32 }
33
GetSize() const34 Size BodyField::GetSize() const {
35 if (size_field_ == nullptr) {
36 return Size(0);
37 }
38 std::string dynamic_size = "(" + size_field_->GetName() + " * 8)";
39 return dynamic_size;
40 }
41
GetDataType() const42 std::string BodyField::GetDataType() const {
43 ERROR(this) << "No need to know the type of a body field.";
44 return "BodyType";
45 }
46
GenExtractor(std::ostream &,int,bool) const47 void BodyField::GenExtractor(std::ostream&, int, bool) const {}
48
GetGetterFunctionName() const49 std::string BodyField::GetGetterFunctionName() const {
50 return "";
51 }
52
GenGetter(std::ostream &,Size,Size) const53 void BodyField::GenGetter(std::ostream&, Size, Size) const {}
54
GetBuilderParameterType() const55 std::string BodyField::GetBuilderParameterType() const {
56 return "";
57 }
58
HasParameterValidator() const59 bool BodyField::HasParameterValidator() const {
60 return false;
61 }
62
GenParameterValidator(std::ostream &) const63 void BodyField::GenParameterValidator(std::ostream&) const {
64 // There is no validation needed for a payload
65 }
66
GenInserter(std::ostream &) const67 void BodyField::GenInserter(std::ostream&) const {
68 // Do nothing
69 }
70
GenValidator(std::ostream &) const71 void BodyField::GenValidator(std::ostream&) const {
72 // Do nothing
73 }
74
GenStringRepresentation(std::ostream & s,std::string accessor) const75 void BodyField::GenStringRepresentation(std::ostream& s, std::string accessor) const {
76 s << "\"BODY REPRESENTATION_UNIMPLEMENTED " << accessor << " \"";
77 }
78
GetRustDataType() const79 std::string BodyField::GetRustDataType() const {
80 return GetDataType();
81 }
82
GenRustGetter(std::ostream &,Size,Size) const83 void BodyField::GenRustGetter(std::ostream&, Size, Size) const {
84 }
85
GenRustWriter(std::ostream &,Size,Size) const86 void BodyField::GenRustWriter(std::ostream&, Size, Size) const {}
87