| 655 | } |
| 656 | |
| 657 | void SerializeThriftRequest(butil::IOBuf* request_buf, Controller* cntl, |
| 658 | const google::protobuf::Message* req_base) { |
| 659 | if (req_base == NULL) { |
| 660 | return cntl->SetFailed(EREQUEST, "request is NULL"); |
| 661 | } |
| 662 | if (req_base->GetDescriptor() != ThriftFramedMessage::descriptor()) { |
| 663 | return cntl->SetFailed(EINVAL, "Type of request must be ThriftFramedMessage"); |
| 664 | } |
| 665 | if (cntl->response() != NULL && |
| 666 | cntl->response()->GetDescriptor() != ThriftFramedMessage::descriptor()) { |
| 667 | return cntl->SetFailed(EINVAL, "Type of response must be ThriftFramedMessage"); |
| 668 | } |
| 669 | |
| 670 | const std::string& method_name = cntl->thrift_method_name(); |
| 671 | // we should do more check on the thrift method name, but since it is rare when |
| 672 | // the method_name is just some white space or something else |
| 673 | if (method_name.empty() || method_name[0] == ' ') { |
| 674 | return cntl->SetFailed(ENOMETHOD, "Invalid thrift_method_name!"); |
| 675 | } |
| 676 | if (method_name.size() > MAX_THRIFT_METHOD_NAME_LENGTH) { |
| 677 | return cntl->SetFailed(ENOMETHOD, "thrift_method_name is too long"); |
| 678 | } |
| 679 | |
| 680 | const ThriftFramedMessage* req = (const ThriftFramedMessage*)req_base; |
| 681 | |
| 682 | // xxx_pargs write |
| 683 | if (req->raw_instance()) { |
| 684 | auto out_buffer = |
| 685 | THRIFT_STDCXX::make_shared<apache::thrift::transport::TMemoryBuffer>(); |
| 686 | apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TMemoryBuffer> oprot(out_buffer); |
| 687 | |
| 688 | oprot.writeMessageBegin( |
| 689 | method_name, ::apache::thrift::protocol::T_CALL, 0/*seq_id*/); |
| 690 | |
| 691 | uint32_t xfer = 0; |
| 692 | char struct_begin_str[32 + method_name.size()]; |
| 693 | char* p = struct_begin_str; |
| 694 | memcpy(p, "ThriftService_", 14); |
| 695 | p += 14; |
| 696 | memcpy(p, method_name.data(), method_name.size()); |
| 697 | p += method_name.size(); |
| 698 | memcpy(p, "_pargs", 6); |
| 699 | p += 6; |
| 700 | *p = '\0'; |
| 701 | xfer += oprot.writeStructBegin(struct_begin_str); |
| 702 | xfer += oprot.writeFieldBegin("request", ::apache::thrift::protocol::T_STRUCT, |
| 703 | THRIFT_REQUEST_FID); |
| 704 | |
| 705 | // request's write |
| 706 | xfer += req->raw_instance()->Write(&oprot); |
| 707 | |
| 708 | xfer += oprot.writeFieldEnd(); |
| 709 | xfer += oprot.writeFieldStop(); |
| 710 | xfer += oprot.writeStructEnd(); |
| 711 | (void)xfer; |
| 712 | |
| 713 | oprot.writeMessageEnd(); |
| 714 | oprot.getTransport()->writeEnd(); |
nothing calls this directly
no test coverage detected