// Code generated by gotdgen, DO NOT EDIT. package tdapi import ( "context" "errors" "fmt" "sort" "strings" "go.uber.org/multierr" "go.mau.fi/mautrix-telegram/pkg/gotd/bin" "go.mau.fi/mautrix-telegram/pkg/gotd/tdjson" "go.mau.fi/mautrix-telegram/pkg/gotd/tdp" "go.mau.fi/mautrix-telegram/pkg/gotd/tgerr" ) // No-op definition for keeping imports. var ( _ = bin.Buffer{} _ = context.Background() _ = fmt.Stringer(nil) _ = strings.Builder{} _ = errors.Is _ = multierr.AppendInto _ = sort.Ints _ = tdp.Format _ = tgerr.Error{} _ = tdjson.Encoder{} ) // NotificationSounds represents TL type `notificationSounds#7ba3c849`. type NotificationSounds struct { // A list of notification sounds NotificationSounds []NotificationSound } // NotificationSoundsTypeID is TL type id of NotificationSounds. const NotificationSoundsTypeID = 0x7ba3c849 // Ensuring interfaces in compile-time for NotificationSounds. var ( _ bin.Encoder = &NotificationSounds{} _ bin.Decoder = &NotificationSounds{} _ bin.BareEncoder = &NotificationSounds{} _ bin.BareDecoder = &NotificationSounds{} ) func (n *NotificationSounds) Zero() bool { if n == nil { return true } if !(n.NotificationSounds == nil) { return false } return true } // String implements fmt.Stringer. func (n *NotificationSounds) String() string { if n == nil { return "NotificationSounds(nil)" } type Alias NotificationSounds return fmt.Sprintf("NotificationSounds%+v", Alias(*n)) } // TypeID returns type id in TL schema. // // See https://core.telegram.org/mtproto/TL-tl#remarks. func (*NotificationSounds) TypeID() uint32 { return NotificationSoundsTypeID } // TypeName returns name of type in TL schema. func (*NotificationSounds) TypeName() string { return "notificationSounds" } // TypeInfo returns info about TL type. func (n *NotificationSounds) TypeInfo() tdp.Type { typ := tdp.Type{ Name: "notificationSounds", ID: NotificationSoundsTypeID, } if n == nil { typ.Null = true return typ } typ.Fields = []tdp.Field{ { Name: "NotificationSounds", SchemaName: "notification_sounds", }, } return typ } // Encode implements bin.Encoder. func (n *NotificationSounds) Encode(b *bin.Buffer) error { if n == nil { return fmt.Errorf("can't encode notificationSounds#7ba3c849 as nil") } b.PutID(NotificationSoundsTypeID) return n.EncodeBare(b) } // EncodeBare implements bin.BareEncoder. func (n *NotificationSounds) EncodeBare(b *bin.Buffer) error { if n == nil { return fmt.Errorf("can't encode notificationSounds#7ba3c849 as nil") } b.PutInt(len(n.NotificationSounds)) for idx, v := range n.NotificationSounds { if err := v.EncodeBare(b); err != nil { return fmt.Errorf("unable to encode bare notificationSounds#7ba3c849: field notification_sounds element with index %d: %w", idx, err) } } return nil } // Decode implements bin.Decoder. func (n *NotificationSounds) Decode(b *bin.Buffer) error { if n == nil { return fmt.Errorf("can't decode notificationSounds#7ba3c849 to nil") } if err := b.ConsumeID(NotificationSoundsTypeID); err != nil { return fmt.Errorf("unable to decode notificationSounds#7ba3c849: %w", err) } return n.DecodeBare(b) } // DecodeBare implements bin.BareDecoder. func (n *NotificationSounds) DecodeBare(b *bin.Buffer) error { if n == nil { return fmt.Errorf("can't decode notificationSounds#7ba3c849 to nil") } { headerLen, err := b.Int() if err != nil { return fmt.Errorf("unable to decode notificationSounds#7ba3c849: field notification_sounds: %w", err) } if headerLen > 0 { n.NotificationSounds = make([]NotificationSound, 0, headerLen%bin.PreallocateLimit) } for idx := 0; idx < headerLen; idx++ { var value NotificationSound if err := value.DecodeBare(b); err != nil { return fmt.Errorf("unable to decode bare notificationSounds#7ba3c849: field notification_sounds: %w", err) } n.NotificationSounds = append(n.NotificationSounds, value) } } return nil } // EncodeTDLibJSON implements tdjson.TDLibEncoder. func (n *NotificationSounds) EncodeTDLibJSON(b tdjson.Encoder) error { if n == nil { return fmt.Errorf("can't encode notificationSounds#7ba3c849 as nil") } b.ObjStart() b.PutID("notificationSounds") b.Comma() b.FieldStart("notification_sounds") b.ArrStart() for idx, v := range n.NotificationSounds { if err := v.EncodeTDLibJSON(b); err != nil { return fmt.Errorf("unable to encode notificationSounds#7ba3c849: field notification_sounds element with index %d: %w", idx, err) } b.Comma() } b.StripComma() b.ArrEnd() b.Comma() b.StripComma() b.ObjEnd() return nil } // DecodeTDLibJSON implements tdjson.TDLibDecoder. func (n *NotificationSounds) DecodeTDLibJSON(b tdjson.Decoder) error { if n == nil { return fmt.Errorf("can't decode notificationSounds#7ba3c849 to nil") } return b.Obj(func(b tdjson.Decoder, key []byte) error { switch string(key) { case tdjson.TypeField: if err := b.ConsumeID("notificationSounds"); err != nil { return fmt.Errorf("unable to decode notificationSounds#7ba3c849: %w", err) } case "notification_sounds": if err := b.Arr(func(b tdjson.Decoder) error { var value NotificationSound if err := value.DecodeTDLibJSON(b); err != nil { return fmt.Errorf("unable to decode notificationSounds#7ba3c849: field notification_sounds: %w", err) } n.NotificationSounds = append(n.NotificationSounds, value) return nil }); err != nil { return fmt.Errorf("unable to decode notificationSounds#7ba3c849: field notification_sounds: %w", err) } default: return b.Skip() } return nil }) } // GetNotificationSounds returns value of NotificationSounds field. func (n *NotificationSounds) GetNotificationSounds() (value []NotificationSound) { if n == nil { return } return n.NotificationSounds }