| 382 | static bool SkipAMFObjectBody(AMFInputStream* stream); |
| 383 | |
| 384 | static bool ReadAMFObjectField(AMFInputStream* stream, |
| 385 | google::protobuf::Message* message, |
| 386 | const google::protobuf::FieldDescriptor* field) { |
| 387 | const google::protobuf::Reflection* reflection = NULL; |
| 388 | if (field) { |
| 389 | reflection = message->GetReflection(); |
| 390 | } |
| 391 | uint8_t marker; |
| 392 | if (stream->cut_u8(&marker) != 1u) { |
| 393 | LOG(ERROR) << "stream is not long enough"; |
| 394 | return false; |
| 395 | } |
| 396 | switch ((AMFMarker)marker) { |
| 397 | case AMF_MARKER_NUMBER: { |
| 398 | uint64_t val = 0; |
| 399 | if (stream->cut_u64(&val) != 8u) { |
| 400 | LOG(ERROR) << "stream is not long enough"; |
| 401 | return false; |
| 402 | } |
| 403 | if (field) { |
| 404 | if (field->cpp_type() != google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE) { |
| 405 | LOG(WARNING) << "Can't set double=" << val << " to " |
| 406 | << field->full_name(); |
| 407 | } else { |
| 408 | double* dptr = (double*)&val; |
| 409 | reflection->SetDouble(message, field, *dptr); |
| 410 | } |
| 411 | } |
| 412 | } break; |
| 413 | case AMF_MARKER_BOOLEAN: { |
| 414 | uint8_t val = 0; |
| 415 | if (stream->cut_u8(&val) != 1u) { |
| 416 | LOG(ERROR) << "stream is not long enough"; |
| 417 | return false; |
| 418 | } |
| 419 | if (field) { |
| 420 | if (field->cpp_type() != google::protobuf::FieldDescriptor::CPPTYPE_BOOL) { |
| 421 | LOG(WARNING) << "Can't set bool to " << field->full_name(); |
| 422 | } else { |
| 423 | reflection->SetBool(message, field, !!val); |
| 424 | } |
| 425 | } |
| 426 | } break; |
| 427 | case AMF_MARKER_STRING: { |
| 428 | std::string val; |
| 429 | if (!ReadAMFShortStringBody(&val, stream)) { |
| 430 | return false; |
| 431 | } |
| 432 | if (field) { |
| 433 | if (field->cpp_type() != google::protobuf::FieldDescriptor::CPPTYPE_STRING) { |
| 434 | LOG(WARNING) << "Can't set string=`" << val << "' to " |
| 435 | << field->full_name(); |
| 436 | } else { |
| 437 | reflection->SetString(message, field, val); |
| 438 | } |
| 439 | } |
| 440 | } break; |
| 441 | case AMF_MARKER_TYPED_OBJECT: { |
no test coverage detected