package ticket import ( "github.com/ClickHouse/clickhouse-go/v2/lib/driver" "github.com/kelindar/bitmap" "google.golang.org/protobuf/types/known/timestamppb" "time" ) func (x *Ticket) Scan(row driver.Rows) error { var ( from map[string]string createdAt time.Time updatedAt time.Time err error ) if err = row.Scan( &x.TicketId, &x.ThreadId, &x.To, &from, &x.Flags, &x.Meta, &x.Tags, &createdAt, &updatedAt, &x.MessageIds, &x.Subjects, ); err != nil { return err } x.From = &EmailAddress{ Address: from["address"], Name: from["name"], } x.CreatedAt = timestamppb.New(createdAt) x.UpdatedAt = timestamppb.New(updatedAt) return nil } func (x *Ticket) SetFlags(flags ...TicketFlag) { mask := bitmap.FromBytes(x.Flags) for i := range flags { if TicketFlag_unknown_ticket_flag == flags[i] { continue } mask.Set(uint32(flags[i])) } x.Flags = mask.ToBytes() } func (x *Ticket) RemoveFlags(flags ...TicketFlag) { mask := bitmap.FromBytes(x.Flags) for i := range flags { if TicketFlag_unknown_ticket_flag == flags[i] { continue } mask.Remove(uint32(flags[i])) } x.Flags = mask.ToBytes() } func (x *Ticket) HasFlag(flag TicketFlag) bool { return bitmap. FromBytes(x.Flags). Contains(uint32(flag)) }