Skip to content

Commit

Permalink
Merge branch 'dev' into version-bump-v1.10.15
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Nov 2, 2023
2 parents ed1b280 + 36d1630 commit 734fd26
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 77 deletions.
19 changes: 17 additions & 2 deletions codec/reflectcodec/struct_fielder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ const (

// TagValue is the value the tag must have to be serialized.
TagValue = "true"

// TagValue is the value the tag must have to be serialized, this variant
// includes the nullable option
TagWithNullableValue = "true,nullable"
)

var _ StructFielder = (*structFielder)(nil)

type FieldDesc struct {
Index int
MaxSliceLen uint32
Nullable bool
}

// StructFielder handles discovery of serializable fields in a struct.
Expand Down Expand Up @@ -82,10 +87,19 @@ func (s *structFielder) GetSerializedFields(t reflect.Type) ([]FieldDesc, error)
// Multiple tags per fields can be specified.
// Serialize/Deserialize field if it has
// any tag with the right value
captureField := false
var (
captureField bool
nullable bool
)
for _, tag := range s.tags {
if field.Tag.Get(tag) == TagValue {
switch field.Tag.Get(tag) {
case TagValue:
captureField = true
case TagWithNullableValue:
captureField = true
nullable = true
}
if captureField {
break
}
}
Expand All @@ -107,6 +121,7 @@ func (s *structFielder) GetSerializedFields(t reflect.Type) ([]FieldDesc, error)
serializedFields = append(serializedFields, FieldDesc{
Index: i,
MaxSliceLen: maxSliceLen,
Nullable: nullable,
})
}
s.serializedFieldIndices[t] = serializedFields // cache result
Expand Down
Loading

0 comments on commit 734fd26

Please sign in to comment.