[
https://issues.apache.org/jira/browse/THRIFT-2420?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Frank Schroeder updated THRIFT-2420:
------------------------------------
Attachment: THRIFT-2420-with-indentation.patch
After applying the patch you should see the following output with {{git diff
-b}}
{code}
[thrift master] $ git diff -b
diff --git a/compiler/cpp/src/generate/t_go_generator.cc
b/compiler/cpp/src/generate/t_go_generator.cc
index a216c2b..d00d89f 100644
--- a/compiler/cpp/src/generate/t_go_generator.cc
+++ b/compiler/cpp/src/generate/t_go_generator.cc
@@ -1130,6 +1130,14 @@ void t_go_generator::generate_go_struct_reader(ofstream&
out,
// Check for field STOP marker and break
out <<
indent() << "if fieldTypeId == thrift.STOP { break; }" << endl;
+
+ // if there are no defined fields make sure we skip the field we just read
+ if (fields.empty()) {
+ out <<
+ indent() << "if err := iprot.Skip(fieldTypeId); err != nil {" <<
endl <<
+ indent() << " return err" << endl <<
+ indent() << "}" << endl;
+ } else {
// Switch statement on the field we are reading
bool first = true;
string thriftFieldTypeId;
@@ -1176,6 +1184,7 @@ void t_go_generator::generate_go_struct_reader(ofstream&
out,
indent() << " }" << endl <<
indent() << "}" << endl;
}
+ }
{code}
> Go argument parser for methods without arguments does not skip fields
> ---------------------------------------------------------------------
>
> Key: THRIFT-2420
> URL: https://issues.apache.org/jira/browse/THRIFT-2420
> Project: Thrift
> Issue Type: Bug
> Components: Go - Compiler
> Affects Versions: 0.9.2
> Environment: All
> Reporter: Frank Schroeder
> Fix For: 0.9.2
>
> Attachments: THRIFT-2420-with-indentation.patch
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> The Read() method of a struct of a thrift function which does not have
> arguments (e.g. foo()) calls iprot.ReadFieldBegin() to read the field type
> but does not consume/skip a field which it was not expecting.
> Read() methods for argument parsers for methods which have arguments have the
> correct code in the default section of the switch statement.
> This is the current code (I've added where the iprot.Skip() call is missing):
> {code}
> func (p *GetVersionDataArgs) Read(iprot thrift.TProtocol) error {
> if _, err := iprot.ReadStructBegin(); err != nil {
> return fmt.Errorf("%T read error: %s", p, err)
> }
> for {
> _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
> if err != nil {
> return fmt.Errorf("%T field %d read error: %s", p,
> fieldId, err)
> }
> if fieldTypeId == thrift.STOP {
> break
> }
> // should call iprot.Skip(fieldTypeId) if not STOP
> if err := iprot.ReadFieldEnd(); err != nil {
> return err
> }
> }
> if err := iprot.ReadStructEnd(); err != nil {
> return fmt.Errorf("%T read struct end error: %s", p, err)
> }
> return nil
> }
> {code}
> After the check for {{thrift.STOP}} there needs to be this code
> {code}
> if err := iprot.Skip(fieldTypeId); err != nil {
> return err
> }
> {code}
> We've found this because on the Java side we dynamically inject fields into
> the struct on call which are ignored on the Go side as long as the function
> has arguments. When we make a call to the no-argument function some bytes are
> not consumed and make the thrift code go out of sync.
> I will attach a patch which fixes this.
--
This message was sent by Atlassian JIRA
(v6.2#6252)