1// GENERATED FILE - DO NOT MODIFY
2
3#include <algorithm>
4
5#include "tensorflow/core/framework/attr_value.pb_text-impl.h"
6
7using ::tensorflow::strings::ProtoSpaceAndComments;
8using ::tensorflow::strings::Scanner;
9using ::tensorflow::strings::StrCat;
10
11namespace tensorflow {
12
13string ProtoDebugString(
14 const ::tensorflow::AttrValue_ListValue& msg) {
15 string s;
16 ::tensorflow::strings::ProtoTextOutput o(&s, false);
17 internal::AppendProtoDebugString(&o, msg);
18 o.CloseTopMessage();
19 return s;
20}
21
22string ProtoShortDebugString(
23 const ::tensorflow::AttrValue_ListValue& msg) {
24 string s;
25 ::tensorflow::strings::ProtoTextOutput o(&s, true);
26 internal::AppendProtoDebugString(&o, msg);
27 o.CloseTopMessage();
28 return s;
29}
30
31namespace internal {
32
33void AppendProtoDebugString(
34 ::tensorflow::strings::ProtoTextOutput* o,
35 const ::tensorflow::AttrValue_ListValue& msg) {
36 for (int i = 0; i < msg.s_size(); ++i) {
37 o->AppendString("s", ProtobufStringToString(msg.s(i)));
38 }
39 for (int i = 0; i < msg.i_size(); ++i) {
40 o->AppendNumeric("i", msg.i(i));
41 }
42 for (int i = 0; i < msg.f_size(); ++i) {
43 o->AppendNumeric("f", msg.f(i));
44 }
45 for (int i = 0; i < msg.b_size(); ++i) {
46 o->AppendBool("b", msg.b(i));
47 }
48 for (int i = 0; i < msg.type_size(); ++i) {
49 const char* enum_name = ::tensorflow::EnumName_DataType(msg.type(i));
50 if (enum_name[0]) {
51 o->AppendEnumName("type", enum_name);
52 } else {
53 o->AppendNumeric("type", msg.type(i));
54 }
55 }
56 for (int i = 0; i < msg.shape_size(); ++i) {
57 o->OpenNestedMessage("shape");
58 ::tensorflow::internal::AppendProtoDebugString(o, msg.shape(i));
59 o->CloseNestedMessage();
60 }
61 for (int i = 0; i < msg.tensor_size(); ++i) {
62 o->OpenNestedMessage("tensor");
63 ::tensorflow::internal::AppendProtoDebugString(o, msg.tensor(i));
64 o->CloseNestedMessage();
65 }
66 for (int i = 0; i < msg.func_size(); ++i) {
67 o->OpenNestedMessage("func");
68 ::tensorflow::internal::AppendProtoDebugString(o, msg.func(i));
69 o->CloseNestedMessage();
70 }
71}
72
73} // namespace internal
74
75bool ProtoParseFromString(
76 const string& s,
77 ::tensorflow::AttrValue_ListValue* msg) {
78 msg->Clear();
79 Scanner scanner(s);
80 if (!internal::ProtoParseFromScanner(&scanner, false, false, msg)) return false;
81 scanner.Eos();
82 return scanner.GetResult();
83}
84
85namespace internal {
86
87bool ProtoParseFromScanner(
88 ::tensorflow::strings::Scanner* scanner, bool nested, bool close_curly,
89 ::tensorflow::AttrValue_ListValue* msg) {
90 std::vector<bool> has_seen(8, false);
91 while(true) {
92 ProtoSpaceAndComments(scanner);
93 if (nested && (scanner->Peek() == (close_curly ? '}' : '>'))) {
94 scanner->One(Scanner::ALL);
95 ProtoSpaceAndComments(scanner);
96 return true;
97 }
98 if (!nested && scanner->empty()) { return true; }
99 scanner->RestartCapture()
100 .Many(Scanner::LETTER_DIGIT_UNDERSCORE)
101 .StopCapture();
102 StringPiece identifier;
103 if (!scanner->GetResult(nullptr, &identifier)) return false;
104 bool parsed_colon = false;
105 (void)parsed_colon;
106 ProtoSpaceAndComments(scanner);
107 if (scanner->Peek() == ':') {
108 parsed_colon = true;
109 scanner->One(Scanner::ALL);
110 ProtoSpaceAndComments(scanner);
111 }
112 if (identifier == "s") {
113 const bool is_list = (scanner->Peek() == '[');
114 do {
115 if (is_list) {
116 scanner->One(Scanner::ALL);
117 ProtoSpaceAndComments(scanner);
118 }
119 string str_value;
120 if (!parsed_colon || !::tensorflow::strings::ProtoParseStringLiteralFromScanner(
121 scanner, &str_value)) return false;
122 SetProtobufStringSwapAllowed(&str_value, msg->add_s());
123 } while (is_list && scanner->Peek() == ',');
124 if (is_list && !scanner->OneLiteral("]").GetResult()) return false;
125 }
126 else if (identifier == "i") {
127 const bool is_list = (scanner->Peek() == '[');
128 do {
129 if (is_list) {
130 scanner->One(Scanner::ALL);
131 ProtoSpaceAndComments(scanner);
132 }
133 int64 value;
134 if (!parsed_colon || !::tensorflow::strings::ProtoParseNumericFromScanner(scanner, &value)) return false;
135 msg->add_i(value);
136 } while (is_list && scanner->Peek() == ',');
137 if (is_list && !scanner->OneLiteral("]").GetResult()) return false;
138 }
139 else if (identifier == "f") {
140 const bool is_list = (scanner->Peek() == '[');
141 do {
142 if (is_list) {
143 scanner->One(Scanner::ALL);
144 ProtoSpaceAndComments(scanner);
145 }
146 float value;
147 if (!parsed_colon || !::tensorflow::strings::ProtoParseNumericFromScanner(scanner, &value)) return false;
148 msg->add_f(value);
149 } while (is_list && scanner->Peek() == ',');
150 if (is_list && !scanner->OneLiteral("]").GetResult()) return false;
151 }
152 else if (identifier == "b") {
153 const bool is_list = (scanner->Peek() == '[');
154 do {
155 if (is_list) {
156 scanner->One(Scanner::ALL);
157 ProtoSpaceAndComments(scanner);
158 }
159 bool value;
160 if (!parsed_colon || !::tensorflow::strings::ProtoParseBoolFromScanner(scanner, &value)) return false;
161 msg->add_b(value);
162 } while (is_list && scanner->Peek() == ',');
163 if (is_list && !scanner->OneLiteral("]").GetResult()) return false;
164 }
165 else if (identifier == "type") {
166 const bool is_list = (scanner->Peek() == '[');
167 do {
168 if (is_list) {
169 scanner->One(Scanner::ALL);
170 ProtoSpaceAndComments(scanner);
171 }
172 StringPiece value;
173 if (!parsed_colon || !scanner->RestartCapture().Many(Scanner::LETTER_DIGIT_DASH_UNDERSCORE).GetResult(nullptr, &value)) return false;
174 if (value == "DT_INVALID") {
175 msg->add_type(::tensorflow::DT_INVALID);
176 } else if (value == "DT_FLOAT") {
177 msg->add_type(::tensorflow::DT_FLOAT);
178 } else if (value == "DT_DOUBLE") {
179 msg->add_type(::tensorflow::DT_DOUBLE);
180 } else if (value == "DT_INT32") {
181 msg->add_type(::tensorflow::DT_INT32);
182 } else if (value == "DT_UINT8") {
183 msg->add_type(::tensorflow::DT_UINT8);
184 } else if (value == "DT_INT16") {
185 msg->add_type(::tensorflow::DT_INT16);
186 } else if (value == "DT_INT8") {
187 msg->add_type(::tensorflow::DT_INT8);
188 } else if (value == "DT_STRING") {
189 msg->add_type(::tensorflow::DT_STRING);
190 } else if (value == "DT_COMPLEX64") {
191 msg->add_type(::tensorflow::DT_COMPLEX64);
192 } else if (value == "DT_INT64") {
193 msg->add_type(::tensorflow::DT_INT64);
194 } else if (value == "DT_BOOL") {
195 msg->add_type(::tensorflow::DT_BOOL);
196 } else if (value == "DT_QINT8") {
197 msg->add_type(::tensorflow::DT_QINT8);
198 } else if (value == "DT_QUINT8") {
199 msg->add_type(::tensorflow::DT_QUINT8);
200 } else if (value == "DT_QINT32") {
201 msg->add_type(::tensorflow::DT_QINT32);
202 } else if (value == "DT_BFLOAT16") {
203 msg->add_type(::tensorflow::DT_BFLOAT16);
204 } else if (value == "DT_QINT16") {
205 msg->add_type(::tensorflow::DT_QINT16);
206 } else if (value == "DT_QUINT16") {
207 msg->add_type(::tensorflow::DT_QUINT16);
208 } else if (value == "DT_UINT16") {
209 msg->add_type(::tensorflow::DT_UINT16);
210 } else if (value == "DT_COMPLEX128") {
211 msg->add_type(::tensorflow::DT_COMPLEX128);
212 } else if (value == "DT_HALF") {
213 msg->add_type(::tensorflow::DT_HALF);
214 } else if (value == "DT_RESOURCE") {
215 msg->add_type(::tensorflow::DT_RESOURCE);
216 } else if (value == "DT_VARIANT") {
217 msg->add_type(::tensorflow::DT_VARIANT);
218 } else if (value == "DT_UINT32") {
219 msg->add_type(::tensorflow::DT_UINT32);
220 } else if (value == "DT_UINT64") {
221 msg->add_type(::tensorflow::DT_UINT64);
222 } else if (value == "DT_FLOAT_REF") {
223 msg->add_type(::tensorflow::DT_FLOAT_REF);
224 } else if (value == "DT_DOUBLE_REF") {
225 msg->add_type(::tensorflow::DT_DOUBLE_REF);
226 } else if (value == "DT_INT32_REF") {
227 msg->add_type(::tensorflow::DT_INT32_REF);
228 } else if (value == "DT_UINT8_REF") {
229 msg->add_type(::tensorflow::DT_UINT8_REF);
230 } else if (value == "DT_INT16_REF") {
231 msg->add_type(::tensorflow::DT_INT16_REF);
232 } else if (value == "DT_INT8_REF") {
233 msg->add_type(::tensorflow::DT_INT8_REF);
234 } else if (value == "DT_STRING_REF") {
235 msg->add_type(::tensorflow::DT_STRING_REF);
236 } else if (value == "DT_COMPLEX64_REF") {
237 msg->add_type(::tensorflow::DT_COMPLEX64_REF);
238 } else if (value == "DT_INT64_REF") {
239 msg->add_type(::tensorflow::DT_INT64_REF);
240 } else if (value == "DT_BOOL_REF") {
241 msg->add_type(::tensorflow::DT_BOOL_REF);
242 } else if (value == "DT_QINT8_REF") {
243 msg->add_type(::tensorflow::DT_QINT8_REF);
244 } else if (value == "DT_QUINT8_REF") {
245 msg->add_type(::tensorflow::DT_QUINT8_REF);
246 } else if (value == "DT_QINT32_REF") {
247 msg->add_type(::tensorflow::DT_QINT32_REF);
248 } else if (value == "DT_BFLOAT16_REF") {
249 msg->add_type(::tensorflow::DT_BFLOAT16_REF);
250 } else if (value == "DT_QINT16_REF") {
251 msg->add_type(::tensorflow::DT_QINT16_REF);
252 } else if (value == "DT_QUINT16_REF") {
253 msg->add_type(::tensorflow::DT_QUINT16_REF);
254 } else if (value == "DT_UINT16_REF") {
255 msg->add_type(::tensorflow::DT_UINT16_REF);
256 } else if (value == "DT_COMPLEX128_REF") {
257 msg->add_type(::tensorflow::DT_COMPLEX128_REF);
258 } else if (value == "DT_HALF_REF") {
259 msg->add_type(::tensorflow::DT_HALF_REF);
260 } else if (value == "DT_RESOURCE_REF") {
261 msg->add_type(::tensorflow::DT_RESOURCE_REF);
262 } else if (value == "DT_VARIANT_REF") {
263 msg->add_type(::tensorflow::DT_VARIANT_REF);
264 } else if (value == "DT_UINT32_REF") {
265 msg->add_type(::tensorflow::DT_UINT32_REF);
266 } else if (value == "DT_UINT64_REF") {
267 msg->add_type(::tensorflow::DT_UINT64_REF);
268 } else {
269 int32 int_value;
270 if (strings::SafeStringToNumeric(value, &int_value)) {
271 msg->add_type(static_cast<::tensorflow::DataType>(int_value));
272 } else {
273 return false;
274 }
275 }
276 } while (is_list && scanner->Peek() == ',');
277 if (is_list && !scanner->OneLiteral("]").GetResult()) return false;
278 }
279 else if (identifier == "shape") {
280 const bool is_list = (scanner->Peek() == '[');
281 do {
282 if (is_list) {
283 scanner->One(Scanner::ALL);
284 ProtoSpaceAndComments(scanner);
285 }
286 const char open_char = scanner->Peek();
287 if (open_char != '{' && open_char != '<') return false;
288 scanner->One(Scanner::ALL);
289 ProtoSpaceAndComments(scanner);
290 if (!::tensorflow::internal::ProtoParseFromScanner(
291 scanner, true, open_char == '{', msg->add_shape())) return false;
292 } while (is_list && scanner->Peek() == ',');
293 if (is_list && !scanner->OneLiteral("]").GetResult()) return false;
294 }
295 else if (identifier == "tensor") {
296 const bool is_list = (scanner->Peek() == '[');
297 do {
298 if (is_list) {
299 scanner->One(Scanner::ALL);
300 ProtoSpaceAndComments(scanner);
301 }
302 const char open_char = scanner->Peek();
303 if (open_char != '{' && open_char != '<') return false;
304 scanner->One(Scanner::ALL);
305 ProtoSpaceAndComments(scanner);
306 if (!::tensorflow::internal::ProtoParseFromScanner(
307 scanner, true, open_char == '{', msg->add_tensor())) return false;
308 } while (is_list && scanner->Peek() == ',');
309 if (is_list && !scanner->OneLiteral("]").GetResult()) return false;
310 }
311 else if (identifier == "func") {
312 const bool is_list = (scanner->Peek() == '[');
313 do {
314 if (is_list) {
315 scanner->One(Scanner::ALL);
316 ProtoSpaceAndComments(scanner);
317 }
318 const char open_char = scanner->Peek();
319 if (open_char != '{' && open_char != '<') return false;
320 scanner->One(Scanner::ALL);
321 ProtoSpaceAndComments(scanner);
322 if (!::tensorflow::internal::ProtoParseFromScanner(
323 scanner, true, open_char == '{', msg->add_func())) return false;
324 } while (is_list && scanner->Peek() == ',');
325 if (is_list && !scanner->OneLiteral("]").GetResult()) return false;
326 }
327 }
328}
329
330} // namespace internal
331
332string ProtoDebugString(
333 const ::tensorflow::AttrValue& msg) {
334 string s;
335 ::tensorflow::strings::ProtoTextOutput o(&s, false);
336 internal::AppendProtoDebugString(&o, msg);
337 o.CloseTopMessage();
338 return s;
339}
340
341string ProtoShortDebugString(
342 const ::tensorflow::AttrValue& msg) {
343 string s;
344 ::tensorflow::strings::ProtoTextOutput o(&s, true);
345 internal::AppendProtoDebugString(&o, msg);
346 o.CloseTopMessage();
347 return s;
348}
349
350namespace internal {
351
352void AppendProtoDebugString(
353 ::tensorflow::strings::ProtoTextOutput* o,
354 const ::tensorflow::AttrValue& msg) {
355 if (msg.value_case() == ::tensorflow::AttrValue::kList) {
356 o->OpenNestedMessage("list");
357 ::tensorflow::internal::AppendProtoDebugString(o, msg.list());
358 o->CloseNestedMessage();
359 }
360 if (msg.value_case() == ::tensorflow::AttrValue::kS) {
361 o->AppendString("s", ProtobufStringToString(msg.s()));
362 }
363 if (msg.value_case() == ::tensorflow::AttrValue::kI) {
364 o->AppendNumeric("i", msg.i());
365 }
366 if (msg.value_case() == ::tensorflow::AttrValue::kF) {
367 o->AppendNumeric("f", msg.f());
368 }
369 if (msg.value_case() == ::tensorflow::AttrValue::kB) {
370 o->AppendBool("b", msg.b());
371 }
372 if (msg.value_case() == ::tensorflow::AttrValue::kType) {
373 const char* enum_name = ::tensorflow::EnumName_DataType(msg.type());
374 if (enum_name[0]) {
375 o->AppendEnumName("type", enum_name);
376 } else {
377 o->AppendNumeric("type", msg.type());
378 }
379 }
380 if (msg.value_case() == ::tensorflow::AttrValue::kShape) {
381 o->OpenNestedMessage("shape");
382 ::tensorflow::internal::AppendProtoDebugString(o, msg.shape());
383 o->CloseNestedMessage();
384 }
385 if (msg.value_case() == ::tensorflow::AttrValue::kTensor) {
386 o->OpenNestedMessage("tensor");
387 ::tensorflow::internal::AppendProtoDebugString(o, msg.tensor());
388 o->CloseNestedMessage();
389 }
390 if (msg.value_case() == ::tensorflow::AttrValue::kPlaceholder) {
391 o->AppendString("placeholder", ProtobufStringToString(msg.placeholder()));
392 }
393 if (msg.value_case() == ::tensorflow::AttrValue::kFunc) {
394 o->OpenNestedMessage("func");
395 ::tensorflow::internal::AppendProtoDebugString(o, msg.func());
396 o->CloseNestedMessage();
397 }
398}
399
400} // namespace internal
401
402bool ProtoParseFromString(
403 const string& s,
404 ::tensorflow::AttrValue* msg) {
405 msg->Clear();
406 Scanner scanner(s);
407 if (!internal::ProtoParseFromScanner(&scanner, false, false, msg)) return false;
408 scanner.Eos();
409 return scanner.GetResult();
410}
411
412namespace internal {
413
414bool ProtoParseFromScanner(
415 ::tensorflow::strings::Scanner* scanner, bool nested, bool close_curly,
416 ::tensorflow::AttrValue* msg) {
417 std::vector<bool> has_seen(10, false);
418 while(true) {
419 ProtoSpaceAndComments(scanner);
420 if (nested && (scanner->Peek() == (close_curly ? '}' : '>'))) {
421 scanner->One(Scanner::ALL);
422 ProtoSpaceAndComments(scanner);
423 return true;
424 }
425 if (!nested && scanner->empty()) { return true; }
426 scanner->RestartCapture()
427 .Many(Scanner::LETTER_DIGIT_UNDERSCORE)
428 .StopCapture();
429 StringPiece identifier;
430 if (!scanner->GetResult(nullptr, &identifier)) return false;
431 bool parsed_colon = false;
432 (void)parsed_colon;
433 ProtoSpaceAndComments(scanner);
434 if (scanner->Peek() == ':') {
435 parsed_colon = true;
436 scanner->One(Scanner::ALL);
437 ProtoSpaceAndComments(scanner);
438 }
439 if (identifier == "s") {
440 if (msg->value_case() != 0) return false;
441 if (has_seen[0]) return false;
442 has_seen[0] = true;
443 string str_value;
444 if (!parsed_colon || !::tensorflow::strings::ProtoParseStringLiteralFromScanner(
445 scanner, &str_value)) return false;
446 SetProtobufStringSwapAllowed(&str_value, msg->mutable_s());
447 }
448 else if (identifier == "i") {
449 if (msg->value_case() != 0) return false;
450 if (has_seen[1]) return false;
451 has_seen[1] = true;
452 int64 value;
453 if (!parsed_colon || !::tensorflow::strings::ProtoParseNumericFromScanner(scanner, &value)) return false;
454 msg->set_i(value);
455 }
456 else if (identifier == "f") {
457 if (msg->value_case() != 0) return false;
458 if (has_seen[2]) return false;
459 has_seen[2] = true;
460 float value;
461 if (!parsed_colon || !::tensorflow::strings::ProtoParseNumericFromScanner(scanner, &value)) return false;
462 msg->set_f(value);
463 }
464 else if (identifier == "b") {
465 if (msg->value_case() != 0) return false;
466 if (has_seen[3]) return false;
467 has_seen[3] = true;
468 bool value;
469 if (!parsed_colon || !::tensorflow::strings::ProtoParseBoolFromScanner(scanner, &value)) return false;
470 msg->set_b(value);
471 }
472 else if (identifier == "type") {
473 if (msg->value_case() != 0) return false;
474 if (has_seen[4]) return false;
475 has_seen[4] = true;
476 StringPiece value;
477 if (!parsed_colon || !scanner->RestartCapture().Many(Scanner::LETTER_DIGIT_DASH_UNDERSCORE).GetResult(nullptr, &value)) return false;
478 if (value == "DT_INVALID") {
479 msg->set_type(::tensorflow::DT_INVALID);
480 } else if (value == "DT_FLOAT") {
481 msg->set_type(::tensorflow::DT_FLOAT);
482 } else if (value == "DT_DOUBLE") {
483 msg->set_type(::tensorflow::DT_DOUBLE);
484 } else if (value == "DT_INT32") {
485 msg->set_type(::tensorflow::DT_INT32);
486 } else if (value == "DT_UINT8") {
487 msg->set_type(::tensorflow::DT_UINT8);
488 } else if (value == "DT_INT16") {
489 msg->set_type(::tensorflow::DT_INT16);
490 } else if (value == "DT_INT8") {
491 msg->set_type(::tensorflow::DT_INT8);
492 } else if (value == "DT_STRING") {
493 msg->set_type(::tensorflow::DT_STRING);
494 } else if (value == "DT_COMPLEX64") {
495 msg->set_type(::tensorflow::DT_COMPLEX64);
496 } else if (value == "DT_INT64") {
497 msg->set_type(::tensorflow::DT_INT64);
498 } else if (value == "DT_BOOL") {
499 msg->set_type(::tensorflow::DT_BOOL);
500 } else if (value == "DT_QINT8") {
501 msg->set_type(::tensorflow::DT_QINT8);
502 } else if (value == "DT_QUINT8") {
503 msg->set_type(::tensorflow::DT_QUINT8);
504 } else if (value == "DT_QINT32") {
505 msg->set_type(::tensorflow::DT_QINT32);
506 } else if (value == "DT_BFLOAT16") {
507 msg->set_type(::tensorflow::DT_BFLOAT16);
508 } else if (value == "DT_QINT16") {
509 msg->set_type(::tensorflow::DT_QINT16);
510 } else if (value == "DT_QUINT16") {
511 msg->set_type(::tensorflow::DT_QUINT16);
512 } else if (value == "DT_UINT16") {
513 msg->set_type(::tensorflow::DT_UINT16);
514 } else if (value == "DT_COMPLEX128") {
515 msg->set_type(::tensorflow::DT_COMPLEX128);
516 } else if (value == "DT_HALF") {
517 msg->set_type(::tensorflow::DT_HALF);
518 } else if (value == "DT_RESOURCE") {
519 msg->set_type(::tensorflow::DT_RESOURCE);
520 } else if (value == "DT_VARIANT") {
521 msg->set_type(::tensorflow::DT_VARIANT);
522 } else if (value == "DT_UINT32") {
523 msg->set_type(::tensorflow::DT_UINT32);
524 } else if (value == "DT_UINT64") {
525 msg->set_type(::tensorflow::DT_UINT64);
526 } else if (value == "DT_FLOAT_REF") {
527 msg->set_type(::tensorflow::DT_FLOAT_REF);
528 } else if (value == "DT_DOUBLE_REF") {
529 msg->set_type(::tensorflow::DT_DOUBLE_REF);
530 } else if (value == "DT_INT32_REF") {
531 msg->set_type(::tensorflow::DT_INT32_REF);
532 } else if (value == "DT_UINT8_REF") {
533 msg->set_type(::tensorflow::DT_UINT8_REF);
534 } else if (value == "DT_INT16_REF") {
535 msg->set_type(::tensorflow::DT_INT16_REF);
536 } else if (value == "DT_INT8_REF") {
537 msg->set_type(::tensorflow::DT_INT8_REF);
538 } else if (value == "DT_STRING_REF") {
539 msg->set_type(::tensorflow::DT_STRING_REF);
540 } else if (value == "DT_COMPLEX64_REF") {
541 msg->set_type(::tensorflow::DT_COMPLEX64_REF);
542 } else if (value == "DT_INT64_REF") {
543 msg->set_type(::tensorflow::DT_INT64_REF);
544 } else if (value == "DT_BOOL_REF") {
545 msg->set_type(::tensorflow::DT_BOOL_REF);
546 } else if (value == "DT_QINT8_REF") {
547 msg->set_type(::tensorflow::DT_QINT8_REF);
548 } else if (value == "DT_QUINT8_REF") {
549 msg->set_type(::tensorflow::DT_QUINT8_REF);
550 } else if (value == "DT_QINT32_REF") {
551 msg->set_type(::tensorflow::DT_QINT32_REF);
552 } else if (value == "DT_BFLOAT16_REF") {
553 msg->set_type(::tensorflow::DT_BFLOAT16_REF);
554 } else if (value == "DT_QINT16_REF") {
555 msg->set_type(::tensorflow::DT_QINT16_REF);
556 } else if (value == "DT_QUINT16_REF") {
557 msg->set_type(::tensorflow::DT_QUINT16_REF);
558 } else if (value == "DT_UINT16_REF") {
559 msg->set_type(::tensorflow::DT_UINT16_REF);
560 } else if (value == "DT_COMPLEX128_REF") {
561 msg->set_type(::tensorflow::DT_COMPLEX128_REF);
562 } else if (value == "DT_HALF_REF") {
563 msg->set_type(::tensorflow::DT_HALF_REF);
564 } else if (value == "DT_RESOURCE_REF") {
565 msg->set_type(::tensorflow::DT_RESOURCE_REF);
566 } else if (value == "DT_VARIANT_REF") {
567 msg->set_type(::tensorflow::DT_VARIANT_REF);
568 } else if (value == "DT_UINT32_REF") {
569 msg->set_type(::tensorflow::DT_UINT32_REF);
570 } else if (value == "DT_UINT64_REF") {
571 msg->set_type(::tensorflow::DT_UINT64_REF);
572 } else {
573 int32 int_value;
574 if (strings::SafeStringToNumeric(value, &int_value)) {
575 msg->set_type(static_cast<::tensorflow::DataType>(int_value));
576 } else {
577 return false;
578 }
579 }
580 }
581 else if (identifier == "shape") {
582 if (msg->value_case() != 0) return false;
583 if (has_seen[5]) return false;
584 has_seen[5] = true;
585 const char open_char = scanner->Peek();
586 if (open_char != '{' && open_char != '<') return false;
587 scanner->One(Scanner::ALL);
588 ProtoSpaceAndComments(scanner);
589 if (!::tensorflow::internal::ProtoParseFromScanner(
590 scanner, true, open_char == '{', msg->mutable_shape())) return false;
591 }
592 else if (identifier == "tensor") {
593 if (msg->value_case() != 0) return false;
594 if (has_seen[6]) return false;
595 has_seen[6] = true;
596 const char open_char = scanner->Peek();
597 if (open_char != '{' && open_char != '<') return false;
598 scanner->One(Scanner::ALL);
599 ProtoSpaceAndComments(scanner);
600 if (!::tensorflow::internal::ProtoParseFromScanner(
601 scanner, true, open_char == '{', msg->mutable_tensor())) return false;
602 }
603 else if (identifier == "list") {
604 if (msg->value_case() != 0) return false;
605 if (has_seen[7]) return false;
606 has_seen[7] = true;
607 const char open_char = scanner->Peek();
608 if (open_char != '{' && open_char != '<') return false;
609 scanner->One(Scanner::ALL);
610 ProtoSpaceAndComments(scanner);
611 if (!::tensorflow::internal::ProtoParseFromScanner(
612 scanner, true, open_char == '{', msg->mutable_list())) return false;
613 }
614 else if (identifier == "func") {
615 if (msg->value_case() != 0) return false;
616 if (has_seen[8]) return false;
617 has_seen[8] = true;
618 const char open_char = scanner->Peek();
619 if (open_char != '{' && open_char != '<') return false;
620 scanner->One(Scanner::ALL);
621 ProtoSpaceAndComments(scanner);
622 if (!::tensorflow::internal::ProtoParseFromScanner(
623 scanner, true, open_char == '{', msg->mutable_func())) return false;
624 }
625 else if (identifier == "placeholder") {
626 if (msg->value_case() != 0) return false;
627 if (has_seen[9]) return false;
628 has_seen[9] = true;
629 string str_value;
630 if (!parsed_colon || !::tensorflow::strings::ProtoParseStringLiteralFromScanner(
631 scanner, &str_value)) return false;
632 SetProtobufStringSwapAllowed(&str_value, msg->mutable_placeholder());
633 }
634 }
635}
636
637} // namespace internal
638
639namespace internal {
640namespace {
641
642bool ProtoParseFromScanner(
643 ::tensorflow::strings::Scanner* scanner, bool nested, bool close_curly,
644 ::tensorflow::protobuf::Map<string, ::tensorflow::AttrValue>* map) {
645 string map_key;
646 bool set_map_key = false;
647 ::tensorflow::AttrValue map_value;
648 bool set_map_value = false;
649 std::vector<bool> has_seen(2, false);
650 while(true) {
651 ProtoSpaceAndComments(scanner);
652 if (nested && (scanner->Peek() == (close_curly ? '}' : '>'))) {
653 scanner->One(Scanner::ALL);
654 ProtoSpaceAndComments(scanner);
655 if (!set_map_key || !set_map_value) return false;
656 (*map)[map_key] = map_value;
657 return true;
658 }
659 if (!nested && scanner->empty()) { return true; }
660 scanner->RestartCapture()
661 .Many(Scanner::LETTER_DIGIT_UNDERSCORE)
662 .StopCapture();
663 StringPiece identifier;
664 if (!scanner->GetResult(nullptr, &identifier)) return false;
665 bool parsed_colon = false;
666 (void)parsed_colon;
667 ProtoSpaceAndComments(scanner);
668 if (scanner->Peek() == ':') {
669 parsed_colon = true;
670 scanner->One(Scanner::ALL);
671 ProtoSpaceAndComments(scanner);
672 }
673 if (identifier == "key") {
674 string str_value;
675 if (!parsed_colon || !::tensorflow::strings::ProtoParseStringLiteralFromScanner(
676 scanner, &str_value)) return false;
677 SetProtobufStringSwapAllowed(&str_value, &map_key);
678 set_map_key = true;
679 }
680 else if (identifier == "value") {
681 const char open_char = scanner->Peek();
682 if (open_char != '{' && open_char != '<') return false;
683 scanner->One(Scanner::ALL);
684 ProtoSpaceAndComments(scanner);
685 if (!::tensorflow::internal::ProtoParseFromScanner(
686 scanner, true, open_char == '{', &map_value)) return false;
687 set_map_value = true;
688 }
689 }
690}
691
692} // namespace
693} // namespace internal
694
695string ProtoDebugString(
696 const ::tensorflow::NameAttrList& msg) {
697 string s;
698 ::tensorflow::strings::ProtoTextOutput o(&s, false);
699 internal::AppendProtoDebugString(&o, msg);
700 o.CloseTopMessage();
701 return s;
702}
703
704string ProtoShortDebugString(
705 const ::tensorflow::NameAttrList& msg) {
706 string s;
707 ::tensorflow::strings::ProtoTextOutput o(&s, true);
708 internal::AppendProtoDebugString(&o, msg);
709 o.CloseTopMessage();
710 return s;
711}
712
713namespace internal {
714
715void AppendProtoDebugString(
716 ::tensorflow::strings::ProtoTextOutput* o,
717 const ::tensorflow::NameAttrList& msg) {
718 o->AppendStringIfNotEmpty("name", ProtobufStringToString(msg.name()));
719 {
720 std::vector<string> keys;
721 for (const auto& e : msg.attr()) keys.push_back(e.first);
722 std::stable_sort(keys.begin(), keys.end());
723 for (const auto& key : keys) {
724 o->OpenNestedMessage("attr");
725 o->AppendString("key", ProtobufStringToString(key));
726 o->OpenNestedMessage("value");
727 ::tensorflow::internal::AppendProtoDebugString(o, msg.attr().at(key));
728 o->CloseNestedMessage();
729 o->CloseNestedMessage();
730 }
731 }
732}
733
734} // namespace internal
735
736bool ProtoParseFromString(
737 const string& s,
738 ::tensorflow::NameAttrList* msg) {
739 msg->Clear();
740 Scanner scanner(s);
741 if (!internal::ProtoParseFromScanner(&scanner, false, false, msg)) return false;
742 scanner.Eos();
743 return scanner.GetResult();
744}
745
746namespace internal {
747
748bool ProtoParseFromScanner(
749 ::tensorflow::strings::Scanner* scanner, bool nested, bool close_curly,
750 ::tensorflow::NameAttrList* msg) {
751 std::vector<bool> has_seen(2, false);
752 while(true) {
753 ProtoSpaceAndComments(scanner);
754 if (nested && (scanner->Peek() == (close_curly ? '}' : '>'))) {
755 scanner->One(Scanner::ALL);
756 ProtoSpaceAndComments(scanner);
757 return true;
758 }
759 if (!nested && scanner->empty()) { return true; }
760 scanner->RestartCapture()
761 .Many(Scanner::LETTER_DIGIT_UNDERSCORE)
762 .StopCapture();
763 StringPiece identifier;
764 if (!scanner->GetResult(nullptr, &identifier)) return false;
765 bool parsed_colon = false;
766 (void)parsed_colon;
767 ProtoSpaceAndComments(scanner);
768 if (scanner->Peek() == ':') {
769 parsed_colon = true;
770 scanner->One(Scanner::ALL);
771 ProtoSpaceAndComments(scanner);
772 }
773 if (identifier == "name") {
774 if (has_seen[0]) return false;
775 has_seen[0] = true;
776 string str_value;
777 if (!parsed_colon || !::tensorflow::strings::ProtoParseStringLiteralFromScanner(
778 scanner, &str_value)) return false;
779 SetProtobufStringSwapAllowed(&str_value, msg->mutable_name());
780 }
781 else if (identifier == "attr") {
782 const bool is_list = (scanner->Peek() == '[');
783 do {
784 if (is_list) {
785 scanner->One(Scanner::ALL);
786 ProtoSpaceAndComments(scanner);
787 }
788 const char open_char = scanner->Peek();
789 if (open_char != '{' && open_char != '<') return false;
790 scanner->One(Scanner::ALL);
791 ProtoSpaceAndComments(scanner);
792 if (!ProtoParseFromScanner(
793 scanner, true, open_char == '{', msg->mutable_attr())) return false;
794 } while (is_list && scanner->Peek() == ',');
795 if (is_list && !scanner->OneLiteral("]").GetResult()) return false;
796 }
797 }
798}
799
800} // namespace internal
801
802} // namespace tensorflow
803