additional methods for FieldsMask and ChangedFields

This commit is contained in:
Pavel Merzlyakov 2023-06-17 10:45:52 +03:00
parent 4fd35a4f3a
commit abe543a275
2 changed files with 20 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}