Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-3778

go client can not pass method parameter to server of other language if no field_id is given

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.9.3
    • 0.11.0
    • Go - Compiler
    • None

    Description

      go client can not pass method parameter to java server

      for example message.thrift

      message.thrift
      namespace java test
      namespace csharp test
      namespace go test
      struct Message
      {
          1: string text
      }
      service MessageProcessor {
          void process(Message message);
      }
      

      We generated messageprocess.go as golang client and MessageProcessor.java as java server
      When go client send service method arguments "process_args", 1 is sent as the field_id of struct "message"

      messageprocessor.go
      func (p *MessageProcessorProcessArgs) Write(oprot thrift.TProtocol) error {
        if err := oprot.WriteStructBegin("process_args"); err != nil {
          return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
        }
        if err := p.writeField_1(oprot); err != nil {
          return err
        }
        ...
      }
      
      func (p *MessageProcessorProcessArgs) writeField_1(oprot thrift.TProtocol) (err error) {
        if err := oprot.WriteFieldBegin("message", thrift.STRUCT, 1); err != nil {
          return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:message: ", p), err)
        }
        ...
      }
      

      When java server try to receive service method arguments "process_args", -1 is marked as the field_id of struct "message"

      MessageProcessor.java
        private static class process_argsStandardScheme extends StandardScheme<process_args> {
        ...
        iprot.readStructBegin();
        while (true)
        {
          schemeField = iprot.readFieldBegin();
          if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
            break;
          }
          switch (schemeField.id) {
            case -1: // MESSAGE
            if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
              struct.message = new Message();
              struct.message.read(iprot);
              struct.setMessageIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
            default:
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
          }
          iprot.readFieldEnd();
        }
        iprot.readStructEnd();
        ...
      

      Because of this, we always receive NULL "message" in java server.
      Compared to some other language implementation, I think it's a thrift go generator problem.

      Attachments

        Activity

          People

            ggndnn Guo
            ggndnn Guo
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: