From abe543a275b06e2de75e104a82af159ac2263926 Mon Sep 17 00:00:00 2001 From: Pavel Merzlyakov Date: Sat, 17 Jun 2023 10:45:52 +0300 Subject: [PATCH] additional methods for FieldsMask and ChangedFields --- changed_fields.go | 8 ++++++++ fields_mask.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) 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 }