Skip to content

Commit

Permalink
fix(thrift): write default val for optional fields (#79)
Browse files Browse the repository at this point in the history
fix: write default val for optional fields
  • Loading branch information
Marina-Sakai authored Oct 25, 2024
1 parent fa8cd91 commit ba1cfef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions thrift/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ func (b RequiresBitmap) CheckRequires(desc *StructDescriptor, writeDefault bool,
return nil
}

// CheckRequires scan every bit of the bitmap. When a bit is marked, it will:
// HandleRequires scan every bit of the bitmap. When a bit is marked, it will:
// - if the corresponding field is required-requireness and writeRquired is true, it will call handler to handle this field, otherwise report error
// - if the corresponding is default-requireness and writeDefault is true, it will call handler to handle this field
// - if the corresponding is optional-requireness and writeOptional is true, it will call handler to handle this field
//
//go:nocheckptr
func (b RequiresBitmap) HandleRequires(desc *StructDescriptor, writeRquired bool, writeDefault bool, writeOptional bool, handler func(field *FieldDescriptor) error) error {
func (b RequiresBitmap) HandleRequires(desc *StructDescriptor, writeRequired bool, writeDefault bool, writeOptional bool, handler func(field *FieldDescriptor) error) error {
// handle bitmap first
n := len(b)
s := (*rt.GoSlice)(unsafe.Pointer(&b)).Ptr
Expand All @@ -156,10 +156,10 @@ func (b RequiresBitmap) HandleRequires(desc *StructDescriptor, writeRquired bool
for j := 0; v != 0 && j < int64BitSize; j++ {
if v%2 == 1 {
f := desc.FieldById(FieldID(i*int64BitSize + j))
if f.Required() == RequiredRequireness && !writeRquired {
if f.Required() == RequiredRequireness && !writeRequired {
return errMissRequiredField(f, desc)
}
if (f.Required() == DefaultRequireness && !writeDefault) || (f.Required() == OptionalRequireness && !writeOptional) {
if (f.Required() == DefaultRequireness && !writeDefault) || (f.Required() == OptionalRequireness && !writeOptional && f.DefaultValue() == nil) {
v >>= 1
continue
}
Expand Down

0 comments on commit ba1cfef

Please sign in to comment.