@@ -66,7 +66,7 @@ using ::pdpi::Format;
66
66
using ::pdpi::IrValue;
67
67
68
68
absl::StatusOr<std::string> ArbitraryToNormalizedByteString (
69
- const std::string & bytes, int expected_bitwidth) {
69
+ const std::string& bytes, int expected_bitwidth) {
70
70
// If the bytestring length is zero, the server always rejects the string.
71
71
// https://p4.org/p4-spec/p4runtime/main/P4Runtime-Spec.html#sec-bytestrings
72
72
if (bytes.empty ()) {
@@ -87,15 +87,15 @@ absl::StatusOr<std::string> ArbitraryToNormalizedByteString(
87
87
canonical_string);
88
88
}
89
89
90
- absl::StatusOr<uint64_t > ArbitraryByteStringToUint (const std::string & bytes,
90
+ absl::StatusOr<uint64_t > ArbitraryByteStringToUint (const std::string& bytes,
91
91
int bitwidth) {
92
92
if (bitwidth > 64 ) {
93
93
return absl::Status (absl::StatusCode::kInvalidArgument ,
94
94
absl::StrCat (" Cannot convert value with "
95
95
" bitwidth " ,
96
96
bitwidth, " to uint." ));
97
97
}
98
- ASSIGN_OR_RETURN (const auto & stripped_value,
98
+ ASSIGN_OR_RETURN (const auto & stripped_value,
99
99
ArbitraryToNormalizedByteString (bytes, bitwidth));
100
100
uint64_t nb_value; // network byte order
101
101
char value[sizeof (nb_value)];
@@ -121,19 +121,19 @@ absl::StatusOr<std::string> UintToNormalizedByteString(uint64_t value,
121
121
std::string bytes = " " ;
122
122
if (bitwidth <= 8 ) {
123
123
uint8_t tmp = static_cast <uint8_t >(value);
124
- bytes.assign (reinterpret_cast <char *>(&tmp), sizeof (uint8_t ));
124
+ bytes.assign (reinterpret_cast <char *>(&tmp), sizeof (uint8_t ));
125
125
} else if (bitwidth <= 16 ) {
126
126
uint16_t tmp = htons (static_cast <uint16_t >(value));
127
- bytes.assign (reinterpret_cast <char *>(&tmp), sizeof (uint16_t ));
127
+ bytes.assign (reinterpret_cast <char *>(&tmp), sizeof (uint16_t ));
128
128
} else if (bitwidth <= 32 ) {
129
129
uint32_t tmp = htonl (static_cast <uint32_t >(value));
130
- bytes.assign (reinterpret_cast <char *>(&tmp), sizeof (uint32_t ));
130
+ bytes.assign (reinterpret_cast <char *>(&tmp), sizeof (uint32_t ));
131
131
} else {
132
132
uint64_t tmp =
133
133
(htonl (1 ) == 1 )
134
134
? value
135
135
: (static_cast <uint64_t >(htonl (value)) << 32 ) | htonl (value >> 32 );
136
- bytes.assign (reinterpret_cast <char *>(&tmp), sizeof (uint64_t ));
136
+ bytes.assign (reinterpret_cast <char *>(&tmp), sizeof (uint64_t ));
137
137
}
138
138
139
139
ASSIGN_OR_RETURN (auto normalized_str,
@@ -148,13 +148,13 @@ std::string ArbitraryToCanonicalByteString(std::string bytes) {
148
148
return bytes;
149
149
}
150
150
151
- absl::StatusOr<Format> GetFormat (const std::vector<std::string> & annotations,
151
+ absl::StatusOr<Format> GetFormat (const std::vector<std::string>& annotations,
152
152
const int bitwidth, bool is_sdn_string) {
153
153
Format format = Format::HEX_STRING;
154
154
if (is_sdn_string) {
155
155
format = Format::STRING;
156
156
}
157
- for (const std::string & annotation : annotations) {
157
+ for (const std::string& annotation : annotations) {
158
158
if (absl::StartsWith (annotation, " @format(" )) {
159
159
if (format != Format::HEX_STRING) {
160
160
return gutil::InvalidArgumentErrorBuilder ()
@@ -189,7 +189,7 @@ absl::StatusOr<Format> GetFormat(const std::vector<std::string> &annotations,
189
189
190
190
absl::StatusOr<IrValue> ArbitraryByteStringToIrValue (Format format,
191
191
const int bitwidth,
192
- const std::string & bytes) {
192
+ const std::string& bytes) {
193
193
// If the bytestring length is zero, the server always rejects the string.
194
194
// https://p4.org/p4-spec/p4runtime/main/P4Runtime-Spec.html#sec-bytestrings
195
195
if (bytes.empty ()) {
@@ -247,9 +247,9 @@ absl::StatusOr<IrValue> ArbitraryByteStringToIrValue(Format format,
247
247
}
248
248
}
249
249
250
- absl::Status ValidateIrValueFormat (const IrValue & ir_value, Format format,
251
- const TranslationOptions & options) {
252
- const auto & format_case = ir_value.format_case ();
250
+ absl::Status ValidateIrValueFormat (const IrValue& ir_value, Format format,
251
+ const TranslationOptions& options) {
252
+ const auto & format_case = ir_value.format_case ();
253
253
ASSIGN_OR_RETURN (const std::string format_case_name,
254
254
gutil::GetOneOfFieldName (ir_value, std::string (" format" )));
255
255
switch (format) {
@@ -307,7 +307,7 @@ absl::Status ValidateIrValueFormat(const IrValue &ir_value, Format format,
307
307
}
308
308
309
309
absl::StatusOr<std::string> IrValueToNormalizedByteString (
310
- const IrValue & ir_value, const int bitwidth) {
310
+ const IrValue& ir_value, const int bitwidth) {
311
311
switch (ir_value.format_case ()) {
312
312
case IrValue::kMac : {
313
313
ASSIGN_OR_RETURN (MacAddress mac, MacAddress::OfString (ir_value.mac ()));
@@ -341,7 +341,7 @@ absl::StatusOr<std::string> IrValueToNormalizedByteString(
341
341
break ;
342
342
}
343
343
case IrValue::kHexStr : {
344
- const std::string & hex_str = ir_value.hex_str ();
344
+ const std::string& hex_str = ir_value.hex_str ();
345
345
const int expected_num_hex_chars =
346
346
bitwidth / 4 + (bitwidth % 4 != 0 ? 1 : 0 );
347
347
if (!absl::StartsWith (hex_str, " 0x" )) {
@@ -377,7 +377,7 @@ absl::StatusOr<std::string> IrValueToNormalizedByteString(
377
377
<< " Uninitialized value: " << ir_value.DebugString ();
378
378
}
379
379
380
- absl::StatusOr<IrValue> FormattedStringToIrValue (const std::string & value,
380
+ absl::StatusOr<IrValue> FormattedStringToIrValue (const std::string& value,
381
381
Format format) {
382
382
IrValue result;
383
383
switch (format) {
@@ -403,7 +403,7 @@ absl::StatusOr<IrValue> FormattedStringToIrValue(const std::string &value,
403
403
return result;
404
404
}
405
405
406
- std::string IrValueString (const IrValue & value) {
406
+ std::string IrValueString (const IrValue& value) {
407
407
switch (value.format_case ()) {
408
408
case IrValue::FormatCase::kMac :
409
409
return value.mac ();
@@ -421,9 +421,9 @@ std::string IrValueString(const IrValue &value) {
421
421
return " " ;
422
422
}
423
423
424
- bool IsAllZeros (const std::string & s) {
424
+ bool IsAllZeros (const std::string& s) {
425
425
bool has_non_zero_value = false ;
426
- for (const auto & c : s) {
426
+ for (const auto & c : s) {
427
427
if (c != ' \x00 ' ) {
428
428
has_non_zero_value = true ;
429
429
break ;
@@ -433,8 +433,8 @@ bool IsAllZeros(const std::string &s) {
433
433
return has_non_zero_value == false ;
434
434
}
435
435
436
- absl::StatusOr<std::string> Intersection (const std::string & left,
437
- const std::string & right) {
436
+ absl::StatusOr<std::string> Intersection (const std::string& left,
437
+ const std::string& right) {
438
438
if (left.size () != right.size ()) {
439
439
return gutil::InvalidArgumentErrorBuilder ()
440
440
<< " Cannot find intersection. '" << absl::CEscape (left) << " '("
@@ -488,7 +488,7 @@ absl::Status IsGoogleRpcCode(int rpc_code) {
488
488
}
489
489
490
490
absl::Status ValidateGenericUpdateStatus (google::rpc::Code code,
491
- const std::string & message) {
491
+ const std::string& message) {
492
492
if (code == google::rpc::OK && !message.empty ()) {
493
493
return absl::InvalidArgumentError (
494
494
" OK status should not contain error message." );
@@ -497,11 +497,11 @@ absl::Status ValidateGenericUpdateStatus(google::rpc::Code code,
497
497
}
498
498
499
499
std::string IrWriteResponseToReadableMessage (
500
- const IrWriteResponse & ir_write_response) {
500
+ const IrWriteResponse& ir_write_response) {
501
501
std::string readable_message;
502
502
absl::StrAppend (&readable_message, " Batch failed, individual results:\n " );
503
503
int i = 1 ;
504
- for (const auto & ir_update_status : ir_write_response.statuses ()) {
504
+ for (const auto & ir_update_status : ir_write_response.statuses ()) {
505
505
absl::StrAppend (&readable_message, " #" , i, " : " ,
506
506
absl::StatusCodeToString (static_cast <absl::StatusCode>(
507
507
ir_update_status.code ())));
@@ -559,7 +559,7 @@ std::string MetadataName(absl::string_view metadata_name) {
559
559
}
560
560
561
561
bool IsElementDeprecated (
562
- const google::protobuf::RepeatedPtrField<std::string> & annotations) {
562
+ const google::protobuf::RepeatedPtrField<std::string>& annotations) {
563
563
return absl::c_any_of (annotations, [](absl::string_view annotation) {
564
564
return absl::StartsWith (annotation, " @deprecated" );
565
565
});
@@ -568,7 +568,7 @@ bool IsElementDeprecated(
568
568
namespace {
569
569
// Compress and return a match field into a unique, descriptive short-form
570
570
// string.
571
- std::string MatchFieldShortDescription (const IrMatch & match) {
571
+ std::string MatchFieldShortDescription (const IrMatch& match) {
572
572
switch (match.match_value_case ()) {
573
573
case IrMatch::MatchValueCase::kExact :
574
574
return absl::Substitute (" $0=$1" , match.name (),
@@ -592,10 +592,10 @@ std::string MatchFieldShortDescription(const IrMatch &match) {
592
592
593
593
// Compress and return an action invocation into a unique, descriptive
594
594
// short-form string.
595
- std::string ActionInvocationShortDescription (const IrActionInvocation & action) {
595
+ std::string ActionInvocationShortDescription (const IrActionInvocation& action) {
596
596
if (action.params ().empty ()) return action.name ();
597
597
absl::btree_set<std::string> action_params;
598
- for (const IrActionInvocation::IrActionParam & param : action.params ()) {
598
+ for (const IrActionInvocation::IrActionParam& param : action.params ()) {
599
599
action_params.insert (
600
600
absl::Substitute (" $0=$1" , param.name (), IrValueString (param.value ())));
601
601
}
@@ -605,9 +605,9 @@ std::string ActionInvocationShortDescription(const IrActionInvocation &action) {
605
605
606
606
// Compress and return an action set into a unique, descriptive short-form
607
607
// string.
608
- std::string ActionSetShortDescription (const IrActionSet & action_set) {
608
+ std::string ActionSetShortDescription (const IrActionSet& action_set) {
609
609
absl::btree_set<std::string> actions;
610
- for (const IrActionSetInvocation & invocation : action_set.actions ()) {
610
+ for (const IrActionSetInvocation& invocation : action_set.actions ()) {
611
611
actions.insert (absl::Substitute (
612
612
" $0$1[$2]" ,
613
613
invocation.watch_port ().empty ()
@@ -620,9 +620,9 @@ std::string ActionSetShortDescription(const IrActionSet &action_set) {
620
620
}
621
621
} // namespace
622
622
623
- std::string ShortDescription (const IrTableEntry & entry) {
623
+ std::string ShortDescription (const IrTableEntry& entry) {
624
624
absl::btree_set<std::string> match_fields;
625
- for (const IrMatch & match : entry.matches ()) {
625
+ for (const IrMatch& match : entry.matches ()) {
626
626
match_fields.insert (MatchFieldShortDescription (match));
627
627
}
628
628
0 commit comments