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 MessagesTranslateTextRequest struct {
Flags bin .Fields
Peer InputPeerClass
ID []int
Text []TextWithEntities
ToLang string
}
const MessagesTranslateTextRequestTypeID = 0x63183030
var (
_ bin .Encoder = &MessagesTranslateTextRequest {}
_ bin .Decoder = &MessagesTranslateTextRequest {}
_ bin .BareEncoder = &MessagesTranslateTextRequest {}
_ bin .BareDecoder = &MessagesTranslateTextRequest {}
)
func (t *MessagesTranslateTextRequest ) Zero () bool {
if t == nil {
return true
}
if !(t .Flags .Zero ()) {
return false
}
if !(t .Peer == nil ) {
return false
}
if !(t .ID == nil ) {
return false
}
if !(t .Text == nil ) {
return false
}
if !(t .ToLang == "" ) {
return false
}
return true
}
func (t *MessagesTranslateTextRequest ) String () string {
if t == nil {
return "MessagesTranslateTextRequest(nil)"
}
type Alias MessagesTranslateTextRequest
return fmt .Sprintf ("MessagesTranslateTextRequest%+v" , Alias (*t ))
}
func (t *MessagesTranslateTextRequest ) FillFrom (from interface {
GetPeer () (value InputPeerClass , ok bool )
GetID () (value []int , ok bool )
GetText () (value []TextWithEntities , ok bool )
GetToLang () (value string )
}) {
if val , ok := from .GetPeer (); ok {
t .Peer = val
}
if val , ok := from .GetID (); ok {
t .ID = val
}
if val , ok := from .GetText (); ok {
t .Text = val
}
t .ToLang = from .GetToLang ()
}
func (*MessagesTranslateTextRequest ) TypeID () uint32 {
return MessagesTranslateTextRequestTypeID
}
func (*MessagesTranslateTextRequest ) TypeName () string {
return "messages.translateText"
}
func (t *MessagesTranslateTextRequest ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messages.translateText" ,
ID : MessagesTranslateTextRequestTypeID ,
}
if t == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Peer" ,
SchemaName : "peer" ,
Null : !t .Flags .Has (0 ),
},
{
Name : "ID" ,
SchemaName : "id" ,
Null : !t .Flags .Has (0 ),
},
{
Name : "Text" ,
SchemaName : "text" ,
Null : !t .Flags .Has (1 ),
},
{
Name : "ToLang" ,
SchemaName : "to_lang" ,
},
}
return typ
}
func (t *MessagesTranslateTextRequest ) SetFlags () {
if !(t .Peer == nil ) {
t .Flags .Set (0 )
}
if !(t .ID == nil ) {
t .Flags .Set (0 )
}
if !(t .Text == nil ) {
t .Flags .Set (1 )
}
}
func (t *MessagesTranslateTextRequest ) Encode (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't encode messages.translateText#63183030 as nil" )
}
b .PutID (MessagesTranslateTextRequestTypeID )
return t .EncodeBare (b )
}
func (t *MessagesTranslateTextRequest ) EncodeBare (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't encode messages.translateText#63183030 as nil" )
}
t .SetFlags ()
if err := t .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.translateText#63183030: field flags: %w" , err )
}
if t .Flags .Has (0 ) {
if t .Peer == nil {
return fmt .Errorf ("unable to encode messages.translateText#63183030: field peer is nil" )
}
if err := t .Peer .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.translateText#63183030: field peer: %w" , err )
}
}
if t .Flags .Has (0 ) {
b .PutVectorHeader (len (t .ID ))
for _ , v := range t .ID {
b .PutInt (v )
}
}
if t .Flags .Has (1 ) {
b .PutVectorHeader (len (t .Text ))
for idx , v := range t .Text {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.translateText#63183030: field text element with index %d: %w" , idx , err )
}
}
}
b .PutString (t .ToLang )
return nil
}
func (t *MessagesTranslateTextRequest ) Decode (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't decode messages.translateText#63183030 to nil" )
}
if err := b .ConsumeID (MessagesTranslateTextRequestTypeID ); err != nil {
return fmt .Errorf ("unable to decode messages.translateText#63183030: %w" , err )
}
return t .DecodeBare (b )
}
func (t *MessagesTranslateTextRequest ) DecodeBare (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't decode messages.translateText#63183030 to nil" )
}
{
if err := t .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messages.translateText#63183030: field flags: %w" , err )
}
}
if t .Flags .Has (0 ) {
value , err := DecodeInputPeer (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.translateText#63183030: field peer: %w" , err )
}
t .Peer = value
}
if t .Flags .Has (0 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode messages.translateText#63183030: field id: %w" , err )
}
if headerLen > 0 {
t .ID = make ([]int , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.translateText#63183030: field id: %w" , err )
}
t .ID = append (t .ID , value )
}
}
if t .Flags .Has (1 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode messages.translateText#63183030: field text: %w" , err )
}
if headerLen > 0 {
t .Text = make ([]TextWithEntities , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value TextWithEntities
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messages.translateText#63183030: field text: %w" , err )
}
t .Text = append (t .Text , value )
}
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode messages.translateText#63183030: field to_lang: %w" , err )
}
t .ToLang = value
}
return nil
}
func (t *MessagesTranslateTextRequest ) SetPeer (value InputPeerClass ) {
t .Flags .Set (0 )
t .Peer = value
}
func (t *MessagesTranslateTextRequest ) GetPeer () (value InputPeerClass , ok bool ) {
if t == nil {
return
}
if !t .Flags .Has (0 ) {
return value , false
}
return t .Peer , true
}
func (t *MessagesTranslateTextRequest ) SetID (value []int ) {
t .Flags .Set (0 )
t .ID = value
}
func (t *MessagesTranslateTextRequest ) GetID () (value []int , ok bool ) {
if t == nil {
return
}
if !t .Flags .Has (0 ) {
return value , false
}
return t .ID , true
}
func (t *MessagesTranslateTextRequest ) SetText (value []TextWithEntities ) {
t .Flags .Set (1 )
t .Text = value
}
func (t *MessagesTranslateTextRequest ) GetText () (value []TextWithEntities , ok bool ) {
if t == nil {
return
}
if !t .Flags .Has (1 ) {
return value , false
}
return t .Text , true
}
func (t *MessagesTranslateTextRequest ) GetToLang () (value string ) {
if t == nil {
return
}
return t .ToLang
}
func (c *Client ) MessagesTranslateText (ctx context .Context , request *MessagesTranslateTextRequest ) (*MessagesTranslateResult , error ) {
var result MessagesTranslateResult
if err := c .rpc .Invoke (ctx , request , &result ); err != nil {
return nil , err
}
return &result , nil
}
The pages are generated with Golds v0.6.7 . (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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds .