diff --git a/changed_fields.go b/changed_fields.go index 405f966..41e0fe6 100644 --- a/changed_fields.go +++ b/changed_fields.go @@ -27,6 +27,10 @@ func (cf ChangedFields) Changed(field string) bool { } func (cf *ChangedFields) SetChanged(fields ...string) { + if cf.fieldNames == nil { + cf.fieldNames = make(map[string]struct{}) + } + for _, field := range fields { cf.fieldNames[field] = struct{}{} } @@ -35,3 +39,7 @@ func (cf *ChangedFields) SetChanged(fields ...string) { func (cf ChangedFields) Empty() bool { return len(cf.fieldNames) == 0 } + +func (cf ChangedFields) IsNil() bool { + return cf.fieldNames == nil +} diff --git a/fields_mask.go b/fields_mask.go index 2179582..151bf09 100644 --- a/fields_mask.go +++ b/fields_mask.go @@ -52,6 +52,18 @@ func (fm FieldsMask) IsFilled() bool { return false } +func (fm *FieldsMask) Reset() { + for i := range fm.parts { + fm.parts[i] = 0 + } +} + +func (fm *FieldsMask) SetChangedAll() { + for i := range fm.parts { + fm.parts[i] = 1<<64 - 1 + } +} + func (fm FieldsMask) partIndex(index uint64) uint64 { return index / FieldsMaskPartBitSize }