Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(thrift): write default val for optional fields #79

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading