Skip to content

Commit

Permalink
opt: only write StructEnd while WriteEmpty()
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Jul 10, 2023
1 parent 6ec0698 commit c6daa2a
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions thrift/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,23 +502,7 @@ func (p *BinaryProtocol) WriteEmpty(desc *TypeDescriptor) error {
}
return p.WriteMapEnd()
case STRUCT:
if err := p.WriteStructBegin(""); err != nil {
return err
}
for _, f := range desc.Struct().Fields() {
if f.Required() == OptionalRequireness {
continue
}
if err := p.WriteFieldBegin(f.Name(), f.Type().Type(), f.ID()); err != nil {
return err
}
if err := p.WriteEmpty(f.Type()); err != nil {
return err
}
if err := p.WriteFieldEnd(); err != nil {
return err
}
}
// NOTICE: to avoid self-cycled type dead loop here, just write empty struct
return p.WriteStructEnd()
default:
return errors.New("invalid type")
Expand Down

0 comments on commit c6daa2a

Please sign in to comment.