package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type ContactsSearchRequest struct {
Flags bin .Fields
Broadcasts bool
Bots bool
Q string
Limit int
}
const ContactsSearchRequestTypeID = 0x5f58d0f
var (
_ bin .Encoder = &ContactsSearchRequest {}
_ bin .Decoder = &ContactsSearchRequest {}
_ bin .BareEncoder = &ContactsSearchRequest {}
_ bin .BareDecoder = &ContactsSearchRequest {}
)
func (s *ContactsSearchRequest ) Zero () bool {
if s == nil {
return true
}
if !(s .Flags .Zero ()) {
return false
}
if !(s .Broadcasts == false ) {
return false
}
if !(s .Bots == false ) {
return false
}
if !(s .Q == "" ) {
return false
}
if !(s .Limit == 0 ) {
return false
}
return true
}
func (s *ContactsSearchRequest ) String () string {
if s == nil {
return "ContactsSearchRequest(nil)"
}
type Alias ContactsSearchRequest
return fmt .Sprintf ("ContactsSearchRequest%+v" , Alias (*s ))
}
func (s *ContactsSearchRequest ) FillFrom (from interface {
GetBroadcasts () (value bool )
GetBots () (value bool )
GetQ () (value string )
GetLimit () (value int )
}) {
s .Broadcasts = from .GetBroadcasts ()
s .Bots = from .GetBots ()
s .Q = from .GetQ ()
s .Limit = from .GetLimit ()
}
func (*ContactsSearchRequest ) TypeID () uint32 {
return ContactsSearchRequestTypeID
}
func (*ContactsSearchRequest ) TypeName () string {
return "contacts.search"
}
func (s *ContactsSearchRequest ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "contacts.search" ,
ID : ContactsSearchRequestTypeID ,
}
if s == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Broadcasts" ,
SchemaName : "broadcasts" ,
Null : !s .Flags .Has (0 ),
},
{
Name : "Bots" ,
SchemaName : "bots" ,
Null : !s .Flags .Has (1 ),
},
{
Name : "Q" ,
SchemaName : "q" ,
},
{
Name : "Limit" ,
SchemaName : "limit" ,
},
}
return typ
}
func (s *ContactsSearchRequest ) SetFlags () {
if !(s .Broadcasts == false ) {
s .Flags .Set (0 )
}
if !(s .Bots == false ) {
s .Flags .Set (1 )
}
}
func (s *ContactsSearchRequest ) Encode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode contacts.search#5f58d0f as nil" )
}
b .PutID (ContactsSearchRequestTypeID )
return s .EncodeBare (b )
}
func (s *ContactsSearchRequest ) EncodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode contacts.search#5f58d0f as nil" )
}
s .SetFlags ()
if err := s .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode contacts.search#5f58d0f: field flags: %w" , err )
}
b .PutString (s .Q )
b .PutInt (s .Limit )
return nil
}
func (s *ContactsSearchRequest ) Decode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode contacts.search#5f58d0f to nil" )
}
if err := b .ConsumeID (ContactsSearchRequestTypeID ); err != nil {
return fmt .Errorf ("unable to decode contacts.search#5f58d0f: %w" , err )
}
return s .DecodeBare (b )
}
func (s *ContactsSearchRequest ) DecodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode contacts.search#5f58d0f to nil" )
}
{
if err := s .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode contacts.search#5f58d0f: field flags: %w" , err )
}
}
s .Broadcasts = s .Flags .Has (0 )
s .Bots = s .Flags .Has (1 )
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode contacts.search#5f58d0f: field q: %w" , err )
}
s .Q = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode contacts.search#5f58d0f: field limit: %w" , err )
}
s .Limit = value
}
return nil
}
func (s *ContactsSearchRequest ) SetBroadcasts (value bool ) {
if value {
s .Flags .Set (0 )
s .Broadcasts = true
} else {
s .Flags .Unset (0 )
s .Broadcasts = false
}
}
func (s *ContactsSearchRequest ) GetBroadcasts () (value bool ) {
if s == nil {
return
}
return s .Flags .Has (0 )
}
func (s *ContactsSearchRequest ) SetBots (value bool ) {
if value {
s .Flags .Set (1 )
s .Bots = true
} else {
s .Flags .Unset (1 )
s .Bots = false
}
}
func (s *ContactsSearchRequest ) GetBots () (value bool ) {
if s == nil {
return
}
return s .Flags .Has (1 )
}
func (s *ContactsSearchRequest ) GetQ () (value string ) {
if s == nil {
return
}
return s .Q
}
func (s *ContactsSearchRequest ) GetLimit () (value int ) {
if s == nil {
return
}
return s .Limit
}
func (c *Client ) ContactsSearch (ctx context .Context , request *ContactsSearchRequest ) (*ContactsFound , error ) {
var result ContactsFound
if err := c .rpc .Invoke (ctx , request , &result ); err != nil {
return nil , err
}
return &result , nil
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .