move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.interfaceConfig*/ -}}
|
||||
{{ define "box" }}{{ $f := .Interface }}
|
||||
// Decode{{ $f.Func }} implements binary de-serialization for {{ $f.Name }}.
|
||||
func Decode{{ $f.Func }} (buf *bin.Buffer) ({{ $f.Name }}, error) {
|
||||
id, err := buf.PeekID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch id {
|
||||
{{- range $c := $f.Constructors }}
|
||||
case {{ $c.Name }}TypeID:
|
||||
// Decoding {{ $c.RawType }}.
|
||||
v := {{ $c.Name }}{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode {{ $f.Name }}: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
{{- end }}
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to decode {{ $f.Name }}: %w", bin.NewUnexpectedID(id))
|
||||
}
|
||||
}
|
||||
|
||||
{{- if $.Config.Flags.TDLibJSON }}
|
||||
// DecodeTDLibJSON{{ $f.Func }} implements binary de-serialization for {{ $f.Name }}.
|
||||
func DecodeTDLibJSON{{ $f.Func }} (buf tdjson.Decoder) ({{ $f.Name }}, error) {
|
||||
id, err := buf.FindTypeID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch id {
|
||||
{{- range $c := $f.Constructors }}
|
||||
case "{{ $c.RawName }}":
|
||||
// Decoding {{ $c.RawType }}.
|
||||
v := {{ $c.Name }}{}
|
||||
if err := v.DecodeTDLibJSON(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode {{ $f.Name }}: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
{{- end }}
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to decode {{ $f.Name }}: %w", tdjson.NewUnexpectedID(id))
|
||||
}
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
// {{ $f.Func }} boxes the {{ $f.Name }} providing a helper.
|
||||
type {{ $f.Func }}Box struct {
|
||||
{{ $f.BaseName }} {{ $f.Name }}
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder for {{ $f.Func }}Box.
|
||||
func (b *{{ $f.Func }}Box) Decode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("unable to decode {{ $f.Func }}Box to nil")
|
||||
}
|
||||
v, err := Decode{{ $f.Func }}(buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode boxed value: %w", err)
|
||||
}
|
||||
b.{{ $f.BaseName }} = v
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode implements bin.Encode for {{ $f.Func }}Box.
|
||||
func (b *{{ $f.Func }}Box) Encode(buf *bin.Buffer) error {
|
||||
if b == nil || b.{{ $f.BaseName }} == nil {
|
||||
return fmt.Errorf("unable to encode {{ $f.Name }} as nil")
|
||||
}
|
||||
return b.{{ $f.BaseName }}.Encode(buf)
|
||||
}
|
||||
|
||||
{{- if $.Config.Flags.TDLibJSON }}
|
||||
// DecodeTDLibJSON implements bin.Decoder for {{ $f.Func }}Box.
|
||||
func (b *{{ $f.Func }}Box) DecodeTDLibJSON(buf tdjson.Decoder) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("unable to decode {{ $f.Func }}Box to nil")
|
||||
}
|
||||
v, err := DecodeTDLibJSON{{ $f.Func }}(buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode boxed value: %w", err)
|
||||
}
|
||||
b.{{ $f.BaseName }} = v
|
||||
return nil
|
||||
}
|
||||
|
||||
// EncodeTDLibJSON implements bin.Encode for {{ $f.Func }}Box.
|
||||
func (b *{{ $f.Func }}Box) EncodeTDLibJSON(buf tdjson.Encoder) error {
|
||||
if b == nil || b.{{ $f.BaseName }} == nil {
|
||||
return fmt.Errorf("unable to encode {{ $f.Name }} as nil")
|
||||
}
|
||||
return b.{{ $f.BaseName }}.EncodeTDLibJSON(buf)
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
{{ end }}
|
||||
@@ -0,0 +1,27 @@
|
||||
{{ define "client" }}
|
||||
{{ $pkg := $.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
// Invoker can invoke raw MTProto rpc calls.
|
||||
type Invoker interface {
|
||||
Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder) error
|
||||
}
|
||||
|
||||
// Client implement methods for calling functions from TL schema via Invoker.
|
||||
type Client struct {
|
||||
rpc Invoker
|
||||
}
|
||||
|
||||
// Invoker returns Invoker used by this client.
|
||||
func (c *Client) Invoker() Invoker {
|
||||
return c.rpc
|
||||
}
|
||||
|
||||
// NewClient creates new Client.
|
||||
func NewClient(invoker Invoker) *Client {
|
||||
return &Client{
|
||||
rpc: invoker,
|
||||
}
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
@@ -0,0 +1,101 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
{{ define "decode" }}{{ $s := . }}
|
||||
// Decode implements bin.Decoder.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) Decode({{ $s.BufArg }} *bin.Buffer) error {
|
||||
if {{ $s.Receiver }} == nil {
|
||||
return fmt.Errorf("can't decode {{ $s.RawType }} to nil")
|
||||
}
|
||||
{{ if not $s.Vector -}}
|
||||
if err := {{ $s.BufArg }}.ConsumeID({{ $s.Name }}TypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: %w", err)
|
||||
}
|
||||
{{- end }}
|
||||
return {{ $s.Receiver }}.DecodeBare({{ $s.BufArg }})
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) DecodeBare({{ $s.BufArg }} *bin.Buffer) error {
|
||||
if {{ $s.Receiver }} == nil {
|
||||
return fmt.Errorf("can't decode {{ $s.RawType }} to nil")
|
||||
}
|
||||
{{- range $f := $s.Fields }}
|
||||
{{- if $f.ConditionalBool }}
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = {{ $s.Receiver }}.{{ $f.ConditionalField }}.Has({{ $f.ConditionalIndex }})
|
||||
{{- else }}
|
||||
{{- if $f.Conditional}}
|
||||
if {{ $s.Receiver }}.{{ $f.ConditionalField }}.Has({{ $f.ConditionalIndex }}) {
|
||||
{{- else}}
|
||||
{
|
||||
{{- end }}
|
||||
{{- if $f.Vector }}
|
||||
headerLen, err := {{ if $f.BareVector }}{{ $s.BufArg }}.Int(){{ else }}{{ $s.BufArg }}.VectorHeader(){{ end }}
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = make({{ template "print_type" $f }}, 0, headerLen % bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
|
||||
{{- if $f.DoubleVector }}
|
||||
innerLen, err := {{ $s.BufArg }}.VectorHeader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
|
||||
var row []{{ $f.Type }}
|
||||
if innerLen > 0 {
|
||||
row = make([]{{ $f.Type }}, 0, innerLen % bin.PreallocateLimit)
|
||||
}
|
||||
for innerIndex := 0; innerIndex < innerLen; innerLen++ {
|
||||
{{- end }}
|
||||
{{- if $f.Interface }}
|
||||
value, err := Decode{{ $f.InterfaceFunc }}({{ $s.BufArg }})
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- else if $f.Encoder }}
|
||||
var value {{ $f.Type }}
|
||||
if err := value.Decode{{ if and $f.BareEncoder $f.BareVector }}Bare{{ end }}({{ $s.BufArg }}); err != nil {
|
||||
return fmt.Errorf("unable to decode{{ if and $f.BareEncoder $f.BareVector }} bare{{ end }} {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- else}}
|
||||
value, err := {{ $s.BufArg }}.{{ $f.Func }}()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- end }}
|
||||
{{- if $f.DoubleVector }}
|
||||
row = append(row, value)
|
||||
}
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = append({{ $s.Receiver }}.{{ $f.Name }}, row)
|
||||
{{- else }}
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = append({{ $s.Receiver }}.{{ $f.Name }}, value)
|
||||
{{- end }}
|
||||
}
|
||||
{{- else }}
|
||||
{{- if $f.Interface }}
|
||||
value, err := Decode{{ $f.InterfaceFunc }}({{ $s.BufArg }})
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = value
|
||||
{{- else if $f.Encoder }}
|
||||
if err := {{ $s.Receiver }}.{{ $f.Name }}.Decode({{ $s.BufArg }}); err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- else }}
|
||||
value, err := {{ $s.BufArg }}.{{ $f.Func }}()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = value
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
return nil
|
||||
}
|
||||
{{ end }}
|
||||
@@ -0,0 +1,85 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
{{ define "decode_tdlib_json" }}{{ $s := . }}
|
||||
// DecodeTDLibJSON implements tdjson.TDLibDecoder.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) DecodeTDLibJSON({{ $s.BufArg }} tdjson.Decoder) error {
|
||||
if {{ $s.Receiver }} == nil {
|
||||
return fmt.Errorf("can't decode {{ $s.RawType }} to nil")
|
||||
}
|
||||
|
||||
return {{ $s.BufArg }}.Obj(func({{ $s.BufArg }} tdjson.Decoder, key []byte) error {
|
||||
switch string(key) {
|
||||
case tdjson.TypeField:
|
||||
if err := {{ $s.BufArg }}.ConsumeID("{{ $s.RawName }}"); err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: %w", err)
|
||||
}
|
||||
{{- range $f := $s.Fields }}
|
||||
case "{{ $f.RawName }}":
|
||||
{{- if or $f.ConditionalBool $f.Conditional }}
|
||||
{{ $s.Receiver }}.{{ $f.ConditionalField }}.Set({{ $f.ConditionalIndex }})
|
||||
{{- end }}
|
||||
{{- if $f.Vector }}
|
||||
if err := {{ $s.BufArg }}.Arr(func({{ $s.BufArg }} tdjson.Decoder) error {
|
||||
|
||||
{{- if $f.DoubleVector }}
|
||||
var row []{{ $f.Type }}
|
||||
if err := {{ $s.BufArg }}.Arr(func({{ $s.BufArg }} tdjson.Decoder) error {
|
||||
{{- end }}
|
||||
{{- if $f.Interface }}
|
||||
value, err := DecodeTDLibJSON{{ $f.InterfaceFunc }}({{ $s.BufArg }})
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- else if $f.Encoder }}
|
||||
var value {{ $f.Type }}
|
||||
if err := value.DecodeTDLibJSON({{ $s.BufArg }}); err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- else}}
|
||||
value, err := {{ $s.BufArg }}.{{ $f.Func }}()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- end }}
|
||||
{{- if $f.DoubleVector }}
|
||||
row = append(row, value)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = append({{ $s.Receiver }}.{{ $f.Name }}, row)
|
||||
{{- else }}
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = append({{ $s.Receiver }}.{{ $f.Name }}, value)
|
||||
{{- end }}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- else }}
|
||||
{{- if $f.Interface }}
|
||||
value, err := DecodeTDLibJSON{{ $f.InterfaceFunc }}({{ $s.BufArg }})
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = value
|
||||
{{- else if $f.Encoder }}
|
||||
{{- if not (eq $f.Type "bin.Fields") }}
|
||||
if err := {{ $s.Receiver }}.{{ $f.Name }}.DecodeTDLibJSON({{ $s.BufArg }}); err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
value, err := {{ $s.BufArg }}.{{ $f.Func }}()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = value
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
default:
|
||||
return {{ $s.BufArg }}.Skip()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
{{ end }}
|
||||
@@ -0,0 +1,71 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
{{ define "encode" }}{{ $s := . }}
|
||||
// Encode implements bin.Encoder.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) Encode({{ $s.BufArg }} *bin.Buffer) error {
|
||||
if {{ $s.Receiver }} == nil {
|
||||
return fmt.Errorf("can't encode {{ $s.RawType }} as nil")
|
||||
}
|
||||
{{ if not $s.Vector -}}
|
||||
{{ $s.BufArg }}.PutID({{ $s.Name }}TypeID)
|
||||
{{- end }}
|
||||
return {{ $s.Receiver }}.EncodeBare({{ $s.BufArg }})
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) EncodeBare({{ $s.BufArg }} *bin.Buffer) error {
|
||||
if {{ $s.Receiver }} == nil {
|
||||
return fmt.Errorf("can't encode {{ $s.RawType }} as nil")
|
||||
}
|
||||
{{- if hasFlags $s }}
|
||||
{{ $s.Receiver }}.SetFlags()
|
||||
{{- end }}
|
||||
{{- range $f := $s.Fields }}
|
||||
{{- if not $f.ConditionalBool }}
|
||||
{{- if $f.Conditional }}
|
||||
if {{ $s.Receiver }}.{{ $f.ConditionalField }}.Has({{ $f.ConditionalIndex }}) {
|
||||
{{- end }}
|
||||
{{- if $f.Vector }}
|
||||
{{ if not $f.BareVector }}{{ $s.BufArg }}.PutVectorHeader(len({{ $s.Receiver }}.{{ $f.Name }})){{ else }}{{ $s.BufArg }}.PutInt(len({{ $s.Receiver }}.{{ $f.Name }})){{- end }}
|
||||
for {{ if $f.Encoder }}idx{{ else }}_{{ end }}, {{- if $f.DoubleVector }}row{{else}}v{{end}} := range {{ $s.Receiver }}.{{ $f.Name }} {
|
||||
{{- if $f.DoubleVector }}
|
||||
{{ $s.BufArg }}.PutVectorHeader(len(row))
|
||||
for _, v := range row {
|
||||
{{- end }}
|
||||
{{- if $f.Encoder }}
|
||||
{{- if $f.Interface }}
|
||||
if v == nil {
|
||||
return fmt.Errorf("unable to encode {{ $s.RawType }}: field {{ $f.RawName }} element with index %d is nil", idx)
|
||||
}
|
||||
{{- end}}
|
||||
if err := v.Encode{{ if and $f.BareEncoder $f.BareVector }}Bare{{ end }}({{ $s.BufArg }}); err != nil {
|
||||
return fmt.Errorf("unable to encode{{ if and $f.BareEncoder $f.BareVector }} bare{{ end }} {{ $s.RawType }}: field {{ $f.RawName }} element with index %d: %w", idx, err)
|
||||
}
|
||||
{{- else }}
|
||||
{{ $s.BufArg }}.Put{{ $f.Func }}(v)
|
||||
{{- end }}
|
||||
{{- if $f.DoubleVector }}
|
||||
}
|
||||
{{- end }}
|
||||
}
|
||||
{{- else }}
|
||||
{{- if $f.Encoder }}
|
||||
{{- if $f.Interface }}
|
||||
if {{ $s.Receiver }}.{{ $f.Name }} == nil {
|
||||
return fmt.Errorf("unable to encode {{ $s.RawType }}: field {{ $f.RawName }} is nil")
|
||||
}
|
||||
{{- end}}
|
||||
if err := {{ $s.Receiver }}.{{ $f.Name }}.Encode({{ $s.BufArg }}); err != nil {
|
||||
return fmt.Errorf("unable to encode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- else }}
|
||||
{{ $s.BufArg }}.Put{{ $f.Func }}({{ $s.Receiver }}.{{ $f.Name }})
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if $f.Conditional }}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
return nil
|
||||
}
|
||||
{{ end }}
|
||||
@@ -0,0 +1,75 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
{{ define "encode_tdlib_json" }}{{ $s := . }}
|
||||
// EncodeTDLibJSON implements tdjson.TDLibEncoder.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) EncodeTDLibJSON({{ $s.BufArg }} tdjson.Encoder) error {
|
||||
if {{ $s.Receiver }} == nil {
|
||||
return fmt.Errorf("can't encode {{ $s.RawType }} as nil")
|
||||
}
|
||||
{{ $s.BufArg }}.ObjStart()
|
||||
{{ $s.BufArg }}.PutID("{{ $s.RawName }}")
|
||||
{{ $s.BufArg }}.Comma()
|
||||
{{- if hasFlags $s }}
|
||||
{{ $s.Receiver }}.SetFlags()
|
||||
{{- end }}
|
||||
{{- range $i, $f := $s.Fields }}
|
||||
{{- if not $f.ConditionalBool }}
|
||||
{{- if $f.Conditional }}
|
||||
if {{ $s.Receiver }}.{{ $f.ConditionalField }}.Has({{ $f.ConditionalIndex }}) {
|
||||
{{- end }}
|
||||
{{ $s.BufArg }}.FieldStart("{{ $f.RawName }}")
|
||||
{{- if $f.Vector }}
|
||||
{{ $s.BufArg }}.ArrStart()
|
||||
for {{ if $f.Encoder }}idx{{ else }}_{{ end }}, {{- if $f.DoubleVector }}row{{else}}v{{end}} := range {{ $s.Receiver }}.{{ $f.Name }} {
|
||||
{{- if $f.DoubleVector }}
|
||||
{{ $s.BufArg }}.ArrStart()
|
||||
for _, v := range row {
|
||||
{{- end }}
|
||||
{{- if $f.Encoder }}
|
||||
{{- if $f.Interface }}
|
||||
if v == nil {
|
||||
return fmt.Errorf("unable to encode {{ $s.RawType }}: field {{ $f.RawName }} element with index %d is nil", idx)
|
||||
}
|
||||
{{- end }}
|
||||
if err := v.EncodeTDLibJSON({{ $s.BufArg }}); err != nil {
|
||||
return fmt.Errorf("unable to encode {{ $s.RawType }}: field {{ $f.RawName }} element with index %d: %w", idx, err)
|
||||
}
|
||||
{{- else }}
|
||||
{{ $s.BufArg }}.Put{{ $f.Func }}(v)
|
||||
{{- end }}
|
||||
{{ $s.BufArg }}.Comma()
|
||||
{{- if $f.DoubleVector }}
|
||||
}
|
||||
{{ $s.BufArg }}.StripComma()
|
||||
{{ $s.BufArg }}.ArrEnd()
|
||||
{{ $s.BufArg }}.Comma()
|
||||
{{- end }}
|
||||
}
|
||||
{{ $s.BufArg }}.StripComma()
|
||||
{{ $s.BufArg }}.ArrEnd()
|
||||
{{- else }}
|
||||
{{- if $f.Encoder }}
|
||||
{{- if $f.Interface }}
|
||||
if {{ $s.Receiver }}.{{ $f.Name }} == nil {
|
||||
return fmt.Errorf("unable to encode {{ $s.RawType }}: field {{ $f.RawName }} is nil")
|
||||
}
|
||||
{{- end }}
|
||||
{{- if not (eq $f.Type "bin.Fields") }}
|
||||
if err := {{ $s.Receiver }}.{{ $f.Name }}.EncodeTDLibJSON({{ $s.BufArg }}); err != nil {
|
||||
return fmt.Errorf("unable to encode {{ $s.RawType }}: field {{ $f.RawName }}: %w", err)
|
||||
}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{ $s.BufArg }}.Put{{ $f.Func }}({{ $s.Receiver }}.{{ $f.Name }})
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if $f.Conditional }}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{ $s.BufArg }}.Comma()
|
||||
{{- end }}
|
||||
{{ $s.BufArg }}.StripComma()
|
||||
{{ $s.BufArg }}.ObjEnd()
|
||||
return nil
|
||||
}
|
||||
{{ end }}
|
||||
@@ -0,0 +1,21 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.config*/ -}}
|
||||
|
||||
{{ define "errors" }}
|
||||
{{ $pkg := $.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
// Telegram API error types.
|
||||
const (
|
||||
{{- range $s := $.Errors }}
|
||||
Err{{ $s.Name }} = "{{ $s.Type }}"
|
||||
{{- end }}
|
||||
)
|
||||
|
||||
{{- range $s := $.Errors }}
|
||||
// Is{{ $s.Name }} reports whether err is {{ $s.Type }}.
|
||||
func Is{{ $s.Name }}(err error) bool {
|
||||
return tgerr.Is(err, Err{{ $s.Name }})
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ end }}
|
||||
@@ -0,0 +1,48 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structConfig*/ -}}
|
||||
{{ define "field_mapping" }}{{- $s := .Struct -}}
|
||||
|
||||
{{- range $f := $s.Fields }}{{ if and (not $f.DoubleSlice) (ne ($f.Type) ("bin.Fields")) }}
|
||||
{{ if not $f.Slice }}
|
||||
|
||||
{{- $mappings := index ($.Config.Mappings) ($f.Type) -}}
|
||||
{{- range $mapping := $mappings }}{{- if (not $mapping.Constructor) }}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.constructorMapping*/ -}}
|
||||
// Get{{ $f.Name }}As{{ $mapping.MapperName }} returns mapped value of {{ $f.Name }} {{ if $f.Conditional }}
|
||||
{{- if not ($f.ConditionalBool) }}conditional field and
|
||||
// boolean which is true if field was set.
|
||||
{{- else }}conditional field.
|
||||
{{- end }}
|
||||
{{- else }}field.
|
||||
{{- end }}
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) Get{{ $f.Name }}As{{ $mapping.MapperName }}() ({{ template "print_mapper_type" $mapping }}, bool) {
|
||||
{{- if $f.Conditional }}
|
||||
if value, ok := {{ $s.Receiver }}.Get{{ $f.Name }}(); ok {
|
||||
return value.As{{ $mapping.MapperName }}()
|
||||
}
|
||||
return nil, false
|
||||
{{- else }}
|
||||
return {{ $s.Receiver }}.{{ $f.Name }}.As{{ $mapping.MapperName }}()
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}{{- end }}
|
||||
|
||||
{{- else }}
|
||||
|
||||
{{- if $f.Interface }}
|
||||
// Map{{ $f.Name }} returns field {{ $f.Name }} wrapped in {{ template "slice_field_name" $f }} helper.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) Map{{ $f.Name }}() (value {{ template "slice_field_name" $f }}{{ if $f.Conditional }}, ok bool{{ end }}) {
|
||||
{{- if $f.Conditional }}
|
||||
if !{{ $s.Receiver }}.{{ $f.ConditionalField }}.Has({{ $f.ConditionalIndex }}) {
|
||||
return value, false
|
||||
}
|
||||
return {{ template "slice_field_name" $f }}({{ $s.Receiver }}.{{ $f.Name }}), true
|
||||
{{- else }}
|
||||
return {{ template "slice_field_name" $f }}({{ $s.Receiver }}.{{ $f.Name }})
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
{{- end }}
|
||||
{{- end }}{{- end }}
|
||||
|
||||
{{ end }}
|
||||
@@ -0,0 +1,20 @@
|
||||
{{ define "fill_from" }}{{ $s := . }}{{ if $s.Fields }}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
// FillFrom fills {{ $s.Name }} from given interface.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) FillFrom(from interface{
|
||||
{{- range $f := $s.Fields }}{{ if ne ($f.Type) ("bin.Fields") }}
|
||||
{{ template "getter_func_type" $f }}
|
||||
{{- end }}{{- end }}
|
||||
}) {
|
||||
{{- range $f := $s.Fields }}{{ if ne ($f.Type) ("bin.Fields") }}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.fieldDef*/ -}}
|
||||
{{- if and ($f.Conditional) (not $f.ConditionalBool) }}
|
||||
if val, ok := from.Get{{ $f.Name }}(); ok {
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = val
|
||||
}
|
||||
{{ else }}
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = from.Get{{ $f.Name }}()
|
||||
{{- end }}
|
||||
{{- end }}{{- end }}
|
||||
}
|
||||
{{ end }}{{ end }}
|
||||
@@ -0,0 +1,48 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
{{ define "getset" }}{{ $s := . }}
|
||||
|
||||
{{- range $f := $s.Fields }}{{ if ne ($f.Type) ("bin.Fields") }}
|
||||
{{ if $f.Conditional }}
|
||||
// Set{{ $f.Name }} sets value of {{ $f.Name }} conditional field.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) Set{{ $f.Name }}(value {{ template "print_type" $f }}) {
|
||||
{{- if $f.ConditionalBool }}
|
||||
if value {
|
||||
{{ $s.Receiver }}.{{ $f.ConditionalField }}.Set({{ $f.ConditionalIndex }})
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = true
|
||||
} else {
|
||||
{{ $s.Receiver }}.{{ $f.ConditionalField }}.Unset({{ $f.ConditionalIndex }})
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = false
|
||||
}
|
||||
{{- else }}
|
||||
{{ $s.Receiver }}.{{ $f.ConditionalField }}.Set({{ $f.ConditionalIndex }})
|
||||
{{ $s.Receiver }}.{{ $f.Name }} = value
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
// Get{{ $f.Name }} returns value of {{ $f.Name }} {{ if $f.Conditional }}
|
||||
{{- if not ($f.ConditionalBool) }}conditional field and
|
||||
// boolean which is true if field was set.
|
||||
{{- else }}conditional field.
|
||||
{{- end }}
|
||||
{{- else }}field.
|
||||
{{- end }}
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) {{ template "getter_func_type" $f }} {
|
||||
if {{ $s.Receiver }} == nil {
|
||||
return
|
||||
}
|
||||
{{- if $f.Conditional }}{{ if not ($f.ConditionalBool) }}
|
||||
if !{{ $s.Receiver }}.{{ $f.ConditionalField }}.Has({{ $f.ConditionalIndex }}) {
|
||||
return value, false
|
||||
}
|
||||
return {{ $s.Receiver }}.{{ $f.Name }}, true
|
||||
{{- else }}
|
||||
return {{ $s.Receiver }}.{{ $f.ConditionalField }}.Has({{ $f.ConditionalIndex }})
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
return {{ $s.Receiver }}.{{ $f.Name }}
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}{{- end }}
|
||||
|
||||
{{ end }}
|
||||
@@ -0,0 +1,93 @@
|
||||
{{ define "handlers" }}
|
||||
{{ $pkg := $.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
type handler = func(context.Context, Entities, UpdateClass) error
|
||||
|
||||
type UpdateDispatcher struct {
|
||||
handlers map[uint32]handler
|
||||
}
|
||||
|
||||
func NewUpdateDispatcher() UpdateDispatcher {
|
||||
return UpdateDispatcher{
|
||||
handlers: map[uint32]handler{},
|
||||
}
|
||||
}
|
||||
|
||||
type Entities struct {
|
||||
Short bool
|
||||
Users map[int64]*User
|
||||
Chats map[int64]*Chat
|
||||
Channels map[int64]*Channel
|
||||
}
|
||||
|
||||
func (u *Entities) short() {
|
||||
u.Short = true
|
||||
u.Users = make(map[int64]*User, 0)
|
||||
u.Chats = make(map[int64]*Chat, 0)
|
||||
u.Channels = make(map[int64]*Channel, 0)
|
||||
}
|
||||
|
||||
// Handle implements UpdateDispatcher.
|
||||
func (u UpdateDispatcher) Handle(ctx context.Context, updates UpdatesClass) error {
|
||||
var (
|
||||
e Entities
|
||||
upds []UpdateClass
|
||||
)
|
||||
switch u := updates.(type) {
|
||||
case *Updates:
|
||||
upds = u.Updates
|
||||
e.Users = u.MapUsers().NotEmptyToMap()
|
||||
chats := u.MapChats()
|
||||
e.Chats = chats.ChatToMap()
|
||||
e.Channels = chats.ChannelToMap()
|
||||
case *UpdatesCombined:
|
||||
upds = u.Updates
|
||||
e.Users = u.MapUsers().NotEmptyToMap()
|
||||
chats := u.MapChats()
|
||||
e.Chats = chats.ChatToMap()
|
||||
e.Channels = chats.ChannelToMap()
|
||||
case *UpdateShort:
|
||||
upds = []UpdateClass{u.Update}
|
||||
e.short()
|
||||
default:
|
||||
// *UpdateShortMessage
|
||||
// *UpdateShortChatMessage
|
||||
// *UpdateShortSentMessage
|
||||
// *UpdatesTooLong
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
for _, update := range upds {
|
||||
multierr.AppendInto(&err, u.dispatch(ctx, e, update))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (u UpdateDispatcher) dispatch(ctx context.Context, e Entities, update UpdateClass) error {
|
||||
if update == nil {
|
||||
return nil
|
||||
}
|
||||
typeID := update.TypeID()
|
||||
handler, ok := u.handlers[typeID]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return handler(ctx, e, update)
|
||||
}
|
||||
|
||||
{{- range $s := $.Structs }}{{ if eq $s.Interface "UpdateClass" }}
|
||||
{{ $eventName := trimPrefix $s.Name "Update"}}
|
||||
// {{ $eventName }}Handler is a {{ $eventName }} event handler.
|
||||
type {{ $eventName }}Handler func(ctx context.Context, e Entities, update *{{ $s.Name }}) error
|
||||
|
||||
// On{{ $eventName }} sets {{ $eventName }} handler.
|
||||
func (u UpdateDispatcher) On{{ $eventName }}(handler {{ $eventName }}Handler) {
|
||||
u.handlers[{{ $s.Name }}TypeID] = func(ctx context.Context, e Entities, update UpdateClass) error {
|
||||
return handler(ctx, e, update.(*{{ $s.Name }}))
|
||||
}
|
||||
}
|
||||
{{- end }}{{ end }}
|
||||
|
||||
{{ end }}
|
||||
@@ -0,0 +1,36 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.config*/ -}}
|
||||
{{ define "header" }}
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package {{ $.Package }}
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
{{ end }}
|
||||
@@ -0,0 +1,58 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.interfaceConfig*/ -}}
|
||||
{{ define "interface" }}{{ $f := .Interface }}
|
||||
|
||||
// {{ $f.Name }}Name is schema name of {{ $f.Name }}.
|
||||
const {{ $f.Name }}Name = "{{ $f.RawType }}"
|
||||
|
||||
// {{ $f.Name }} represents {{ $f.RawType }} generic type.
|
||||
//
|
||||
{{- if $f.URL }}
|
||||
// See {{ $f.URL }} for reference.
|
||||
//
|
||||
{{- end }}
|
||||
// Example:
|
||||
// g, err := {{ $.Config.Package }}.Decode{{ $f.Func }}(buf)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// switch v := g.(type) {
|
||||
{{ range $c := $f.Constructors -}}
|
||||
// case *{{ $.Config.Package }}.{{ $c.Name }}: // {{ $c.RawType }}
|
||||
{{ end -}}
|
||||
// default: panic(v)
|
||||
// }
|
||||
type {{ $f.Name }} interface {
|
||||
{{ template "class_interface_header" $f }}
|
||||
|
||||
{{ if $.Config.Flags.TDLibJSON }}
|
||||
EncodeTDLibJSON(b tdjson.Encoder) error
|
||||
DecodeTDLibJSON(b tdjson.Decoder) error
|
||||
{{- end }}
|
||||
|
||||
{{ range $field := $f.SharedFields.Common -}}
|
||||
{{- template "print_comment" $field.Comment }}
|
||||
{{- if $field.Links }}
|
||||
{{- template "print_links" $field.Links }}
|
||||
{{- end }}
|
||||
{{ if $.Config.Flags.GetSet }}{{ template "getter_func_type" $field -}}{{ end }}
|
||||
|
||||
{{- if and ($.Config.Flags.Mapping) (not $field.DoubleSlice) }}
|
||||
{{- if not $field.Slice }}
|
||||
{{- $mappings := index ($.Config.Mappings) ($field.Type) -}}
|
||||
{{- range $mapping := $mappings -}}
|
||||
{{- template "print_comment" $field.Comment }}
|
||||
Get{{ $field.Name }}As{{ $mapping.MapperName }}() ({{ template "print_mapper_type" $mapping }}, bool)
|
||||
{{- end }}
|
||||
{{ else }}{{- if $field.Interface }}
|
||||
{{- template "print_comment" $field.Comment }}
|
||||
Map{{ $field.Name }}() (value {{ template "slice_field_name" $field }}{{ if $field.Conditional }}, ok bool{{ end }})
|
||||
{{- end }}{{- end }}
|
||||
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{ range $mapping := $f.Mappings -}}{{- if and ($.Config.Flags.Mapping) (not $mapping.Constructor) -}}
|
||||
// As{{ $mapping.MapperName }} tries to map {{ $f.Name }} to {{ $mapping.Name }}.
|
||||
{{ template "mapper_func_type" $mapping }}
|
||||
{{ end }}{{ end }}
|
||||
}
|
||||
{{ end }}
|
||||
@@ -0,0 +1,56 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.interfaceDef*/ -}}
|
||||
{{ define "interface_mapping" }}{{ $f := . }}
|
||||
{{ range $mapping := $f.Mappings -}}
|
||||
|
||||
{{- if not ($mapping.Concrete) }}
|
||||
// {{ $mapping.Name }} represents {{ $mapping.MapperName }} subset of {{ $f.Name }}.
|
||||
type {{ $mapping.Name }} interface {
|
||||
{{ template "class_interface_header" $f }}
|
||||
|
||||
{{ range $field := index ($f.SharedFields) ($mapping.MapperName) -}}{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.fieldDef*/ -}}
|
||||
{{- template "print_comment" $field.Comment }}
|
||||
{{- if $field.Links }}
|
||||
{{- template "print_links" $field.Links }}
|
||||
{{- end }}
|
||||
{{ template "getter_func_type" $field}}
|
||||
{{ end }}
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
{{ range $s := $f.Constructors -}}{{- if or (not $mapping.Constructor) (eq ($s.Name) ($mapping.Constructor)) }}
|
||||
// As{{ $mapping.MapperName }} tries to map {{ $s.Name }} to {{ $mapping.Name }}.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) {{ template "mapper_func_type" $mapping }} {
|
||||
{{- if not ($mapping.Concrete) }}
|
||||
value, ok := ({{ $f.Name }}({{ $s.Receiver }})).({{ $mapping.Name }})
|
||||
return value, ok
|
||||
{{- else }}{{- if $mapping.Fields }}
|
||||
value := new({{ $mapping.Name }})
|
||||
{{- range $pair := $mapping.Fields -}}
|
||||
{{- if and ($pair.L.Conditional) (not $pair.L.ConditionalBool) }}
|
||||
if fieldValue, ok := {{ $s.Receiver }}.Get{{ $pair.L.Name }}(); ok {
|
||||
{{- if $pair.R.Conditional }}
|
||||
value.Set{{ $pair.R.Name }}(fieldValue)
|
||||
{{- else }}
|
||||
value.{{ $pair.R.Name }} = fieldValue
|
||||
{{- end }}
|
||||
}
|
||||
{{ else }}
|
||||
{{- if $pair.R.Conditional -}}
|
||||
value.Set{{ $pair.R.Name }}({{ $s.Receiver }}.Get{{ $pair.L.Name }}())
|
||||
{{- else }}
|
||||
value.{{ $pair.R.Name }} = {{ $s.Receiver }}.Get{{ $pair.L.Name }}()
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
return value
|
||||
{{- else }}
|
||||
{{- if eq ($s.Name) ($mapping.Name) }} return {{ $s.Receiver }}, true
|
||||
{{- else }} return nil, false {{ end }}
|
||||
{{- end }}{{- end }}
|
||||
}
|
||||
{{ end }}{{ end }}
|
||||
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.interfaceDef*/ -}}
|
||||
{{ define "interface_slice" }}{{ $f := . }}
|
||||
{{ template "slice" $f }}
|
||||
|
||||
{{ range $field := sortableFields ($f.SharedFields.Common) }}
|
||||
{{ template "slice_sort_by" concat ($f) ($field) }}
|
||||
{{ end }}
|
||||
|
||||
{{ range $s := $f.Constructors }}{{ if $s.Fields }}
|
||||
{{ range $field := mapCollectableFields ($f.SharedFields.Common) }}
|
||||
{{ template "slice_collect_to_map" concat ($f) ($field) ($s.Name) }}
|
||||
{{ end }}
|
||||
|
||||
// As{{ $s.Name }} returns copy with only {{ $s.Name }} constructors.
|
||||
func (s {{ template "slice_name" $f }}) As{{ $s.Name }}() (to {{ template "slice_name" $s }}) {
|
||||
for _, elem := range s {
|
||||
value, ok := elem.(*{{ $s.Name }})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
to = append(to, *value)
|
||||
}
|
||||
|
||||
return to
|
||||
}
|
||||
{{- end }}{{- end }}
|
||||
|
||||
{{ range $mapping := $f.Mappings }}{{- if (not $mapping.Constructor) }}
|
||||
|
||||
{{- range $field := mapCollectableFields (index ($f.SharedFields) ($mapping.MapperName)) }}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.fieldDef*/ -}}
|
||||
// Fill{{ $mapping.MapperName }}Map fills only {{ $mapping.MapperName }} constructors to given map.
|
||||
func (s {{ template "slice_name" $f }}) Fill{{ $mapping.MapperName }}{{ template "map_collector_name" $field }}Map(to map[{{ $field.Type }}]{{ template "print_mapper_type" $mapping }}) {
|
||||
for _, elem := range s {
|
||||
value, ok := elem.As{{ $mapping.MapperName }}()
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
to[value.Get{{ $field.Name }}()] = value
|
||||
}
|
||||
}
|
||||
|
||||
// {{ $mapping.MapperName }}ToMap collects only {{ $mapping.MapperName }} constructors to map.
|
||||
func (s {{ template "slice_name" $f }}) {{ $mapping.MapperName }}To{{ template "map_collector_name" $field }}Map() map[{{ $field.Type }}]{{ template "print_mapper_type" $mapping }} {
|
||||
r := make(map[{{ $field.Type }}]{{ template "print_mapper_type" $mapping }}, len(s))
|
||||
s.Fill{{ $mapping.MapperName }}{{ template "map_collector_name" $field }}Map(r)
|
||||
return r
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
// AppendOnly{{ $mapping.MapperName }} appends only {{ $mapping.MapperName }} constructors to
|
||||
// given slice.
|
||||
func (s {{ template "slice_name" $f }}) AppendOnly{{ $mapping.MapperName }}(to []{{ template "print_mapper_type" $mapping }}) []{{ template "print_mapper_type" $mapping }} {
|
||||
for _, elem := range s {
|
||||
value, ok := elem.As{{ $mapping.MapperName }}()
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
to = append(to, value)
|
||||
}
|
||||
|
||||
return to
|
||||
}
|
||||
|
||||
// As{{ $mapping.MapperName }} returns copy with only {{ $mapping.MapperName }} constructors.
|
||||
func (s {{ template "slice_name" $f }}) As{{ $mapping.MapperName }}() (to []{{ template "print_mapper_type" $mapping }}) {
|
||||
return s.AppendOnly{{ $mapping.MapperName }}(to)
|
||||
}
|
||||
|
||||
{{- range $method := concat ("First") ("Last") }}
|
||||
// {{ $method }}As{{ $mapping.MapperName }} returns {{ lower $method }} element of slice (if exists).
|
||||
func (s {{ template "slice_name" $f }}) {{ $method }}As{{ $mapping.MapperName }}() (v {{ template "print_mapper_type" $mapping }}, ok bool) {
|
||||
value, ok := s.{{ $method }}()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
return value.As{{ $mapping.MapperName }}()
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
{{- range $method := concat ("PopFirst") ("Pop") }}
|
||||
// {{ $method }}As{{ $mapping.MapperName }} returns element of slice (if exists).
|
||||
func (s *{{ template "slice_name" $f }}) {{ $method }}As{{ $mapping.MapperName }}() (v {{ template "print_mapper_type" $mapping }}, ok bool) {
|
||||
value, ok := s.{{ $method }}()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
return value.As{{ $mapping.MapperName }}()
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{- end }}{{- end }}
|
||||
|
||||
{{- end }}
|
||||
@@ -0,0 +1,31 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.config*/ -}}
|
||||
|
||||
{{ define "main" }}
|
||||
{{ $pkg := $.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
{{ range $s := $.Structs }}
|
||||
{{ template "struct" $s }}
|
||||
{{ template "zero_derive" $s }}
|
||||
{{ template "string_derive" $s }}
|
||||
{{ if $.Flags.Mapping }}{{ template "fill_from" $s }}{{ end }}
|
||||
{{ template "type_info" $s }}
|
||||
{{ template "set_flags" $s }}
|
||||
{{ template "encode" $s }}
|
||||
{{ template "decode" $s }}
|
||||
{{- if $.Flags.TDLibJSON }}
|
||||
{{ template "encode_tdlib_json" $s }}
|
||||
{{ template "decode_tdlib_json" $s }}
|
||||
{{- end }}
|
||||
{{ if $.Flags.GetSet }}{{ template "getset" $s }}{{ end }}
|
||||
{{ if $.Flags.Mapping }}{{ template "field_mapping" newStructConfig ($s) ($) }}{{ end }}
|
||||
{{ if $.Flags.Client }}{{ template "method" $s }}{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ range $f := $.Interfaces }}
|
||||
{{ template "interface" newInterfaceConfig ($f) ($) }}
|
||||
{{ if $.Flags.Mapping }}{{ template "interface_mapping" $f }}{{ end }}
|
||||
{{ template "box" newInterfaceConfig ($f) ($) }}
|
||||
{{ end }}
|
||||
|
||||
{{- end }}
|
||||
@@ -0,0 +1,62 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
{{ define "method" }}{{- $s := . -}}{{ if $s.Method }}
|
||||
// {{ $s.Method }} invokes method {{ $s.RawType }} returning error if any.
|
||||
{{- if $s.Docs }}
|
||||
{{- range $d := $s.Docs }}
|
||||
// {{ trim $d }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if $s.Links }}
|
||||
{{- template "print_links" $s.Links }}
|
||||
{{- end }}
|
||||
{{- if $s.Errors }}
|
||||
{{- template "print_errors" $s.Errors }}
|
||||
{{- end }}
|
||||
{{- if $s.URL }}
|
||||
//
|
||||
// See {{ $s.URL }} for reference.
|
||||
{{- end }}
|
||||
{{- if $s.BotCanUse }}
|
||||
// Can be used by bots.
|
||||
{{- end }}
|
||||
{{- if $s.Result }}
|
||||
{{- if $s.ResultSingular }}
|
||||
func (c *Client) {{ $s.Method }}({{ template "request_params" $s }}) ({{ if not $s.ResultVector }}*{{ $s.Result }}{{ else }}{{ template "slice_result_name" $s }}{{ end }}, error) {
|
||||
var result {{ $s.Result }}
|
||||
{{ template "pack_request" $s }}
|
||||
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
{{- if $s.ResultVector }}
|
||||
return {{ template "slice_result_name" $s }}(result.Elems), nil
|
||||
{{- else }}
|
||||
return &result, nil
|
||||
{{- end }}
|
||||
}
|
||||
{{- else }}
|
||||
func (c *Client) {{ $s.Method }}({{ template "request_params" $s }}) ({{if ne $s.Result "BoolClass"}}{{ $s.Result }}{{ else }}bool{{ end }}, error) {
|
||||
var result {{ $s.ResultFunc }}Box
|
||||
{{ template "pack_request" $s }}
|
||||
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
|
||||
{{- if ne $s.Result "BoolClass" }}return nil, err{{- else }}return false, err{{- end }}
|
||||
}
|
||||
{{- if ne $s.Result "BoolClass" }}
|
||||
return result.{{ $s.ResultBaseName }}, nil
|
||||
{{- else }}
|
||||
_, ok := result.{{ $s.ResultBaseName }}.(*BoolTrue)
|
||||
return ok, nil
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
func (c *Client) {{ $s.Method }}({{ template "request_params" $s }}) error {
|
||||
var ok Ok
|
||||
{{ template "pack_request" $s }}
|
||||
if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
{{ end }}{{ end }}
|
||||
@@ -0,0 +1,51 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.config*/ -}}
|
||||
|
||||
{{ define "registry" }}
|
||||
{{ $pkg := $.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
{{- if $.Layer }}
|
||||
// Layer version of schema.
|
||||
const Layer = {{ $.Layer }}
|
||||
{{- end }}
|
||||
|
||||
// TypesMap returns mapping from type ids to TL type names.
|
||||
func TypesMap() map[uint32]string {
|
||||
return map[uint32]string {
|
||||
{{- range $elem := $.Registry }}
|
||||
{{ $elem.Name }}TypeID: "{{ $elem.Raw }}",
|
||||
{{- end }}
|
||||
}
|
||||
}
|
||||
|
||||
// NamesMap returns mapping from type names to TL type ids.
|
||||
func NamesMap() map[string]uint32 {
|
||||
return map[string]uint32 {
|
||||
{{- range $elem := $.Registry }}
|
||||
"{{ trimSuffix (trimSuffix ($elem.Raw) ($elem.HexID)) ("#") }}": {{ $elem.Name }}TypeID,
|
||||
{{- end }}
|
||||
}
|
||||
}
|
||||
|
||||
// TypesConstructorMap maps type ids to constructors.
|
||||
func TypesConstructorMap() map[uint32]func() bin.Object {
|
||||
return map[uint32]func() bin.Object {
|
||||
{{- range $elem := $.Registry }}
|
||||
{{ $elem.Name }}TypeID: func() bin.Object { return &{{ $elem.Name }}{} },
|
||||
{{- end }}
|
||||
}
|
||||
}
|
||||
|
||||
// ClassConstructorsMap maps class schema name to constructors type ids.
|
||||
func ClassConstructorsMap() map[string][]uint32 {
|
||||
return map[string][]uint32 {
|
||||
{{- range $elem := $.Interfaces }}
|
||||
{{ $elem.Name }}Name: {
|
||||
{{- range $c := $elem.Constructors }}
|
||||
{{ $c.Name }}TypeID,
|
||||
{{- end }}
|
||||
},
|
||||
{{- end }}
|
||||
}
|
||||
}
|
||||
{{ end }}
|
||||
@@ -0,0 +1,102 @@
|
||||
{{ define "server" }}
|
||||
{{ $pkg := $.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
type ServerDispatcher struct{
|
||||
fallback func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error)
|
||||
handlers map[uint32]func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error)
|
||||
}
|
||||
|
||||
func NewServerDispatcher(fallback func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error)) *ServerDispatcher {
|
||||
return &ServerDispatcher{
|
||||
fallback: fallback,
|
||||
handlers: map[uint32]func(context.Context, *bin.Buffer) (bin.Encoder, error){},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerDispatcher) Handle(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
|
||||
id, err := b.PeekID()
|
||||
if err != nil{
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f, ok := s.handlers[id]
|
||||
if !ok {
|
||||
return s.fallback(ctx, b)
|
||||
}
|
||||
|
||||
return f(ctx, b)
|
||||
}
|
||||
|
||||
{{ range $s:= $.Structs }}{{- if notEmpty $s.Method }}
|
||||
{{- if $s.Result }}
|
||||
{{- if $s.ResultSingular }}
|
||||
func (s *ServerDispatcher) On{{ $s.Method }}(f func({{ template "request_params" $s }}) ({{ if not $s.ResultVector }}*{{ $s.Result }}{{ else }}{{ template "slice_result_name" $s }}{{ end }}, error)) {
|
||||
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
|
||||
var request {{ $s.Name }}
|
||||
if err := request.Decode(b); err != nil{
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response, err := f({{- template "unpack_request" $s }})
|
||||
if err != nil{
|
||||
return nil, err
|
||||
}
|
||||
|
||||
{{- if $s.ResultVector }}
|
||||
return &{{ $s.Result }}{Elems: response}, nil
|
||||
{{- else }}
|
||||
return response, nil
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
s.handlers[{{ $s.Name }}TypeID] = handler
|
||||
}
|
||||
{{- else }}
|
||||
func (s *ServerDispatcher) On{{ $s.Method }}(f func({{ template "request_params" $s }}) ({{if ne $s.Result "BoolClass"}}{{ $s.Result }}{{ else }}bool{{ end }}, error)) {
|
||||
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
|
||||
var request {{ $s.Name }}
|
||||
if err := request.Decode(b); err != nil{
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response, err := f({{- template "unpack_request" $s }})
|
||||
if err != nil{
|
||||
return nil, err
|
||||
}
|
||||
|
||||
{{- if ne $s.Result "BoolClass" }}
|
||||
return &{{ $s.ResultFunc }}Box{ {{ $s.ResultBaseName }}: response }, nil
|
||||
{{- else }}
|
||||
if response {
|
||||
return &{{ $s.ResultFunc }}Box{ {{ $s.ResultBaseName }}: &BoolTrue{} }, nil
|
||||
}
|
||||
|
||||
return &{{ $s.ResultFunc }}Box{ {{ $s.ResultBaseName }}: &BoolFalse{} }, nil
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
s.handlers[{{ $s.Name }}TypeID] = handler
|
||||
}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
func (s *ServerDispatcher) On{{ $s.Method }}(f func({{ template "request_params" $s }}) error) {
|
||||
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
|
||||
var request {{ $s.Name }}
|
||||
if err := request.Decode(b); err != nil{
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := f({{- template "unpack_request" $s }}); err != nil{
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Ok{}, nil
|
||||
}
|
||||
|
||||
s.handlers[{{ $s.Name }}TypeID] = handler
|
||||
}
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,15 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
{{ define "set_flags" }}{{ $s := . }}
|
||||
{{- if hasFlags $s }}
|
||||
// SetFlags sets flags for non-zero fields.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) SetFlags() {
|
||||
{{- range $f := $s.Fields }}
|
||||
{{- if $f.Conditional }}
|
||||
if !({{ $s.Receiver }}.{{template "compare_zero" $f}}) {
|
||||
{{ $s.Receiver }}.{{ $f.ConditionalField }}.Set({{ $f.ConditionalIndex }})
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
@@ -0,0 +1,148 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.config*/ -}}
|
||||
|
||||
{{ define "slices" }}
|
||||
//go:build !no_gotd_slices
|
||||
// +build !no_gotd_slices
|
||||
|
||||
{{ $pkg := $.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
{{- range $f := $.Interfaces }}
|
||||
{{ template "interface_slice" $f }}
|
||||
|
||||
{{- range $s := $.Structs }}{{- if generateSliceHelper ($s) -}}
|
||||
{{ template "struct_slice" $s }}
|
||||
{{- end }}{{- end }}
|
||||
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "slice_sort_by" }}{{ $args := . -}}
|
||||
{{ $f := index ($args) (0) -}}
|
||||
{{ $field := index ($args) (1) -}}
|
||||
// SortBy{{ $field.Name }} sorts slice of {{ $f.Name }} by {{ $field.Name }}.
|
||||
func (s {{ template "slice_name" $f }}) SortBy{{ $field.Name }}() {{ template "slice_name" $f }} {
|
||||
return s.Sort(func(a, b {{ $f.Name }}) bool {
|
||||
return a.Get{{ $field.Name }}() < b.Get{{ $field.Name }}()
|
||||
})
|
||||
}
|
||||
|
||||
// SortStableBy{{ $field.Name }} sorts slice of {{ $f.Name }} by {{ $field.Name }}.
|
||||
func (s {{ template "slice_name" $f }}) SortStableBy{{ $field.Name }}() {{ template "slice_name" $f }} {
|
||||
return s.SortStable(func(a, b {{ $f.Name }}) bool {
|
||||
return a.Get{{ $field.Name }}() < b.Get{{ $field.Name }}()
|
||||
})
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ define "slice_collect_to_map" }}{{ $args := . -}}
|
||||
{{ $f := index ($args) (0) -}}
|
||||
{{ $field := index ($args) (1) -}}
|
||||
{{ $name := index ($args) (2) -}}
|
||||
// Fill{{ $name }}Map fills only {{ $name }} constructors to given map.
|
||||
func (s {{ template "slice_name" $f }}) Fill{{ $name }}{{ template "map_collector_name" $field }}Map(to map[{{ $field.Type }}]*{{ $name }} ) {
|
||||
for _, elem := range s {
|
||||
value, ok := elem.(*{{ $name }})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
to[value.Get{{ $field.Name }}()] = value
|
||||
}
|
||||
}
|
||||
|
||||
// {{ $name }}ToMap collects only {{ $name }} constructors to map.
|
||||
func (s {{ template "slice_name" $f }}) {{ $name }}To{{ template "map_collector_name" $field }}Map() map[{{ $field.Type }}]*{{ $name }} {
|
||||
r := make(map[{{ $field.Type }}]*{{ $name }}, len(s))
|
||||
s.Fill{{ $name }}Map(r)
|
||||
return r
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ define "slice_name" }}{{ $.Name }}Array{{ end }}
|
||||
{{ define "slice_field_name" }}{{ $.Type }}Array{{ end }}
|
||||
{{ define "slice_result_name" }}{{ if $.Interface }}{{ $.ResultFunc }}Array{{ else }}[]{{ $.ResultFunc }}{{ end }}{{ end }}
|
||||
|
||||
{{ define "slice" }}{{ $f := . }}
|
||||
// {{ template "slice_name" $f }} is adapter for slice of {{ $f.Name }}.
|
||||
type {{ template "slice_name" $f }} []{{ $f.Name }}
|
||||
|
||||
// Sort sorts slice of {{ $f.Name }}.
|
||||
func (s {{ template "slice_name" $f }}) Sort(less func(a, b {{ $f.Name }}) bool) {{ template "slice_name" $f }} {
|
||||
sort.Slice(s, func(i, j int) bool {
|
||||
return less(s[i], s[j])
|
||||
})
|
||||
return s
|
||||
}
|
||||
|
||||
// SortStable sorts slice of {{ $f.Name }}.
|
||||
func (s {{ template "slice_name" $f }}) SortStable(less func(a, b {{ $f.Name }}) bool) {{ template "slice_name" $f }} {
|
||||
sort.SliceStable(s, func(i, j int) bool {
|
||||
return less(s[i], s[j])
|
||||
})
|
||||
return s
|
||||
}
|
||||
|
||||
// Retain filters in-place slice of {{ $f.Name }}.
|
||||
func (s {{ template "slice_name" $f }}) Retain(keep func(x {{ $f.Name }}) bool) {{ template "slice_name" $f }} {
|
||||
n := 0
|
||||
for _, x := range s {
|
||||
if keep(x) {
|
||||
s[n] = x
|
||||
n++
|
||||
}
|
||||
}
|
||||
s = s[:n]
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// First returns first element of slice (if exists).
|
||||
func (s {{ template "slice_name" $f }}) First() (v {{ $f.Name }}, ok bool) {
|
||||
if len(s) < 1 {
|
||||
return
|
||||
}
|
||||
return s[0], true
|
||||
}
|
||||
|
||||
// Last returns last element of slice (if exists).
|
||||
func (s {{ template "slice_name" $f }}) Last() (v {{ $f.Name }}, ok bool) {
|
||||
if len(s) < 1 {
|
||||
return
|
||||
}
|
||||
return s[len(s)-1], true
|
||||
}
|
||||
|
||||
|
||||
// PopFirst returns first element of slice (if exists) and deletes it.
|
||||
func (s *{{ template "slice_name" $f }}) PopFirst() (v {{ $f.Name }}, ok bool) {
|
||||
if s == nil || len(*s) < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
a := *s
|
||||
v = a[0]
|
||||
|
||||
// Delete by index from SliceTricks.
|
||||
copy(a[0:], a[1:])
|
||||
var zero {{ $f.Name }}
|
||||
a[len(a)-1] = zero
|
||||
a = a[:len(a)-1]
|
||||
*s = a
|
||||
|
||||
return v, true
|
||||
}
|
||||
|
||||
// Pop returns last element of slice (if exists) and deletes it.
|
||||
func (s *{{ template "slice_name" $f }}) Pop() (v {{ $f.Name }}, ok bool) {
|
||||
if s == nil || len(*s) < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
a := *s
|
||||
v = a[len(a)-1]
|
||||
a = a[:len(a)-1]
|
||||
*s = a
|
||||
|
||||
return v, true
|
||||
}
|
||||
{{ end }}
|
||||
@@ -0,0 +1,10 @@
|
||||
{{define "string_derive" }}{{ $s := $ }}
|
||||
// String implements fmt.Stringer.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) String() string {
|
||||
if {{ $s.Receiver }} == nil {
|
||||
return "{{ $.Name }}(nil)"
|
||||
}
|
||||
type Alias {{ $s.Name }}
|
||||
return fmt.Sprintf("{{ $s.Name }}%+v", Alias(*{{ $s.Receiver }}))
|
||||
}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,46 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
{{ define "struct" }}{{ $s := . }}
|
||||
// {{ $s.Comment }}
|
||||
{{- if $s.Docs }}
|
||||
{{- template "print_comment" $s.Docs }}
|
||||
{{- end }}
|
||||
{{- if $s.Links }}
|
||||
{{- template "print_links" $s.Links }}
|
||||
{{- end }}
|
||||
{{- if $s.URL }}
|
||||
//
|
||||
// See {{ $s.URL }} for reference.
|
||||
{{- end }}
|
||||
type {{ $s.Name }} struct {
|
||||
{{- range $f := $s.Fields }}
|
||||
{{- template "print_comment" $f.Comment }}
|
||||
{{- if $f.Links}}
|
||||
{{- template "print_links" $f.Links }}
|
||||
{{- end }}
|
||||
{{- if and ($f.Conditional) (not $f.ConditionalBool) }}
|
||||
//
|
||||
// Use Set{{ $f.Name }} and Get{{ $f.Name }} helpers.
|
||||
{{- end }}
|
||||
{{ $f.Name }} {{ template "print_type" $f }}
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
// {{ $s.Name }}TypeID is TL type id of {{ $s.Name }}.
|
||||
const {{ $s.Name }}TypeID = {{ if not $s.Vector }}0x{{ $s.HexID }}{{- else -}}bin.TypeVector{{- end }}
|
||||
|
||||
{{ if $s.Interface }}
|
||||
// construct implements constructor of {{ $s.Interface }}.
|
||||
func ({{ $s.Receiver }} {{ $s.Name }}) construct() {{ $s.Interface }} { return &{{ $s.Receiver }} }
|
||||
{{ end }}
|
||||
|
||||
// Ensuring interfaces in compile-time for {{ $s.Name }}.
|
||||
var (
|
||||
_ bin.Encoder = &{{ $s.Name }}{}
|
||||
_ bin.Decoder = &{{ $s.Name }}{}
|
||||
_ bin.BareEncoder = &{{ $s.Name }}{}
|
||||
_ bin.BareDecoder = &{{ $s.Name }}{}
|
||||
{{ if $s.Interface }}
|
||||
_ {{ $s.Interface }} = &{{ $s.Name }}{}
|
||||
{{ end }}
|
||||
)
|
||||
{{ end }}
|
||||
@@ -0,0 +1,23 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
{{ define "struct_slice" }}{{ $f := . }}
|
||||
{{ template "slice" $f }}
|
||||
|
||||
{{ range $field := sortableFields ($f.Fields) }}
|
||||
{{ template "slice_sort_by" concat ($f) ($field) }}
|
||||
{{ end }}
|
||||
{{ range $field := mapCollectableFields ($f.Fields) }}
|
||||
// FillMap fills constructors to given map.
|
||||
func (s {{ template "slice_name" $f }}) Fill{{ template "map_collector_name" $field }}Map(to map[{{ $field.Type }}]{{ $f.Name }} ) {
|
||||
for _, value := range s {
|
||||
to[value.Get{{ $field.Name }}()] = value
|
||||
}
|
||||
}
|
||||
|
||||
// ToMap collects constructors to map.
|
||||
func (s {{ template "slice_name" $f }}) To{{ template "map_collector_name" $field }}Map() map[{{ $field.Type }}]{{ $f.Name }} {
|
||||
r := make(map[{{ $field.Type }}]{{ $f.Name }}, len(s))
|
||||
s.Fill{{ template "map_collector_name" $field }}Map(r)
|
||||
return r
|
||||
}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -0,0 +1,40 @@
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
{{ define "type_info" }}{{ $s := . }}
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*{{ $s.Name }}) TypeID() uint32 {
|
||||
return {{ $s.Name }}TypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*{{ $s.Name }}) TypeName() string {
|
||||
return "{{ $s.RawName }}"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "{{ $s.RawName }}",
|
||||
ID: {{ $s.Name }}TypeID,
|
||||
}
|
||||
if {{ $s.Receiver }} == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{{- range $f := $s.Fields }}
|
||||
{{- if ne ($f.Type) ("bin.Fields") }}
|
||||
{
|
||||
Name: "{{ $f.Name }}",
|
||||
SchemaName: "{{ $f.RawName }}",
|
||||
{{- if $f.Conditional }}
|
||||
Null: !{{ $s.Receiver }}.{{ $f.ConditionalField }}.Has({{ $f.ConditionalIndex }}),
|
||||
{{- end }}
|
||||
},
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
return typ
|
||||
}
|
||||
{{ end }}
|
||||
@@ -0,0 +1,72 @@
|
||||
{{ define "updates_classifier" }}
|
||||
{{ $pkg := $.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
func IsPtsUpdate(u UpdateClass) (pts, ptsCount int, ok bool) {
|
||||
switch u := u.(type) {
|
||||
{{- range $s := $.Structs }}{{ if and (eq $s.Interface "UpdateClass")
|
||||
(hasField $s.Fields "Pts" "int")
|
||||
(not (contains $s.Name "Channel")) }}
|
||||
{{- $ptsCount := or (and (hasField $s.Fields "PtsCount" "int") "u.PtsCount") "0" }}
|
||||
case *{{ $s.Name }}:
|
||||
return u.Pts, {{ $ptsCount }}, true
|
||||
{{- end }}{{ end }}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func IsQtsUpdate(u UpdateClass) (qts int, ok bool) {
|
||||
switch u := u.(type) {
|
||||
{{- range $s := $.Structs }}{{ if and (eq $s.Interface "UpdateClass") (hasField $s.Fields "Qts" "int") }}
|
||||
case *{{ $s.Name }}:
|
||||
return u.Qts, true
|
||||
{{- end }}{{ end }}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func IsChannelPtsUpdate(u UpdateClass) (channelID int64, pts, ptsCount int, ok bool, err error) {
|
||||
switch u := u.(type) {
|
||||
{{- range $s := $.Structs }}{{ if and (eq $s.Interface "UpdateClass")
|
||||
(hasField $s.Fields "Pts" "int")
|
||||
(contains $s.Name "Channel") }}
|
||||
{{- $ptsCount := or (and (hasField $s.Fields "PtsCount" "int") "u.PtsCount") "0" }}
|
||||
case *{{ $s.Name }}:
|
||||
{{- if (hasField $s.Fields "ChannelID" "int64") }}
|
||||
return u.ChannelID, u.Pts, {{ $ptsCount }}, true, nil
|
||||
{{- else }}
|
||||
channelID, err = extractChannelID(u.Message)
|
||||
return channelID, u.Pts, {{ $ptsCount }}, true, err
|
||||
{{- end }}{{ end }}{{ end }}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func extractChannelID(msg MessageClass) (int64, error) {
|
||||
switch msg := msg.(type) {
|
||||
{{- range $s := $.Structs }}{{ if eq $s.Interface "MessageClass" }}
|
||||
case *{{ $s.Name }}:
|
||||
{{- range $field := $s.Fields }}{{ if eq $field.Name "PeerID" }}
|
||||
{{- if (optionalField $s $field) }}
|
||||
peer, ok := msg.GetPeerID()
|
||||
if !ok {
|
||||
return 0, errors.New("{{ $s.Name }} have no peerID field")
|
||||
}
|
||||
{{- else }}
|
||||
peer := msg.PeerID
|
||||
{{ end }}{{ end }}{{ end }}
|
||||
if c, ok := peer.(*PeerChannel); ok {
|
||||
return c.ChannelID, nil
|
||||
}
|
||||
|
||||
return 0, errors.New("unexpected peer type")
|
||||
{{- end }}{{ end }}
|
||||
default:
|
||||
return 0, errors.New("unexpected MessageClass type")
|
||||
}
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
@@ -0,0 +1,88 @@
|
||||
{{ define "request_params" }}ctx context.Context{{- if .UnpackParameters }}{{- if .Fields }}
|
||||
{{- range $f := .Fields }}, {{ lowerGo $f.Name }} {{ template "print_type" $f }}{{- end }}
|
||||
{{- end }}
|
||||
{{- else }}, request *{{ .Name }}{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{ define "pack_request" }}{{- if .UnpackParameters }}
|
||||
request := &{{ $.Name }}{
|
||||
{{- range $f := $.Fields }}
|
||||
{{ $f.Name }}: {{ lowerGo $f.Name }},
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}{{- end }}
|
||||
|
||||
{{ define "unpack_request" }}ctx{{- if .UnpackParameters }}{{- if .Fields }}
|
||||
{{- range $f := $.Fields }}, request.{{ $f.Name }}
|
||||
{{- end }}{{- end }}
|
||||
{{- else }}, &request{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{ define "print_type" }}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.fieldDef*/ -}}
|
||||
{{- if $.DoubleSlice }}[][]{{ $.Type }}
|
||||
{{- else if $.Slice }}[]{{ $.Type }}
|
||||
{{- else }}{{ $.Type }}
|
||||
{{- end }}{{- end }}
|
||||
|
||||
{{ define "getter_func_type" }}{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.fieldDef*/ -}}
|
||||
Get{{$.Name}}() (value {{ template "print_type" $ }}{{ if and ($.Conditional) (not $.ConditionalBool) }}, ok bool{{ end }})
|
||||
{{- end }}
|
||||
|
||||
{{ define "print_mapper_type" }}{{ $mapping := . -}}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.constructorMapping*/ -}}
|
||||
{{- if not ($mapping.Concrete) }}{{ $mapping.Name }}{{- else }}*{{ $mapping.Name }}{{- end -}}
|
||||
{{ end }}
|
||||
|
||||
{{ define "mapper_func_type" }}{{ $mapping := . -}}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.constructorMapping*/ -}}
|
||||
{{- if $mapping.Fields }}As{{ $mapping.MapperName }}() {{ template "print_mapper_type" $mapping }}
|
||||
{{- else }}As{{ $mapping.MapperName }}() ({{ template "print_mapper_type" $mapping }}, bool)
|
||||
{{- end }}{{- end }}
|
||||
|
||||
{{ define "print_links" }}
|
||||
//
|
||||
// Links:
|
||||
{{- range $i, $link := . }}
|
||||
// {{ add $i 1 }}) {{ $link }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{ define "print_comment" }}
|
||||
{{- range $line := . }}
|
||||
// {{ trim $line }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{ define "print_errors" }}
|
||||
//
|
||||
// Possible errors:
|
||||
{{- range $err := . }}
|
||||
// {{ $err.Code }} {{ $err.Type }}: {{ $err.Description }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{ define "class_interface_header" }}{{ $f := . }}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.interfaceDef*/ -}}
|
||||
bin.Encoder
|
||||
bin.Decoder
|
||||
bin.BareEncoder
|
||||
bin.BareDecoder
|
||||
construct() {{ $f.Name }}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
TypeID() uint32
|
||||
// TypeName returns name of type in TL schema.
|
||||
TypeName() string
|
||||
// String implements fmt.Stringer.
|
||||
String() string
|
||||
// Zero returns true if current object has a zero value.
|
||||
Zero() bool
|
||||
{{- end }}
|
||||
|
||||
|
||||
{{ define "map_collector_name" }}{{ $field := . }}{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.fieldDef*/ -}}
|
||||
{{ if ne ($field.Name) ("ID") }}{{ $field.Name }}{{ end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,30 @@
|
||||
{{ define "zero_derive" }}{{ $s := . }}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structDef*/ -}}
|
||||
func ({{ $s.Receiver }} *{{ $s.Name }}) Zero() bool {
|
||||
if {{ $s.Receiver }} == nil {
|
||||
return true
|
||||
}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.fieldDef*/ -}}
|
||||
{{- range $f := $s.Fields }}{{- if ne ($f.Name) ($f.ConditionalField) }}
|
||||
if !({{ $s.Receiver }}.{{template "compare_zero" $f}}) {
|
||||
return false
|
||||
}
|
||||
{{- end }}{{- end }}
|
||||
|
||||
return true
|
||||
}
|
||||
{{- end -}}
|
||||
|
||||
{{ define "compare_zero" }}
|
||||
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.fieldDef*/ -}}
|
||||
{{- .Name -}}
|
||||
{{- if or (.Slice) (.DoubleSlice) -}} == nil
|
||||
{{- else if eq (.Type) ("bin.Int128") -}} == bin.Int128{}
|
||||
{{- else if eq (.Type) ("bin.Int256") -}} == bin.Int256{}
|
||||
{{- else if or (hasPrefix (.Type) ("int")) (hasPrefix (.Type) ("float")) }} == 0
|
||||
{{- else if eq (.Type) ("string") -}} == ""
|
||||
{{- else if eq (.Type) ("bool") -}} == false
|
||||
{{- else if eq (.Type) ("bin.Object") }} == nil
|
||||
{{- else if hasSuffix (.Type) ("Class") }} == nil
|
||||
{{- else -}}.Zero()
|
||||
{{- end -}}{{- end }}
|
||||
@@ -0,0 +1,149 @@
|
||||
int32 = Int32;
|
||||
string ? = String;
|
||||
false#bc799737 = Bool;
|
||||
true#997275b5 = Bool;
|
||||
bytes#e937bb82 = Bytes;
|
||||
|
||||
vector#1cb5c415 {t:Type} # [ t ] = Vector t;
|
||||
|
||||
///@description An object of this type can be returned on every function call, in case of an error
|
||||
//@code Error code; subject to future changes. If the error code is 406, the error message must not be processed in any way and must not be displayed to the user
|
||||
//@message Error message; subject to future changes
|
||||
error code:int32 message:string temporary:Bool = Error;
|
||||
|
||||
//@description can be returned by functions as result.
|
||||
ok = Ok;
|
||||
|
||||
message err:Error = Message;
|
||||
|
||||
sms text:string = SMS;
|
||||
|
||||
responseID id:int32 = Response;
|
||||
responseText text:string = Response;
|
||||
|
||||
//@description Message
|
||||
bigMessage id:int32 count:int32 targetId:int32 escape:bool summary:bool = AbstractMessage;
|
||||
|
||||
noMessage = AbstractMessage;
|
||||
|
||||
targetsMessage targets:vector<int32> = AbstractMessage;
|
||||
|
||||
update msg:AbstractMessage delay:int32 = Update;
|
||||
|
||||
getUpdatesResp updates:Vector<AbstractMessage> = GetUpdatesResp;
|
||||
|
||||
fieldsMessage#947225b5 flags:# escape:flags.0?Bool ttl_seconds:flags.1?int = AbstractMessage;
|
||||
|
||||
bytesMessage data:bytes = AbstractMessage;
|
||||
|
||||
//@class TextEntityType @description Represents a part of the text which must be formatted differently
|
||||
|
||||
//@description A mention of a user by their username
|
||||
textEntityTypeMention = TextEntityType;
|
||||
|
||||
//@description A hashtag text, beginning with "#"
|
||||
textEntityTypeHashtag = TextEntityType;
|
||||
|
||||
//@description A cashtag text, beginning with "$" and consisting of capital english letters (i.e. "$USD")
|
||||
textEntityTypeCashtag = TextEntityType;
|
||||
|
||||
//@description A bot command, beginning with "/". This shouldn't be highlighted if there are no bots in the chat
|
||||
textEntityTypeBotCommand = TextEntityType;
|
||||
|
||||
//@description An HTTP URL
|
||||
textEntityTypeUrl = TextEntityType;
|
||||
|
||||
//@description An email address
|
||||
textEntityTypeEmailAddress = TextEntityType;
|
||||
|
||||
//@description A phone number
|
||||
textEntityTypePhoneNumber = TextEntityType;
|
||||
|
||||
//@description A bank card number. The getBankCardInfo method can be used to get information about the bank card
|
||||
textEntityTypeBankCardNumber = TextEntityType;
|
||||
|
||||
//@description A bold text
|
||||
textEntityTypeBold = TextEntityType;
|
||||
|
||||
//@description An italic text
|
||||
textEntityTypeItalic = TextEntityType;
|
||||
|
||||
//@description An underlined text
|
||||
textEntityTypeUnderline = TextEntityType;
|
||||
|
||||
//@description A strikethrough text
|
||||
textEntityTypeStrikethrough = TextEntityType;
|
||||
|
||||
//@description Text that must be formatted as if inside a code HTML tag
|
||||
textEntityTypeCode = TextEntityType;
|
||||
|
||||
//@description Text that must be formatted as if inside a pre HTML tag
|
||||
textEntityTypePre = TextEntityType;
|
||||
|
||||
//@description Text that must be formatted as if inside pre, and code HTML tags @language Programming language of the code; as defined by the sender
|
||||
textEntityTypePreCode language:string = TextEntityType;
|
||||
|
||||
//@description A text description shown instead of a raw URL @url HTTP or tg:// URL to be opened when the link is clicked
|
||||
textEntityTypeTextUrl url:string = TextEntityType;
|
||||
|
||||
//@description A text shows instead of a raw mention of the user (e.g., when the user has no username) @user_id Identifier of the mentioned user
|
||||
textEntityTypeMentionName user_id:int32 = TextEntityType;
|
||||
|
||||
//@description Represents a part of the text that needs to be formatted in some unusual way @offset Offset of the entity, in UTF-16 code units @length Length of the entity, in UTF-16 code units @type Type of the entity
|
||||
textEntity offset:int32 length:int32 type:TextEntityType = TextEntity;
|
||||
|
||||
//@description Contains a list of text entities @entities List of text entities
|
||||
textEntities entities:vector<textEntity> = TextEntities;
|
||||
|
||||
|
||||
//@description A simple object containing a number; for testing only @value Number
|
||||
testInt value:int32 = TestInt;
|
||||
//@description A simple object containing a string; for testing only @value String
|
||||
testString value:string = TestString;
|
||||
//@description A simple object containing a sequence of bytes; for testing only @value Bytes
|
||||
testBytes value:bytes = TestBytes;
|
||||
//@description A simple object containing a vector of numbers; for testing only @value Vector of numbers
|
||||
testVectorInt value:vector<int32> = TestVectorInt;
|
||||
//@description A simple object containing a vector of objects that hold a number; for testing only @value Vector of objects
|
||||
testVectorIntObject value:vector<testInt> = TestVectorIntObject;
|
||||
//@description A simple object containing a vector of strings; for testing only @value Vector of strings
|
||||
testVectorString value:vector<string> = TestVectorString;
|
||||
//@description A simple object containing a vector of objects that hold a string; for testing only @value Vector of objects
|
||||
testVectorStringObject value:vector<testString> = TestVectorStringObject;
|
||||
|
||||
//@description A simple object containing a vector of bytes.
|
||||
testVectorBytes value:vector<bytes> = TestVectorBytes;
|
||||
|
||||
testVectorVector value:vector<vector<string>> = TestVectorVector;
|
||||
|
||||
client_DH_inner_data#6643b654 nonce:int128 server_nonce:int128 retry_id:long g_b:string = Client_DH_Inner_Data;
|
||||
|
||||
dcOption#18b7a10d flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption;
|
||||
config#330b4067 flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true blocked_mode:flags.8?true pfs_enabled:flags.13?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector<DcOption> dc_txt_domain_name:string chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int pinned_infolder_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string autoupdate_url_prefix:flags.7?string gif_search_username:flags.9?string venue_search_username:flags.10?string img_search_username:flags.11?string static_maps_provider:flags.12?string caption_length_max:int message_length_max:int webfile_dc_id:int suggested_lang_code:flags.2?string lang_pack_version:flags.2?int base_lang_pack_version:flags.2?int = Config;
|
||||
|
||||
invokeWithLayer#da9b0d0d {X:Type} layer:int query:!X = X;
|
||||
|
||||
auth name:string = Auth;
|
||||
|
||||
authPassword name:string password:string = Auth;
|
||||
|
||||
user.auth foo:string = user.Auth;
|
||||
user.authPassword pwd:string = user.Auth;
|
||||
|
||||
theme#28f1114 name:string = Theme;
|
||||
|
||||
account.themesNotModified#f41eb622 = account.Themes;
|
||||
account.themes#7f676421 hash:int themes:Vector<Theme> = account.Themes;
|
||||
|
||||
---functions---
|
||||
|
||||
//@description check that server is live
|
||||
ping id:int32 = Ok;
|
||||
|
||||
send msg:SMS = SMS;
|
||||
|
||||
sendMultipleSMS messages:vector<SMS> = Ok;
|
||||
|
||||
doAuth = Auth;
|
||||
|
||||
echoVector ids:Vector<int> = Vector<int>;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
package gen
|
||||
|
||||
type structConfig struct {
|
||||
Struct structDef
|
||||
Config config
|
||||
}
|
||||
|
||||
func newStructConfig(s structDef, c config) *structConfig {
|
||||
return &structConfig{Struct: s, Config: c}
|
||||
}
|
||||
|
||||
type interfaceConfig struct {
|
||||
Interface interfaceDef
|
||||
Config config
|
||||
}
|
||||
|
||||
func newInterfaceConfig(i interfaceDef, c config) *interfaceConfig {
|
||||
return &interfaceConfig{Interface: i, Config: c}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package gen
|
||||
|
||||
func generateSliceHelper(s structDef) bool {
|
||||
return len(s.Fields) > 0 && !s.Vector && s.Method == ""
|
||||
}
|
||||
|
||||
type simpleField struct {
|
||||
Name string
|
||||
Type string
|
||||
Conditional bool
|
||||
}
|
||||
|
||||
func (s simpleField) match(f fieldDef) bool {
|
||||
return f.Name == s.Name && f.Type == s.Type && f.Conditional == s.Conditional
|
||||
}
|
||||
|
||||
func collectOnlyFields(fields []fieldDef, matchers ...simpleField) []fieldDef {
|
||||
return filterFieldsTo(fields, nil, func(f fieldDef) bool {
|
||||
for _, matcher := range matchers {
|
||||
if matcher.match(f) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
func mapCollectableFields(fields []fieldDef) (r []fieldDef) {
|
||||
return collectOnlyFields(fields,
|
||||
simpleField{Name: "ID", Type: "int"},
|
||||
simpleField{Name: "ID", Type: "int64"},
|
||||
)
|
||||
}
|
||||
|
||||
func sortableFields(fields []fieldDef) (r []fieldDef) {
|
||||
return collectOnlyFields(fields,
|
||||
simpleField{Name: "ID", Type: "int"},
|
||||
simpleField{Name: "ID", Type: "int64"},
|
||||
simpleField{Name: "Date", Type: "int"},
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package gen
|
||||
|
||||
import "flag"
|
||||
|
||||
// GenerateFlags is flags for optional generation.
|
||||
type GenerateFlags struct {
|
||||
// Client enables client generation.
|
||||
Client bool
|
||||
// Registry enables type ID registry generation.
|
||||
Registry bool
|
||||
// Server enables experimental server generation.
|
||||
Server bool
|
||||
// Handlers enables update handler generation.
|
||||
Handlers bool
|
||||
// UpdatesClassifier enables updates classifier generation.
|
||||
UpdatesClassifier bool
|
||||
// GetSet enables getters and setters generation.
|
||||
GetSet bool
|
||||
// Mapping enables mapping helpers generation.
|
||||
Mapping bool
|
||||
// Slices enables slice helpers generation.
|
||||
Slices bool
|
||||
// TDLibJSON enables TDLib API JSON encoders and decoders generation.
|
||||
TDLibJSON bool
|
||||
}
|
||||
|
||||
// RegisterFlags registers GenerateFlags fields in given flag set.
|
||||
func (s *GenerateFlags) RegisterFlags(set *flag.FlagSet) {
|
||||
set.BoolVar(&s.Client, "client", true, "Enables client generation")
|
||||
set.BoolVar(&s.Registry, "registry", true, "Enables type ID registry generation")
|
||||
set.BoolVar(&s.Server, "server", false, "Enables experimental server generation")
|
||||
set.BoolVar(&s.Handlers, "handlers", false, "Enables update handler generation")
|
||||
set.BoolVar(&s.UpdatesClassifier, "updates-classifier", true, "Enables updates classifier generation")
|
||||
set.BoolVar(&s.GetSet, "getset", true, "Enables getters and setters generation")
|
||||
set.BoolVar(&s.Mapping, "mapping", false, "Enables mapping helpers generation")
|
||||
set.BoolVar(&s.Slices, "slices", false, "Enables slice helpers generation")
|
||||
set.BoolVar(&s.TDLibJSON, "tdlib-json", false, "Enables TDLib JSON encoding generation")
|
||||
}
|
||||
|
||||
// GeneratorOptions is a Generator options structure.
|
||||
type GeneratorOptions struct {
|
||||
// DocBaseURL is a documentation base URL.
|
||||
// If DocBaseURL is set, Generator will embed documentation references to generated code.
|
||||
//
|
||||
// If base is https://core.telegram.org, documentation content will be also
|
||||
// embedded.
|
||||
DocBaseURL string
|
||||
// DocLineLimit sets GoDoc comment line length limit.
|
||||
DocLineLimit int
|
||||
GenerateFlags
|
||||
}
|
||||
|
||||
// RegisterFlags registers GeneratorOptions fields in given flag set.
|
||||
func (s *GeneratorOptions) RegisterFlags(set *flag.FlagSet) {
|
||||
set.StringVar(&s.DocBaseURL, "doc", "", "Base documentation url")
|
||||
set.IntVar(&s.DocLineLimit, "line-limit", 0, "GoDoc comment line length limit")
|
||||
s.GenerateFlags.RegisterFlags(set)
|
||||
}
|
||||
|
||||
func (s *GeneratorOptions) setDefaults() {
|
||||
// Zero value DocBaseURL handled by NewGenerator.
|
||||
// It's okay to use zero value GenerateClient.
|
||||
// It's okay to use zero value GenerateRegistry.
|
||||
// It's okay to use zero value GenerateServer.
|
||||
// It's okay to use zero value GenerateHelpers.
|
||||
// It's okay to use zero value GenerateSlices.
|
||||
if s.DocLineLimit == 0 {
|
||||
s.DocLineLimit = 87
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// Package gen implements code generation from TL schema.
|
||||
package gen
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func cloneURL(u *url.URL) *url.URL {
|
||||
if u == nil {
|
||||
return nil
|
||||
}
|
||||
u2 := new(url.URL)
|
||||
*u2 = *u
|
||||
if u.User != nil {
|
||||
u2.User = new(url.Userinfo)
|
||||
*u2.User = *u.User
|
||||
}
|
||||
return u2
|
||||
}
|
||||
|
||||
func (g *Generator) docURL(parts ...string) string {
|
||||
if g.docBase == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
u := cloneURL(g.docBase)
|
||||
u.Path = path.Join(append([]string{u.Path}, parts...)...)
|
||||
|
||||
return u.String()
|
||||
}
|
||||
|
||||
func splitLine(s string, limit int) (r []string) {
|
||||
for {
|
||||
if len(s) < limit {
|
||||
r = append(r, s)
|
||||
return
|
||||
}
|
||||
|
||||
idx := strings.LastIndexFunc(s[:limit], func(r rune) bool {
|
||||
return unicode.IsSpace(r) || r == '.' || r == ','
|
||||
})
|
||||
if idx < 0 || len(s)-1 == idx {
|
||||
r = append(r, s)
|
||||
return
|
||||
}
|
||||
|
||||
r = append(r, s[:idx])
|
||||
s = s[idx+1:]
|
||||
}
|
||||
}
|
||||
|
||||
func splitLines(s []string, limit int) []string {
|
||||
r := make([]string, 0, len(s))
|
||||
|
||||
for _, line := range s {
|
||||
r = append(r, splitLine(line, limit)...)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// Package td contains generated code from example schema and is used
|
||||
// for codegen testing.
|
||||
package td
|
||||
@@ -0,0 +1,292 @@
|
||||
package td
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tmap"
|
||||
)
|
||||
|
||||
func BenchmarkMessage_Encode(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
buf := new(bin.Buffer)
|
||||
msg := Message{
|
||||
Err: Error{
|
||||
Message: "Foo",
|
||||
Code: 134,
|
||||
Temporary: true,
|
||||
},
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
msg.Encode(buf)
|
||||
buf.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMessage_Decode(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
encodeBuf := new(bin.Buffer)
|
||||
msg := &Message{
|
||||
Err: Error{
|
||||
Message: "Foo",
|
||||
Code: 134,
|
||||
Temporary: true,
|
||||
},
|
||||
}
|
||||
msg.Encode(encodeBuf)
|
||||
raw := encodeBuf.Raw()
|
||||
b.SetBytes(int64(len(raw)))
|
||||
|
||||
buf := new(bin.Buffer)
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
var decoded Message
|
||||
buf.ResetTo(raw)
|
||||
if err := decoded.Decode(buf); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkID_Decode(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
encodeBuf := new(bin.Buffer)
|
||||
msg := ResponseID{ID: 1}
|
||||
_ = msg.Encode(encodeBuf)
|
||||
raw := encodeBuf.Raw()
|
||||
b.SetBytes(int64(len(raw)))
|
||||
|
||||
buf := new(bin.Buffer)
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
var decoded ResponseID
|
||||
buf.ResetTo(raw)
|
||||
if err := decoded.Decode(buf); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessage(t *testing.T) {
|
||||
b := new(bin.Buffer)
|
||||
msg := Message{
|
||||
Err: Error{
|
||||
Message: "Foo",
|
||||
Code: 134,
|
||||
Temporary: true,
|
||||
},
|
||||
}
|
||||
msg.Encode(b)
|
||||
|
||||
result := Message{}
|
||||
if err := result.Decode(b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTargetsMessage_Encode(t *testing.T) {
|
||||
b := new(bin.Buffer)
|
||||
msg := TargetsMessage{
|
||||
Targets: []int32{1, 2, 3},
|
||||
}
|
||||
msg.Encode(b)
|
||||
decoded := TargetsMessage{}
|
||||
if err := decoded.Decode(b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Equal(t, msg, decoded)
|
||||
}
|
||||
|
||||
func TestGetUpdatesResp(t *testing.T) {
|
||||
b := new(bin.Buffer)
|
||||
v := GetUpdatesResp{
|
||||
Updates: []AbstractMessageClass{
|
||||
&BigMessage{ID: 12, Count: 3, Escape: true, Summary: true, TargetID: 1},
|
||||
&NoMessage{},
|
||||
&BytesMessage{Data: []byte{0x1, 0xf3, 104, 205}},
|
||||
&TargetsMessage{Targets: []int32{1, 2, 3, 4}},
|
||||
},
|
||||
}
|
||||
v.Encode(b)
|
||||
decoded := GetUpdatesResp{}
|
||||
if err := decoded.Decode(b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Equal(t, v, decoded)
|
||||
}
|
||||
|
||||
func TestDecodeToNil(t *testing.T) {
|
||||
b := new(bin.Buffer)
|
||||
if err := (&TargetsMessage{}).Encode(b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var msg *TargetsMessage
|
||||
if err := msg.Decode(b); err == nil {
|
||||
t.Fatal("unexpected success")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetUpdatesRespNilElem(t *testing.T) {
|
||||
b := new(bin.Buffer)
|
||||
var tMessage *TargetsMessage
|
||||
v := GetUpdatesResp{
|
||||
Updates: []AbstractMessageClass{
|
||||
&BigMessage{ID: 12, Count: 3, Escape: true, Summary: true, TargetID: 1},
|
||||
&NoMessage{},
|
||||
&TargetsMessage{Targets: []int32{1, 2, 3, 4}},
|
||||
tMessage,
|
||||
},
|
||||
}
|
||||
if err := v.Encode(b); err == nil {
|
||||
t.Fatal("unexpected success")
|
||||
}
|
||||
}
|
||||
|
||||
type mockInvoker struct {
|
||||
input bin.Encoder
|
||||
output bin.Encoder
|
||||
}
|
||||
|
||||
func (m *mockInvoker) Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder) error {
|
||||
m.input = input
|
||||
|
||||
buf := bin.Buffer{}
|
||||
err := m.output.Encode(&buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return output.Decode(&buf)
|
||||
}
|
||||
|
||||
func TestVectorResponse(t *testing.T) {
|
||||
elems := []int{1, 2, 3}
|
||||
m := mockInvoker{
|
||||
output: &IntVector{Elems: []int{1, 2, 3}},
|
||||
}
|
||||
client := NewClient(&m)
|
||||
|
||||
r, err := client.EchoVector(context.Background(), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
require.Equal(t, r, elems)
|
||||
}
|
||||
|
||||
func BenchmarkDecodeBool(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
encodeBuf := new(bin.Buffer)
|
||||
(&True{}).Encode(encodeBuf)
|
||||
raw := encodeBuf.Raw()
|
||||
b.SetBytes(int64(len(raw)))
|
||||
|
||||
buf := new(bin.Buffer)
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf.ResetTo(raw)
|
||||
v, err := DecodeBool(buf)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
switch v.(type) {
|
||||
case *True: // ok
|
||||
default:
|
||||
b.Fatalf("Unexpected %T", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecodeResponse(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
encodeBuf := new(bin.Buffer)
|
||||
(&ResponseID{ID: 13}).Encode(encodeBuf)
|
||||
raw := encodeBuf.Raw()
|
||||
b.SetBytes(int64(len(raw)))
|
||||
|
||||
buf := new(bin.Buffer)
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf.ResetTo(raw)
|
||||
v, err := DecodeResponse(buf)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
switch v.(type) {
|
||||
case *ResponseID: // ok
|
||||
default:
|
||||
b.Fatalf("Unexpected %T", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecodeAbstractMessage(b *testing.B) {
|
||||
b.Run("NoMessage", func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
encodeBuf := new(bin.Buffer)
|
||||
(&NoMessage{}).Encode(encodeBuf)
|
||||
raw := encodeBuf.Raw()
|
||||
b.SetBytes(int64(len(raw)))
|
||||
|
||||
buf := new(bin.Buffer)
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf.ResetTo(raw)
|
||||
v, err := DecodeAbstractMessage(buf)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
switch v.(type) {
|
||||
case *NoMessage: // ok
|
||||
default:
|
||||
b.Fatalf("Unexpected %T", v)
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("BigMessage", func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
encodeBuf := new(bin.Buffer)
|
||||
(&BigMessage{}).Encode(encodeBuf)
|
||||
raw := encodeBuf.Raw()
|
||||
b.SetBytes(int64(len(raw)))
|
||||
|
||||
buf := new(bin.Buffer)
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf.ResetTo(raw)
|
||||
v, err := DecodeAbstractMessage(buf)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
switch v.(type) {
|
||||
case *BigMessage: // ok
|
||||
default:
|
||||
b.Fatalf("Unexpected %T", v)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRegistry(t *testing.T) {
|
||||
c := tmap.NewConstructor(
|
||||
TypesConstructorMap(),
|
||||
)
|
||||
require.NotNil(t, c.New(TextEntityTypeStrikethroughTypeID))
|
||||
require.Nil(t, c.New(0x1))
|
||||
}
|
||||
@@ -0,0 +1,946 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// BigMessage represents TL type `bigMessage#7490dcc5`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/bigMessage for reference.
|
||||
type BigMessage struct {
|
||||
// ID field of BigMessage.
|
||||
ID int32
|
||||
// Count field of BigMessage.
|
||||
Count int32
|
||||
// TargetID field of BigMessage.
|
||||
TargetID int32
|
||||
// Escape field of BigMessage.
|
||||
Escape bool
|
||||
// Summary field of BigMessage.
|
||||
Summary bool
|
||||
}
|
||||
|
||||
// BigMessageTypeID is TL type id of BigMessage.
|
||||
const BigMessageTypeID = 0x7490dcc5
|
||||
|
||||
// construct implements constructor of AbstractMessageClass.
|
||||
func (b BigMessage) construct() AbstractMessageClass { return &b }
|
||||
|
||||
// Ensuring interfaces in compile-time for BigMessage.
|
||||
var (
|
||||
_ bin.Encoder = &BigMessage{}
|
||||
_ bin.Decoder = &BigMessage{}
|
||||
_ bin.BareEncoder = &BigMessage{}
|
||||
_ bin.BareDecoder = &BigMessage{}
|
||||
|
||||
_ AbstractMessageClass = &BigMessage{}
|
||||
)
|
||||
|
||||
func (b *BigMessage) Zero() bool {
|
||||
if b == nil {
|
||||
return true
|
||||
}
|
||||
if !(b.ID == 0) {
|
||||
return false
|
||||
}
|
||||
if !(b.Count == 0) {
|
||||
return false
|
||||
}
|
||||
if !(b.TargetID == 0) {
|
||||
return false
|
||||
}
|
||||
if !(b.Escape == false) {
|
||||
return false
|
||||
}
|
||||
if !(b.Summary == false) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (b *BigMessage) String() string {
|
||||
if b == nil {
|
||||
return "BigMessage(nil)"
|
||||
}
|
||||
type Alias BigMessage
|
||||
return fmt.Sprintf("BigMessage%+v", Alias(*b))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*BigMessage) TypeID() uint32 {
|
||||
return BigMessageTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*BigMessage) TypeName() string {
|
||||
return "bigMessage"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (b *BigMessage) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "bigMessage",
|
||||
ID: BigMessageTypeID,
|
||||
}
|
||||
if b == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "ID",
|
||||
SchemaName: "id",
|
||||
},
|
||||
{
|
||||
Name: "Count",
|
||||
SchemaName: "count",
|
||||
},
|
||||
{
|
||||
Name: "TargetID",
|
||||
SchemaName: "targetId",
|
||||
},
|
||||
{
|
||||
Name: "Escape",
|
||||
SchemaName: "escape",
|
||||
},
|
||||
{
|
||||
Name: "Summary",
|
||||
SchemaName: "summary",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (b *BigMessage) Encode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't encode bigMessage#7490dcc5 as nil")
|
||||
}
|
||||
buf.PutID(BigMessageTypeID)
|
||||
return b.EncodeBare(buf)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (b *BigMessage) EncodeBare(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't encode bigMessage#7490dcc5 as nil")
|
||||
}
|
||||
buf.PutInt32(b.ID)
|
||||
buf.PutInt32(b.Count)
|
||||
buf.PutInt32(b.TargetID)
|
||||
buf.PutBool(b.Escape)
|
||||
buf.PutBool(b.Summary)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (b *BigMessage) Decode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't decode bigMessage#7490dcc5 to nil")
|
||||
}
|
||||
if err := buf.ConsumeID(BigMessageTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode bigMessage#7490dcc5: %w", err)
|
||||
}
|
||||
return b.DecodeBare(buf)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (b *BigMessage) DecodeBare(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't decode bigMessage#7490dcc5 to nil")
|
||||
}
|
||||
{
|
||||
value, err := buf.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode bigMessage#7490dcc5: field id: %w", err)
|
||||
}
|
||||
b.ID = value
|
||||
}
|
||||
{
|
||||
value, err := buf.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode bigMessage#7490dcc5: field count: %w", err)
|
||||
}
|
||||
b.Count = value
|
||||
}
|
||||
{
|
||||
value, err := buf.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode bigMessage#7490dcc5: field targetId: %w", err)
|
||||
}
|
||||
b.TargetID = value
|
||||
}
|
||||
{
|
||||
value, err := buf.Bool()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode bigMessage#7490dcc5: field escape: %w", err)
|
||||
}
|
||||
b.Escape = value
|
||||
}
|
||||
{
|
||||
value, err := buf.Bool()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode bigMessage#7490dcc5: field summary: %w", err)
|
||||
}
|
||||
b.Summary = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetID returns value of ID field.
|
||||
func (b *BigMessage) GetID() (value int32) {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
return b.ID
|
||||
}
|
||||
|
||||
// GetCount returns value of Count field.
|
||||
func (b *BigMessage) GetCount() (value int32) {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
return b.Count
|
||||
}
|
||||
|
||||
// GetTargetID returns value of TargetID field.
|
||||
func (b *BigMessage) GetTargetID() (value int32) {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
return b.TargetID
|
||||
}
|
||||
|
||||
// GetEscape returns value of Escape field.
|
||||
func (b *BigMessage) GetEscape() (value bool) {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
return b.Escape
|
||||
}
|
||||
|
||||
// GetSummary returns value of Summary field.
|
||||
func (b *BigMessage) GetSummary() (value bool) {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
return b.Summary
|
||||
}
|
||||
|
||||
// NoMessage represents TL type `noMessage#ee6324c4`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/noMessage for reference.
|
||||
type NoMessage struct {
|
||||
}
|
||||
|
||||
// NoMessageTypeID is TL type id of NoMessage.
|
||||
const NoMessageTypeID = 0xee6324c4
|
||||
|
||||
// construct implements constructor of AbstractMessageClass.
|
||||
func (n NoMessage) construct() AbstractMessageClass { return &n }
|
||||
|
||||
// Ensuring interfaces in compile-time for NoMessage.
|
||||
var (
|
||||
_ bin.Encoder = &NoMessage{}
|
||||
_ bin.Decoder = &NoMessage{}
|
||||
_ bin.BareEncoder = &NoMessage{}
|
||||
_ bin.BareDecoder = &NoMessage{}
|
||||
|
||||
_ AbstractMessageClass = &NoMessage{}
|
||||
)
|
||||
|
||||
func (n *NoMessage) Zero() bool {
|
||||
if n == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (n *NoMessage) String() string {
|
||||
if n == nil {
|
||||
return "NoMessage(nil)"
|
||||
}
|
||||
type Alias NoMessage
|
||||
return fmt.Sprintf("NoMessage%+v", Alias(*n))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*NoMessage) TypeID() uint32 {
|
||||
return NoMessageTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*NoMessage) TypeName() string {
|
||||
return "noMessage"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (n *NoMessage) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "noMessage",
|
||||
ID: NoMessageTypeID,
|
||||
}
|
||||
if n == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (n *NoMessage) Encode(b *bin.Buffer) error {
|
||||
if n == nil {
|
||||
return fmt.Errorf("can't encode noMessage#ee6324c4 as nil")
|
||||
}
|
||||
b.PutID(NoMessageTypeID)
|
||||
return n.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (n *NoMessage) EncodeBare(b *bin.Buffer) error {
|
||||
if n == nil {
|
||||
return fmt.Errorf("can't encode noMessage#ee6324c4 as nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (n *NoMessage) Decode(b *bin.Buffer) error {
|
||||
if n == nil {
|
||||
return fmt.Errorf("can't decode noMessage#ee6324c4 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(NoMessageTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode noMessage#ee6324c4: %w", err)
|
||||
}
|
||||
return n.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (n *NoMessage) DecodeBare(b *bin.Buffer) error {
|
||||
if n == nil {
|
||||
return fmt.Errorf("can't decode noMessage#ee6324c4 to nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TargetsMessage represents TL type `targetsMessage#cc6136f1`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/targetsMessage for reference.
|
||||
type TargetsMessage struct {
|
||||
// Targets field of TargetsMessage.
|
||||
Targets []int32
|
||||
}
|
||||
|
||||
// TargetsMessageTypeID is TL type id of TargetsMessage.
|
||||
const TargetsMessageTypeID = 0xcc6136f1
|
||||
|
||||
// construct implements constructor of AbstractMessageClass.
|
||||
func (t TargetsMessage) construct() AbstractMessageClass { return &t }
|
||||
|
||||
// Ensuring interfaces in compile-time for TargetsMessage.
|
||||
var (
|
||||
_ bin.Encoder = &TargetsMessage{}
|
||||
_ bin.Decoder = &TargetsMessage{}
|
||||
_ bin.BareEncoder = &TargetsMessage{}
|
||||
_ bin.BareDecoder = &TargetsMessage{}
|
||||
|
||||
_ AbstractMessageClass = &TargetsMessage{}
|
||||
)
|
||||
|
||||
func (t *TargetsMessage) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Targets == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TargetsMessage) String() string {
|
||||
if t == nil {
|
||||
return "TargetsMessage(nil)"
|
||||
}
|
||||
type Alias TargetsMessage
|
||||
return fmt.Sprintf("TargetsMessage%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TargetsMessage) TypeID() uint32 {
|
||||
return TargetsMessageTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TargetsMessage) TypeName() string {
|
||||
return "targetsMessage"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TargetsMessage) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "targetsMessage",
|
||||
ID: TargetsMessageTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Targets",
|
||||
SchemaName: "targets",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TargetsMessage) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode targetsMessage#cc6136f1 as nil")
|
||||
}
|
||||
b.PutID(TargetsMessageTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TargetsMessage) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode targetsMessage#cc6136f1 as nil")
|
||||
}
|
||||
b.PutInt(len(t.Targets))
|
||||
for _, v := range t.Targets {
|
||||
b.PutInt32(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TargetsMessage) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode targetsMessage#cc6136f1 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TargetsMessageTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode targetsMessage#cc6136f1: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TargetsMessage) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode targetsMessage#cc6136f1 to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode targetsMessage#cc6136f1: field targets: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
t.Targets = make([]int32, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
value, err := b.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode targetsMessage#cc6136f1: field targets: %w", err)
|
||||
}
|
||||
t.Targets = append(t.Targets, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTargets returns value of Targets field.
|
||||
func (t *TargetsMessage) GetTargets() (value []int32) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Targets
|
||||
}
|
||||
|
||||
// FieldsMessage represents TL type `fieldsMessage#947225b5`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/fieldsMessage for reference.
|
||||
type FieldsMessage struct {
|
||||
// Flags field of FieldsMessage.
|
||||
Flags bin.Fields
|
||||
// Escape field of FieldsMessage.
|
||||
//
|
||||
// Use SetEscape and GetEscape helpers.
|
||||
Escape bool
|
||||
// TTLSeconds field of FieldsMessage.
|
||||
//
|
||||
// Use SetTTLSeconds and GetTTLSeconds helpers.
|
||||
TTLSeconds int
|
||||
}
|
||||
|
||||
// FieldsMessageTypeID is TL type id of FieldsMessage.
|
||||
const FieldsMessageTypeID = 0x947225b5
|
||||
|
||||
// construct implements constructor of AbstractMessageClass.
|
||||
func (f FieldsMessage) construct() AbstractMessageClass { return &f }
|
||||
|
||||
// Ensuring interfaces in compile-time for FieldsMessage.
|
||||
var (
|
||||
_ bin.Encoder = &FieldsMessage{}
|
||||
_ bin.Decoder = &FieldsMessage{}
|
||||
_ bin.BareEncoder = &FieldsMessage{}
|
||||
_ bin.BareDecoder = &FieldsMessage{}
|
||||
|
||||
_ AbstractMessageClass = &FieldsMessage{}
|
||||
)
|
||||
|
||||
func (f *FieldsMessage) Zero() bool {
|
||||
if f == nil {
|
||||
return true
|
||||
}
|
||||
if !(f.Flags.Zero()) {
|
||||
return false
|
||||
}
|
||||
if !(f.Escape == false) {
|
||||
return false
|
||||
}
|
||||
if !(f.TTLSeconds == 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (f *FieldsMessage) String() string {
|
||||
if f == nil {
|
||||
return "FieldsMessage(nil)"
|
||||
}
|
||||
type Alias FieldsMessage
|
||||
return fmt.Sprintf("FieldsMessage%+v", Alias(*f))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*FieldsMessage) TypeID() uint32 {
|
||||
return FieldsMessageTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*FieldsMessage) TypeName() string {
|
||||
return "fieldsMessage"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (f *FieldsMessage) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "fieldsMessage",
|
||||
ID: FieldsMessageTypeID,
|
||||
}
|
||||
if f == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Escape",
|
||||
SchemaName: "escape",
|
||||
Null: !f.Flags.Has(0),
|
||||
},
|
||||
{
|
||||
Name: "TTLSeconds",
|
||||
SchemaName: "ttl_seconds",
|
||||
Null: !f.Flags.Has(1),
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// SetFlags sets flags for non-zero fields.
|
||||
func (f *FieldsMessage) SetFlags() {
|
||||
if !(f.Escape == false) {
|
||||
f.Flags.Set(0)
|
||||
}
|
||||
if !(f.TTLSeconds == 0) {
|
||||
f.Flags.Set(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (f *FieldsMessage) Encode(b *bin.Buffer) error {
|
||||
if f == nil {
|
||||
return fmt.Errorf("can't encode fieldsMessage#947225b5 as nil")
|
||||
}
|
||||
b.PutID(FieldsMessageTypeID)
|
||||
return f.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (f *FieldsMessage) EncodeBare(b *bin.Buffer) error {
|
||||
if f == nil {
|
||||
return fmt.Errorf("can't encode fieldsMessage#947225b5 as nil")
|
||||
}
|
||||
f.SetFlags()
|
||||
if err := f.Flags.Encode(b); err != nil {
|
||||
return fmt.Errorf("unable to encode fieldsMessage#947225b5: field flags: %w", err)
|
||||
}
|
||||
if f.Flags.Has(0) {
|
||||
b.PutBool(f.Escape)
|
||||
}
|
||||
if f.Flags.Has(1) {
|
||||
b.PutInt(f.TTLSeconds)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (f *FieldsMessage) Decode(b *bin.Buffer) error {
|
||||
if f == nil {
|
||||
return fmt.Errorf("can't decode fieldsMessage#947225b5 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(FieldsMessageTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode fieldsMessage#947225b5: %w", err)
|
||||
}
|
||||
return f.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (f *FieldsMessage) DecodeBare(b *bin.Buffer) error {
|
||||
if f == nil {
|
||||
return fmt.Errorf("can't decode fieldsMessage#947225b5 to nil")
|
||||
}
|
||||
{
|
||||
if err := f.Flags.Decode(b); err != nil {
|
||||
return fmt.Errorf("unable to decode fieldsMessage#947225b5: field flags: %w", err)
|
||||
}
|
||||
}
|
||||
if f.Flags.Has(0) {
|
||||
value, err := b.Bool()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode fieldsMessage#947225b5: field escape: %w", err)
|
||||
}
|
||||
f.Escape = value
|
||||
}
|
||||
if f.Flags.Has(1) {
|
||||
value, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode fieldsMessage#947225b5: field ttl_seconds: %w", err)
|
||||
}
|
||||
f.TTLSeconds = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetEscape sets value of Escape conditional field.
|
||||
func (f *FieldsMessage) SetEscape(value bool) {
|
||||
f.Flags.Set(0)
|
||||
f.Escape = value
|
||||
}
|
||||
|
||||
// GetEscape returns value of Escape conditional field and
|
||||
// boolean which is true if field was set.
|
||||
func (f *FieldsMessage) GetEscape() (value bool, ok bool) {
|
||||
if f == nil {
|
||||
return
|
||||
}
|
||||
if !f.Flags.Has(0) {
|
||||
return value, false
|
||||
}
|
||||
return f.Escape, true
|
||||
}
|
||||
|
||||
// SetTTLSeconds sets value of TTLSeconds conditional field.
|
||||
func (f *FieldsMessage) SetTTLSeconds(value int) {
|
||||
f.Flags.Set(1)
|
||||
f.TTLSeconds = value
|
||||
}
|
||||
|
||||
// GetTTLSeconds returns value of TTLSeconds conditional field and
|
||||
// boolean which is true if field was set.
|
||||
func (f *FieldsMessage) GetTTLSeconds() (value int, ok bool) {
|
||||
if f == nil {
|
||||
return
|
||||
}
|
||||
if !f.Flags.Has(1) {
|
||||
return value, false
|
||||
}
|
||||
return f.TTLSeconds, true
|
||||
}
|
||||
|
||||
// BytesMessage represents TL type `bytesMessage#f990a67d`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/bytesMessage for reference.
|
||||
type BytesMessage struct {
|
||||
// Data field of BytesMessage.
|
||||
Data []byte
|
||||
}
|
||||
|
||||
// BytesMessageTypeID is TL type id of BytesMessage.
|
||||
const BytesMessageTypeID = 0xf990a67d
|
||||
|
||||
// construct implements constructor of AbstractMessageClass.
|
||||
func (b BytesMessage) construct() AbstractMessageClass { return &b }
|
||||
|
||||
// Ensuring interfaces in compile-time for BytesMessage.
|
||||
var (
|
||||
_ bin.Encoder = &BytesMessage{}
|
||||
_ bin.Decoder = &BytesMessage{}
|
||||
_ bin.BareEncoder = &BytesMessage{}
|
||||
_ bin.BareDecoder = &BytesMessage{}
|
||||
|
||||
_ AbstractMessageClass = &BytesMessage{}
|
||||
)
|
||||
|
||||
func (b *BytesMessage) Zero() bool {
|
||||
if b == nil {
|
||||
return true
|
||||
}
|
||||
if !(b.Data == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (b *BytesMessage) String() string {
|
||||
if b == nil {
|
||||
return "BytesMessage(nil)"
|
||||
}
|
||||
type Alias BytesMessage
|
||||
return fmt.Sprintf("BytesMessage%+v", Alias(*b))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*BytesMessage) TypeID() uint32 {
|
||||
return BytesMessageTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*BytesMessage) TypeName() string {
|
||||
return "bytesMessage"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (b *BytesMessage) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "bytesMessage",
|
||||
ID: BytesMessageTypeID,
|
||||
}
|
||||
if b == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Data",
|
||||
SchemaName: "data",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (b *BytesMessage) Encode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't encode bytesMessage#f990a67d as nil")
|
||||
}
|
||||
buf.PutID(BytesMessageTypeID)
|
||||
return b.EncodeBare(buf)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (b *BytesMessage) EncodeBare(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't encode bytesMessage#f990a67d as nil")
|
||||
}
|
||||
buf.PutBytes(b.Data)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (b *BytesMessage) Decode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't decode bytesMessage#f990a67d to nil")
|
||||
}
|
||||
if err := buf.ConsumeID(BytesMessageTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode bytesMessage#f990a67d: %w", err)
|
||||
}
|
||||
return b.DecodeBare(buf)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (b *BytesMessage) DecodeBare(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't decode bytesMessage#f990a67d to nil")
|
||||
}
|
||||
{
|
||||
value, err := buf.Bytes()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode bytesMessage#f990a67d: field data: %w", err)
|
||||
}
|
||||
b.Data = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetData returns value of Data field.
|
||||
func (b *BytesMessage) GetData() (value []byte) {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
return b.Data
|
||||
}
|
||||
|
||||
// AbstractMessageClassName is schema name of AbstractMessageClass.
|
||||
const AbstractMessageClassName = "AbstractMessage"
|
||||
|
||||
// AbstractMessageClass represents AbstractMessage generic type.
|
||||
//
|
||||
// See https://localhost:80/doc/type/AbstractMessage for reference.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// g, err := td.DecodeAbstractMessage(buf)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// switch v := g.(type) {
|
||||
// case *td.BigMessage: // bigMessage#7490dcc5
|
||||
// case *td.NoMessage: // noMessage#ee6324c4
|
||||
// case *td.TargetsMessage: // targetsMessage#cc6136f1
|
||||
// case *td.FieldsMessage: // fieldsMessage#947225b5
|
||||
// case *td.BytesMessage: // bytesMessage#f990a67d
|
||||
// default: panic(v)
|
||||
// }
|
||||
type AbstractMessageClass interface {
|
||||
bin.Encoder
|
||||
bin.Decoder
|
||||
bin.BareEncoder
|
||||
bin.BareDecoder
|
||||
construct() AbstractMessageClass
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
TypeID() uint32
|
||||
// TypeName returns name of type in TL schema.
|
||||
TypeName() string
|
||||
// String implements fmt.Stringer.
|
||||
String() string
|
||||
// Zero returns true if current object has a zero value.
|
||||
Zero() bool
|
||||
}
|
||||
|
||||
// DecodeAbstractMessage implements binary de-serialization for AbstractMessageClass.
|
||||
func DecodeAbstractMessage(buf *bin.Buffer) (AbstractMessageClass, error) {
|
||||
id, err := buf.PeekID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch id {
|
||||
case BigMessageTypeID:
|
||||
// Decoding bigMessage#7490dcc5.
|
||||
v := BigMessage{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode AbstractMessageClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
case NoMessageTypeID:
|
||||
// Decoding noMessage#ee6324c4.
|
||||
v := NoMessage{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode AbstractMessageClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
case TargetsMessageTypeID:
|
||||
// Decoding targetsMessage#cc6136f1.
|
||||
v := TargetsMessage{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode AbstractMessageClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
case FieldsMessageTypeID:
|
||||
// Decoding fieldsMessage#947225b5.
|
||||
v := FieldsMessage{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode AbstractMessageClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
case BytesMessageTypeID:
|
||||
// Decoding bytesMessage#f990a67d.
|
||||
v := BytesMessage{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode AbstractMessageClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to decode AbstractMessageClass: %w", bin.NewUnexpectedID(id))
|
||||
}
|
||||
}
|
||||
|
||||
// AbstractMessage boxes the AbstractMessageClass providing a helper.
|
||||
type AbstractMessageBox struct {
|
||||
AbstractMessage AbstractMessageClass
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder for AbstractMessageBox.
|
||||
func (b *AbstractMessageBox) Decode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("unable to decode AbstractMessageBox to nil")
|
||||
}
|
||||
v, err := DecodeAbstractMessage(buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode boxed value: %w", err)
|
||||
}
|
||||
b.AbstractMessage = v
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode implements bin.Encode for AbstractMessageBox.
|
||||
func (b *AbstractMessageBox) Encode(buf *bin.Buffer) error {
|
||||
if b == nil || b.AbstractMessage == nil {
|
||||
return fmt.Errorf("unable to encode AbstractMessageClass as nil")
|
||||
}
|
||||
return b.AbstractMessage.Encode(buf)
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// AccountThemesNotModified represents TL type `account.themesNotModified#f41eb622`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/account.themesNotModified for reference.
|
||||
type AccountThemesNotModified struct {
|
||||
}
|
||||
|
||||
// AccountThemesNotModifiedTypeID is TL type id of AccountThemesNotModified.
|
||||
const AccountThemesNotModifiedTypeID = 0xf41eb622
|
||||
|
||||
// construct implements constructor of AccountThemesClass.
|
||||
func (t AccountThemesNotModified) construct() AccountThemesClass { return &t }
|
||||
|
||||
// Ensuring interfaces in compile-time for AccountThemesNotModified.
|
||||
var (
|
||||
_ bin.Encoder = &AccountThemesNotModified{}
|
||||
_ bin.Decoder = &AccountThemesNotModified{}
|
||||
_ bin.BareEncoder = &AccountThemesNotModified{}
|
||||
_ bin.BareDecoder = &AccountThemesNotModified{}
|
||||
|
||||
_ AccountThemesClass = &AccountThemesNotModified{}
|
||||
)
|
||||
|
||||
func (t *AccountThemesNotModified) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *AccountThemesNotModified) String() string {
|
||||
if t == nil {
|
||||
return "AccountThemesNotModified(nil)"
|
||||
}
|
||||
type Alias AccountThemesNotModified
|
||||
return fmt.Sprintf("AccountThemesNotModified%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*AccountThemesNotModified) TypeID() uint32 {
|
||||
return AccountThemesNotModifiedTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*AccountThemesNotModified) TypeName() string {
|
||||
return "account.themesNotModified"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *AccountThemesNotModified) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "account.themesNotModified",
|
||||
ID: AccountThemesNotModifiedTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *AccountThemesNotModified) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode account.themesNotModified#f41eb622 as nil")
|
||||
}
|
||||
b.PutID(AccountThemesNotModifiedTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *AccountThemesNotModified) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode account.themesNotModified#f41eb622 as nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *AccountThemesNotModified) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode account.themesNotModified#f41eb622 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(AccountThemesNotModifiedTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode account.themesNotModified#f41eb622: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *AccountThemesNotModified) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode account.themesNotModified#f41eb622 to nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccountThemes represents TL type `account.themes#7f676421`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/account.themes for reference.
|
||||
type AccountThemes struct {
|
||||
// Hash field of AccountThemes.
|
||||
Hash int
|
||||
// Themes field of AccountThemes.
|
||||
Themes []Theme
|
||||
}
|
||||
|
||||
// AccountThemesTypeID is TL type id of AccountThemes.
|
||||
const AccountThemesTypeID = 0x7f676421
|
||||
|
||||
// construct implements constructor of AccountThemesClass.
|
||||
func (t AccountThemes) construct() AccountThemesClass { return &t }
|
||||
|
||||
// Ensuring interfaces in compile-time for AccountThemes.
|
||||
var (
|
||||
_ bin.Encoder = &AccountThemes{}
|
||||
_ bin.Decoder = &AccountThemes{}
|
||||
_ bin.BareEncoder = &AccountThemes{}
|
||||
_ bin.BareDecoder = &AccountThemes{}
|
||||
|
||||
_ AccountThemesClass = &AccountThemes{}
|
||||
)
|
||||
|
||||
func (t *AccountThemes) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Hash == 0) {
|
||||
return false
|
||||
}
|
||||
if !(t.Themes == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *AccountThemes) String() string {
|
||||
if t == nil {
|
||||
return "AccountThemes(nil)"
|
||||
}
|
||||
type Alias AccountThemes
|
||||
return fmt.Sprintf("AccountThemes%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*AccountThemes) TypeID() uint32 {
|
||||
return AccountThemesTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*AccountThemes) TypeName() string {
|
||||
return "account.themes"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *AccountThemes) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "account.themes",
|
||||
ID: AccountThemesTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Hash",
|
||||
SchemaName: "hash",
|
||||
},
|
||||
{
|
||||
Name: "Themes",
|
||||
SchemaName: "themes",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *AccountThemes) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode account.themes#7f676421 as nil")
|
||||
}
|
||||
b.PutID(AccountThemesTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *AccountThemes) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode account.themes#7f676421 as nil")
|
||||
}
|
||||
b.PutInt(t.Hash)
|
||||
b.PutVectorHeader(len(t.Themes))
|
||||
for idx, v := range t.Themes {
|
||||
if err := v.Encode(b); err != nil {
|
||||
return fmt.Errorf("unable to encode account.themes#7f676421: field themes element with index %d: %w", idx, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *AccountThemes) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode account.themes#7f676421 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(AccountThemesTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode account.themes#7f676421: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *AccountThemes) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode account.themes#7f676421 to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode account.themes#7f676421: field hash: %w", err)
|
||||
}
|
||||
t.Hash = value
|
||||
}
|
||||
{
|
||||
headerLen, err := b.VectorHeader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode account.themes#7f676421: field themes: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
t.Themes = make([]Theme, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
var value Theme
|
||||
if err := value.Decode(b); err != nil {
|
||||
return fmt.Errorf("unable to decode account.themes#7f676421: field themes: %w", err)
|
||||
}
|
||||
t.Themes = append(t.Themes, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetHash returns value of Hash field.
|
||||
func (t *AccountThemes) GetHash() (value int) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Hash
|
||||
}
|
||||
|
||||
// GetThemes returns value of Themes field.
|
||||
func (t *AccountThemes) GetThemes() (value []Theme) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Themes
|
||||
}
|
||||
|
||||
// AccountThemesClassName is schema name of AccountThemesClass.
|
||||
const AccountThemesClassName = "account.Themes"
|
||||
|
||||
// AccountThemesClass represents account.Themes generic type.
|
||||
//
|
||||
// See https://localhost:80/doc/type/account.Themes for reference.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// g, err := td.DecodeAccountThemes(buf)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// switch v := g.(type) {
|
||||
// case *td.AccountThemesNotModified: // account.themesNotModified#f41eb622
|
||||
// case *td.AccountThemes: // account.themes#7f676421
|
||||
// default: panic(v)
|
||||
// }
|
||||
type AccountThemesClass interface {
|
||||
bin.Encoder
|
||||
bin.Decoder
|
||||
bin.BareEncoder
|
||||
bin.BareDecoder
|
||||
construct() AccountThemesClass
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
TypeID() uint32
|
||||
// TypeName returns name of type in TL schema.
|
||||
TypeName() string
|
||||
// String implements fmt.Stringer.
|
||||
String() string
|
||||
// Zero returns true if current object has a zero value.
|
||||
Zero() bool
|
||||
}
|
||||
|
||||
// DecodeAccountThemes implements binary de-serialization for AccountThemesClass.
|
||||
func DecodeAccountThemes(buf *bin.Buffer) (AccountThemesClass, error) {
|
||||
id, err := buf.PeekID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch id {
|
||||
case AccountThemesNotModifiedTypeID:
|
||||
// Decoding account.themesNotModified#f41eb622.
|
||||
v := AccountThemesNotModified{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode AccountThemesClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
case AccountThemesTypeID:
|
||||
// Decoding account.themes#7f676421.
|
||||
v := AccountThemes{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode AccountThemesClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to decode AccountThemesClass: %w", bin.NewUnexpectedID(id))
|
||||
}
|
||||
}
|
||||
|
||||
// AccountThemes boxes the AccountThemesClass providing a helper.
|
||||
type AccountThemesBox struct {
|
||||
Themes AccountThemesClass
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder for AccountThemesBox.
|
||||
func (b *AccountThemesBox) Decode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("unable to decode AccountThemesBox to nil")
|
||||
}
|
||||
v, err := DecodeAccountThemes(buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode boxed value: %w", err)
|
||||
}
|
||||
b.Themes = v
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode implements bin.Encode for AccountThemesBox.
|
||||
func (b *AccountThemesBox) Encode(buf *bin.Buffer) error {
|
||||
if b == nil || b.Themes == nil {
|
||||
return fmt.Errorf("unable to encode AccountThemesClass as nil")
|
||||
}
|
||||
return b.Themes.Encode(buf)
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// Auth represents TL type `auth#f8bb4a38`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/auth for reference.
|
||||
type Auth struct {
|
||||
// Name field of Auth.
|
||||
Name string
|
||||
}
|
||||
|
||||
// AuthTypeID is TL type id of Auth.
|
||||
const AuthTypeID = 0xf8bb4a38
|
||||
|
||||
// construct implements constructor of AuthClass.
|
||||
func (a Auth) construct() AuthClass { return &a }
|
||||
|
||||
// Ensuring interfaces in compile-time for Auth.
|
||||
var (
|
||||
_ bin.Encoder = &Auth{}
|
||||
_ bin.Decoder = &Auth{}
|
||||
_ bin.BareEncoder = &Auth{}
|
||||
_ bin.BareDecoder = &Auth{}
|
||||
|
||||
_ AuthClass = &Auth{}
|
||||
)
|
||||
|
||||
func (a *Auth) Zero() bool {
|
||||
if a == nil {
|
||||
return true
|
||||
}
|
||||
if !(a.Name == "") {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (a *Auth) String() string {
|
||||
if a == nil {
|
||||
return "Auth(nil)"
|
||||
}
|
||||
type Alias Auth
|
||||
return fmt.Sprintf("Auth%+v", Alias(*a))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*Auth) TypeID() uint32 {
|
||||
return AuthTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*Auth) TypeName() string {
|
||||
return "auth"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (a *Auth) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "auth",
|
||||
ID: AuthTypeID,
|
||||
}
|
||||
if a == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Name",
|
||||
SchemaName: "name",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (a *Auth) Encode(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't encode auth#f8bb4a38 as nil")
|
||||
}
|
||||
b.PutID(AuthTypeID)
|
||||
return a.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (a *Auth) EncodeBare(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't encode auth#f8bb4a38 as nil")
|
||||
}
|
||||
b.PutString(a.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (a *Auth) Decode(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't decode auth#f8bb4a38 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(AuthTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode auth#f8bb4a38: %w", err)
|
||||
}
|
||||
return a.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (a *Auth) DecodeBare(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't decode auth#f8bb4a38 to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode auth#f8bb4a38: field name: %w", err)
|
||||
}
|
||||
a.Name = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetName returns value of Name field.
|
||||
func (a *Auth) GetName() (value string) {
|
||||
if a == nil {
|
||||
return
|
||||
}
|
||||
return a.Name
|
||||
}
|
||||
|
||||
// AuthPassword represents TL type `authPassword#29bacabb`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/authPassword for reference.
|
||||
type AuthPassword struct {
|
||||
// Name field of AuthPassword.
|
||||
Name string
|
||||
// Password field of AuthPassword.
|
||||
Password string
|
||||
}
|
||||
|
||||
// AuthPasswordTypeID is TL type id of AuthPassword.
|
||||
const AuthPasswordTypeID = 0x29bacabb
|
||||
|
||||
// construct implements constructor of AuthClass.
|
||||
func (a AuthPassword) construct() AuthClass { return &a }
|
||||
|
||||
// Ensuring interfaces in compile-time for AuthPassword.
|
||||
var (
|
||||
_ bin.Encoder = &AuthPassword{}
|
||||
_ bin.Decoder = &AuthPassword{}
|
||||
_ bin.BareEncoder = &AuthPassword{}
|
||||
_ bin.BareDecoder = &AuthPassword{}
|
||||
|
||||
_ AuthClass = &AuthPassword{}
|
||||
)
|
||||
|
||||
func (a *AuthPassword) Zero() bool {
|
||||
if a == nil {
|
||||
return true
|
||||
}
|
||||
if !(a.Name == "") {
|
||||
return false
|
||||
}
|
||||
if !(a.Password == "") {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (a *AuthPassword) String() string {
|
||||
if a == nil {
|
||||
return "AuthPassword(nil)"
|
||||
}
|
||||
type Alias AuthPassword
|
||||
return fmt.Sprintf("AuthPassword%+v", Alias(*a))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*AuthPassword) TypeID() uint32 {
|
||||
return AuthPasswordTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*AuthPassword) TypeName() string {
|
||||
return "authPassword"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (a *AuthPassword) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "authPassword",
|
||||
ID: AuthPasswordTypeID,
|
||||
}
|
||||
if a == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Name",
|
||||
SchemaName: "name",
|
||||
},
|
||||
{
|
||||
Name: "Password",
|
||||
SchemaName: "password",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (a *AuthPassword) Encode(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't encode authPassword#29bacabb as nil")
|
||||
}
|
||||
b.PutID(AuthPasswordTypeID)
|
||||
return a.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (a *AuthPassword) EncodeBare(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't encode authPassword#29bacabb as nil")
|
||||
}
|
||||
b.PutString(a.Name)
|
||||
b.PutString(a.Password)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (a *AuthPassword) Decode(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't decode authPassword#29bacabb to nil")
|
||||
}
|
||||
if err := b.ConsumeID(AuthPasswordTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode authPassword#29bacabb: %w", err)
|
||||
}
|
||||
return a.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (a *AuthPassword) DecodeBare(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't decode authPassword#29bacabb to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode authPassword#29bacabb: field name: %w", err)
|
||||
}
|
||||
a.Name = value
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode authPassword#29bacabb: field password: %w", err)
|
||||
}
|
||||
a.Password = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetName returns value of Name field.
|
||||
func (a *AuthPassword) GetName() (value string) {
|
||||
if a == nil {
|
||||
return
|
||||
}
|
||||
return a.Name
|
||||
}
|
||||
|
||||
// GetPassword returns value of Password field.
|
||||
func (a *AuthPassword) GetPassword() (value string) {
|
||||
if a == nil {
|
||||
return
|
||||
}
|
||||
return a.Password
|
||||
}
|
||||
|
||||
// AuthClassName is schema name of AuthClass.
|
||||
const AuthClassName = "Auth"
|
||||
|
||||
// AuthClass represents Auth generic type.
|
||||
//
|
||||
// See https://localhost:80/doc/type/Auth for reference.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// g, err := td.DecodeAuth(buf)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// switch v := g.(type) {
|
||||
// case *td.Auth: // auth#f8bb4a38
|
||||
// case *td.AuthPassword: // authPassword#29bacabb
|
||||
// default: panic(v)
|
||||
// }
|
||||
type AuthClass interface {
|
||||
bin.Encoder
|
||||
bin.Decoder
|
||||
bin.BareEncoder
|
||||
bin.BareDecoder
|
||||
construct() AuthClass
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
TypeID() uint32
|
||||
// TypeName returns name of type in TL schema.
|
||||
TypeName() string
|
||||
// String implements fmt.Stringer.
|
||||
String() string
|
||||
// Zero returns true if current object has a zero value.
|
||||
Zero() bool
|
||||
|
||||
// Name field of Auth.
|
||||
GetName() (value string)
|
||||
}
|
||||
|
||||
// DecodeAuth implements binary de-serialization for AuthClass.
|
||||
func DecodeAuth(buf *bin.Buffer) (AuthClass, error) {
|
||||
id, err := buf.PeekID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch id {
|
||||
case AuthTypeID:
|
||||
// Decoding auth#f8bb4a38.
|
||||
v := Auth{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode AuthClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
case AuthPasswordTypeID:
|
||||
// Decoding authPassword#29bacabb.
|
||||
v := AuthPassword{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode AuthClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to decode AuthClass: %w", bin.NewUnexpectedID(id))
|
||||
}
|
||||
}
|
||||
|
||||
// Auth boxes the AuthClass providing a helper.
|
||||
type AuthBox struct {
|
||||
Auth AuthClass
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder for AuthBox.
|
||||
func (b *AuthBox) Decode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("unable to decode AuthBox to nil")
|
||||
}
|
||||
v, err := DecodeAuth(buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode boxed value: %w", err)
|
||||
}
|
||||
b.Auth = v
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode implements bin.Encode for AuthBox.
|
||||
func (b *AuthBox) Encode(buf *bin.Buffer) error {
|
||||
if b == nil || b.Auth == nil {
|
||||
return fmt.Errorf("unable to encode AuthClass as nil")
|
||||
}
|
||||
return b.Auth.Encode(buf)
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// False represents TL type `false#bc799737`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/false for reference.
|
||||
type False struct {
|
||||
}
|
||||
|
||||
// FalseTypeID is TL type id of False.
|
||||
const FalseTypeID = 0xbc799737
|
||||
|
||||
// construct implements constructor of BoolClass.
|
||||
func (f False) construct() BoolClass { return &f }
|
||||
|
||||
// Ensuring interfaces in compile-time for False.
|
||||
var (
|
||||
_ bin.Encoder = &False{}
|
||||
_ bin.Decoder = &False{}
|
||||
_ bin.BareEncoder = &False{}
|
||||
_ bin.BareDecoder = &False{}
|
||||
|
||||
_ BoolClass = &False{}
|
||||
)
|
||||
|
||||
func (f *False) Zero() bool {
|
||||
if f == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (f *False) String() string {
|
||||
if f == nil {
|
||||
return "False(nil)"
|
||||
}
|
||||
type Alias False
|
||||
return fmt.Sprintf("False%+v", Alias(*f))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*False) TypeID() uint32 {
|
||||
return FalseTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*False) TypeName() string {
|
||||
return "false"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (f *False) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "false",
|
||||
ID: FalseTypeID,
|
||||
}
|
||||
if f == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (f *False) Encode(b *bin.Buffer) error {
|
||||
if f == nil {
|
||||
return fmt.Errorf("can't encode false#bc799737 as nil")
|
||||
}
|
||||
b.PutID(FalseTypeID)
|
||||
return f.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (f *False) EncodeBare(b *bin.Buffer) error {
|
||||
if f == nil {
|
||||
return fmt.Errorf("can't encode false#bc799737 as nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (f *False) Decode(b *bin.Buffer) error {
|
||||
if f == nil {
|
||||
return fmt.Errorf("can't decode false#bc799737 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(FalseTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode false#bc799737: %w", err)
|
||||
}
|
||||
return f.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (f *False) DecodeBare(b *bin.Buffer) error {
|
||||
if f == nil {
|
||||
return fmt.Errorf("can't decode false#bc799737 to nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// True represents TL type `true#997275b5`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/true for reference.
|
||||
type True struct {
|
||||
}
|
||||
|
||||
// TrueTypeID is TL type id of True.
|
||||
const TrueTypeID = 0x997275b5
|
||||
|
||||
// construct implements constructor of BoolClass.
|
||||
func (t True) construct() BoolClass { return &t }
|
||||
|
||||
// Ensuring interfaces in compile-time for True.
|
||||
var (
|
||||
_ bin.Encoder = &True{}
|
||||
_ bin.Decoder = &True{}
|
||||
_ bin.BareEncoder = &True{}
|
||||
_ bin.BareDecoder = &True{}
|
||||
|
||||
_ BoolClass = &True{}
|
||||
)
|
||||
|
||||
func (t *True) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *True) String() string {
|
||||
if t == nil {
|
||||
return "True(nil)"
|
||||
}
|
||||
type Alias True
|
||||
return fmt.Sprintf("True%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*True) TypeID() uint32 {
|
||||
return TrueTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*True) TypeName() string {
|
||||
return "true"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *True) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "true",
|
||||
ID: TrueTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *True) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode true#997275b5 as nil")
|
||||
}
|
||||
b.PutID(TrueTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *True) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode true#997275b5 as nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *True) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode true#997275b5 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TrueTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode true#997275b5: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *True) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode true#997275b5 to nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// BoolClassName is schema name of BoolClass.
|
||||
const BoolClassName = "Bool"
|
||||
|
||||
// BoolClass represents Bool generic type.
|
||||
//
|
||||
// See https://localhost:80/doc/type/Bool for reference.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// g, err := td.DecodeBool(buf)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// switch v := g.(type) {
|
||||
// case *td.False: // false#bc799737
|
||||
// case *td.True: // true#997275b5
|
||||
// default: panic(v)
|
||||
// }
|
||||
type BoolClass interface {
|
||||
bin.Encoder
|
||||
bin.Decoder
|
||||
bin.BareEncoder
|
||||
bin.BareDecoder
|
||||
construct() BoolClass
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
TypeID() uint32
|
||||
// TypeName returns name of type in TL schema.
|
||||
TypeName() string
|
||||
// String implements fmt.Stringer.
|
||||
String() string
|
||||
// Zero returns true if current object has a zero value.
|
||||
Zero() bool
|
||||
}
|
||||
|
||||
// DecodeBool implements binary de-serialization for BoolClass.
|
||||
func DecodeBool(buf *bin.Buffer) (BoolClass, error) {
|
||||
id, err := buf.PeekID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch id {
|
||||
case FalseTypeID:
|
||||
// Decoding false#bc799737.
|
||||
v := False{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode BoolClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
case TrueTypeID:
|
||||
// Decoding true#997275b5.
|
||||
v := True{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode BoolClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to decode BoolClass: %w", bin.NewUnexpectedID(id))
|
||||
}
|
||||
}
|
||||
|
||||
// Bool boxes the BoolClass providing a helper.
|
||||
type BoolBox struct {
|
||||
Bool BoolClass
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder for BoolBox.
|
||||
func (b *BoolBox) Decode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("unable to decode BoolBox to nil")
|
||||
}
|
||||
v, err := DecodeBool(buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode boxed value: %w", err)
|
||||
}
|
||||
b.Bool = v
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode implements bin.Encode for BoolBox.
|
||||
func (b *BoolBox) Encode(buf *bin.Buffer) error {
|
||||
if b == nil || b.Bool == nil {
|
||||
return fmt.Errorf("unable to encode BoolClass as nil")
|
||||
}
|
||||
return b.Bool.Encode(buf)
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// Bytes represents TL type `bytes#e937bb82`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/bytes for reference.
|
||||
type Bytes struct {
|
||||
}
|
||||
|
||||
// BytesTypeID is TL type id of Bytes.
|
||||
const BytesTypeID = 0xe937bb82
|
||||
|
||||
// Ensuring interfaces in compile-time for Bytes.
|
||||
var (
|
||||
_ bin.Encoder = &Bytes{}
|
||||
_ bin.Decoder = &Bytes{}
|
||||
_ bin.BareEncoder = &Bytes{}
|
||||
_ bin.BareDecoder = &Bytes{}
|
||||
)
|
||||
|
||||
func (b *Bytes) Zero() bool {
|
||||
if b == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (b *Bytes) String() string {
|
||||
if b == nil {
|
||||
return "Bytes(nil)"
|
||||
}
|
||||
type Alias Bytes
|
||||
return fmt.Sprintf("Bytes%+v", Alias(*b))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*Bytes) TypeID() uint32 {
|
||||
return BytesTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*Bytes) TypeName() string {
|
||||
return "bytes"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (b *Bytes) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "bytes",
|
||||
ID: BytesTypeID,
|
||||
}
|
||||
if b == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (b *Bytes) Encode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't encode bytes#e937bb82 as nil")
|
||||
}
|
||||
buf.PutID(BytesTypeID)
|
||||
return b.EncodeBare(buf)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (b *Bytes) EncodeBare(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't encode bytes#e937bb82 as nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (b *Bytes) Decode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't decode bytes#e937bb82 to nil")
|
||||
}
|
||||
if err := buf.ConsumeID(BytesTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode bytes#e937bb82: %w", err)
|
||||
}
|
||||
return b.DecodeBare(buf)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (b *Bytes) DecodeBare(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("can't decode bytes#e937bb82 to nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// ClientDHInnerData represents TL type `client_DH_inner_data#6643b654`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/client_DH_inner_data for reference.
|
||||
type ClientDHInnerData struct {
|
||||
// Nonce field of ClientDHInnerData.
|
||||
Nonce bin.Int128
|
||||
// ServerNonce field of ClientDHInnerData.
|
||||
ServerNonce bin.Int128
|
||||
// RetryID field of ClientDHInnerData.
|
||||
RetryID int64
|
||||
// GB field of ClientDHInnerData.
|
||||
GB string
|
||||
}
|
||||
|
||||
// ClientDHInnerDataTypeID is TL type id of ClientDHInnerData.
|
||||
const ClientDHInnerDataTypeID = 0x6643b654
|
||||
|
||||
// Ensuring interfaces in compile-time for ClientDHInnerData.
|
||||
var (
|
||||
_ bin.Encoder = &ClientDHInnerData{}
|
||||
_ bin.Decoder = &ClientDHInnerData{}
|
||||
_ bin.BareEncoder = &ClientDHInnerData{}
|
||||
_ bin.BareDecoder = &ClientDHInnerData{}
|
||||
)
|
||||
|
||||
func (c *ClientDHInnerData) Zero() bool {
|
||||
if c == nil {
|
||||
return true
|
||||
}
|
||||
if !(c.Nonce == bin.Int128{}) {
|
||||
return false
|
||||
}
|
||||
if !(c.ServerNonce == bin.Int128{}) {
|
||||
return false
|
||||
}
|
||||
if !(c.RetryID == 0) {
|
||||
return false
|
||||
}
|
||||
if !(c.GB == "") {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (c *ClientDHInnerData) String() string {
|
||||
if c == nil {
|
||||
return "ClientDHInnerData(nil)"
|
||||
}
|
||||
type Alias ClientDHInnerData
|
||||
return fmt.Sprintf("ClientDHInnerData%+v", Alias(*c))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*ClientDHInnerData) TypeID() uint32 {
|
||||
return ClientDHInnerDataTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*ClientDHInnerData) TypeName() string {
|
||||
return "client_DH_inner_data"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (c *ClientDHInnerData) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "client_DH_inner_data",
|
||||
ID: ClientDHInnerDataTypeID,
|
||||
}
|
||||
if c == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Nonce",
|
||||
SchemaName: "nonce",
|
||||
},
|
||||
{
|
||||
Name: "ServerNonce",
|
||||
SchemaName: "server_nonce",
|
||||
},
|
||||
{
|
||||
Name: "RetryID",
|
||||
SchemaName: "retry_id",
|
||||
},
|
||||
{
|
||||
Name: "GB",
|
||||
SchemaName: "g_b",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (c *ClientDHInnerData) Encode(b *bin.Buffer) error {
|
||||
if c == nil {
|
||||
return fmt.Errorf("can't encode client_DH_inner_data#6643b654 as nil")
|
||||
}
|
||||
b.PutID(ClientDHInnerDataTypeID)
|
||||
return c.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (c *ClientDHInnerData) EncodeBare(b *bin.Buffer) error {
|
||||
if c == nil {
|
||||
return fmt.Errorf("can't encode client_DH_inner_data#6643b654 as nil")
|
||||
}
|
||||
b.PutInt128(c.Nonce)
|
||||
b.PutInt128(c.ServerNonce)
|
||||
b.PutLong(c.RetryID)
|
||||
b.PutString(c.GB)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (c *ClientDHInnerData) Decode(b *bin.Buffer) error {
|
||||
if c == nil {
|
||||
return fmt.Errorf("can't decode client_DH_inner_data#6643b654 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(ClientDHInnerDataTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode client_DH_inner_data#6643b654: %w", err)
|
||||
}
|
||||
return c.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (c *ClientDHInnerData) DecodeBare(b *bin.Buffer) error {
|
||||
if c == nil {
|
||||
return fmt.Errorf("can't decode client_DH_inner_data#6643b654 to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.Int128()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode client_DH_inner_data#6643b654: field nonce: %w", err)
|
||||
}
|
||||
c.Nonce = value
|
||||
}
|
||||
{
|
||||
value, err := b.Int128()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode client_DH_inner_data#6643b654: field server_nonce: %w", err)
|
||||
}
|
||||
c.ServerNonce = value
|
||||
}
|
||||
{
|
||||
value, err := b.Long()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode client_DH_inner_data#6643b654: field retry_id: %w", err)
|
||||
}
|
||||
c.RetryID = value
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode client_DH_inner_data#6643b654: field g_b: %w", err)
|
||||
}
|
||||
c.GB = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetNonce returns value of Nonce field.
|
||||
func (c *ClientDHInnerData) GetNonce() (value bin.Int128) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
return c.Nonce
|
||||
}
|
||||
|
||||
// GetServerNonce returns value of ServerNonce field.
|
||||
func (c *ClientDHInnerData) GetServerNonce() (value bin.Int128) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
return c.ServerNonce
|
||||
}
|
||||
|
||||
// GetRetryID returns value of RetryID field.
|
||||
func (c *ClientDHInnerData) GetRetryID() (value int64) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
return c.RetryID
|
||||
}
|
||||
|
||||
// GetGB returns value of GB field.
|
||||
func (c *ClientDHInnerData) GetGB() (value string) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
return c.GB
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// Invoker can invoke raw MTProto rpc calls.
|
||||
type Invoker interface {
|
||||
Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder) error
|
||||
}
|
||||
|
||||
// Client implement methods for calling functions from TL schema via Invoker.
|
||||
type Client struct {
|
||||
rpc Invoker
|
||||
}
|
||||
|
||||
// Invoker returns Invoker used by this client.
|
||||
func (c *Client) Invoker() Invoker {
|
||||
return c.rpc
|
||||
}
|
||||
|
||||
// NewClient creates new Client.
|
||||
func NewClient(invoker Invoker) *Client {
|
||||
return &Client{
|
||||
rpc: invoker,
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,430 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// DCOption represents TL type `dcOption#18b7a10d`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/dcOption for reference.
|
||||
type DCOption struct {
|
||||
// Flags field of DCOption.
|
||||
Flags bin.Fields
|
||||
// Ipv6 field of DCOption.
|
||||
Ipv6 bool
|
||||
// MediaOnly field of DCOption.
|
||||
MediaOnly bool
|
||||
// TCPObfuscatedOnly field of DCOption.
|
||||
TCPObfuscatedOnly bool
|
||||
// CDN field of DCOption.
|
||||
CDN bool
|
||||
// Static field of DCOption.
|
||||
Static bool
|
||||
// ID field of DCOption.
|
||||
ID int
|
||||
// IPAddress field of DCOption.
|
||||
IPAddress string
|
||||
// Port field of DCOption.
|
||||
Port int
|
||||
// Secret field of DCOption.
|
||||
//
|
||||
// Use SetSecret and GetSecret helpers.
|
||||
Secret []byte
|
||||
}
|
||||
|
||||
// DCOptionTypeID is TL type id of DCOption.
|
||||
const DCOptionTypeID = 0x18b7a10d
|
||||
|
||||
// Ensuring interfaces in compile-time for DCOption.
|
||||
var (
|
||||
_ bin.Encoder = &DCOption{}
|
||||
_ bin.Decoder = &DCOption{}
|
||||
_ bin.BareEncoder = &DCOption{}
|
||||
_ bin.BareDecoder = &DCOption{}
|
||||
)
|
||||
|
||||
func (d *DCOption) Zero() bool {
|
||||
if d == nil {
|
||||
return true
|
||||
}
|
||||
if !(d.Flags.Zero()) {
|
||||
return false
|
||||
}
|
||||
if !(d.Ipv6 == false) {
|
||||
return false
|
||||
}
|
||||
if !(d.MediaOnly == false) {
|
||||
return false
|
||||
}
|
||||
if !(d.TCPObfuscatedOnly == false) {
|
||||
return false
|
||||
}
|
||||
if !(d.CDN == false) {
|
||||
return false
|
||||
}
|
||||
if !(d.Static == false) {
|
||||
return false
|
||||
}
|
||||
if !(d.ID == 0) {
|
||||
return false
|
||||
}
|
||||
if !(d.IPAddress == "") {
|
||||
return false
|
||||
}
|
||||
if !(d.Port == 0) {
|
||||
return false
|
||||
}
|
||||
if !(d.Secret == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (d *DCOption) String() string {
|
||||
if d == nil {
|
||||
return "DCOption(nil)"
|
||||
}
|
||||
type Alias DCOption
|
||||
return fmt.Sprintf("DCOption%+v", Alias(*d))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*DCOption) TypeID() uint32 {
|
||||
return DCOptionTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*DCOption) TypeName() string {
|
||||
return "dcOption"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (d *DCOption) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "dcOption",
|
||||
ID: DCOptionTypeID,
|
||||
}
|
||||
if d == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Ipv6",
|
||||
SchemaName: "ipv6",
|
||||
Null: !d.Flags.Has(0),
|
||||
},
|
||||
{
|
||||
Name: "MediaOnly",
|
||||
SchemaName: "media_only",
|
||||
Null: !d.Flags.Has(1),
|
||||
},
|
||||
{
|
||||
Name: "TCPObfuscatedOnly",
|
||||
SchemaName: "tcpo_only",
|
||||
Null: !d.Flags.Has(2),
|
||||
},
|
||||
{
|
||||
Name: "CDN",
|
||||
SchemaName: "cdn",
|
||||
Null: !d.Flags.Has(3),
|
||||
},
|
||||
{
|
||||
Name: "Static",
|
||||
SchemaName: "static",
|
||||
Null: !d.Flags.Has(4),
|
||||
},
|
||||
{
|
||||
Name: "ID",
|
||||
SchemaName: "id",
|
||||
},
|
||||
{
|
||||
Name: "IPAddress",
|
||||
SchemaName: "ip_address",
|
||||
},
|
||||
{
|
||||
Name: "Port",
|
||||
SchemaName: "port",
|
||||
},
|
||||
{
|
||||
Name: "Secret",
|
||||
SchemaName: "secret",
|
||||
Null: !d.Flags.Has(10),
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// SetFlags sets flags for non-zero fields.
|
||||
func (d *DCOption) SetFlags() {
|
||||
if !(d.Ipv6 == false) {
|
||||
d.Flags.Set(0)
|
||||
}
|
||||
if !(d.MediaOnly == false) {
|
||||
d.Flags.Set(1)
|
||||
}
|
||||
if !(d.TCPObfuscatedOnly == false) {
|
||||
d.Flags.Set(2)
|
||||
}
|
||||
if !(d.CDN == false) {
|
||||
d.Flags.Set(3)
|
||||
}
|
||||
if !(d.Static == false) {
|
||||
d.Flags.Set(4)
|
||||
}
|
||||
if !(d.Secret == nil) {
|
||||
d.Flags.Set(10)
|
||||
}
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (d *DCOption) Encode(b *bin.Buffer) error {
|
||||
if d == nil {
|
||||
return fmt.Errorf("can't encode dcOption#18b7a10d as nil")
|
||||
}
|
||||
b.PutID(DCOptionTypeID)
|
||||
return d.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (d *DCOption) EncodeBare(b *bin.Buffer) error {
|
||||
if d == nil {
|
||||
return fmt.Errorf("can't encode dcOption#18b7a10d as nil")
|
||||
}
|
||||
d.SetFlags()
|
||||
if err := d.Flags.Encode(b); err != nil {
|
||||
return fmt.Errorf("unable to encode dcOption#18b7a10d: field flags: %w", err)
|
||||
}
|
||||
b.PutInt(d.ID)
|
||||
b.PutString(d.IPAddress)
|
||||
b.PutInt(d.Port)
|
||||
if d.Flags.Has(10) {
|
||||
b.PutBytes(d.Secret)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (d *DCOption) Decode(b *bin.Buffer) error {
|
||||
if d == nil {
|
||||
return fmt.Errorf("can't decode dcOption#18b7a10d to nil")
|
||||
}
|
||||
if err := b.ConsumeID(DCOptionTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode dcOption#18b7a10d: %w", err)
|
||||
}
|
||||
return d.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (d *DCOption) DecodeBare(b *bin.Buffer) error {
|
||||
if d == nil {
|
||||
return fmt.Errorf("can't decode dcOption#18b7a10d to nil")
|
||||
}
|
||||
{
|
||||
if err := d.Flags.Decode(b); err != nil {
|
||||
return fmt.Errorf("unable to decode dcOption#18b7a10d: field flags: %w", err)
|
||||
}
|
||||
}
|
||||
d.Ipv6 = d.Flags.Has(0)
|
||||
d.MediaOnly = d.Flags.Has(1)
|
||||
d.TCPObfuscatedOnly = d.Flags.Has(2)
|
||||
d.CDN = d.Flags.Has(3)
|
||||
d.Static = d.Flags.Has(4)
|
||||
{
|
||||
value, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode dcOption#18b7a10d: field id: %w", err)
|
||||
}
|
||||
d.ID = value
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode dcOption#18b7a10d: field ip_address: %w", err)
|
||||
}
|
||||
d.IPAddress = value
|
||||
}
|
||||
{
|
||||
value, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode dcOption#18b7a10d: field port: %w", err)
|
||||
}
|
||||
d.Port = value
|
||||
}
|
||||
if d.Flags.Has(10) {
|
||||
value, err := b.Bytes()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode dcOption#18b7a10d: field secret: %w", err)
|
||||
}
|
||||
d.Secret = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetIpv6 sets value of Ipv6 conditional field.
|
||||
func (d *DCOption) SetIpv6(value bool) {
|
||||
if value {
|
||||
d.Flags.Set(0)
|
||||
d.Ipv6 = true
|
||||
} else {
|
||||
d.Flags.Unset(0)
|
||||
d.Ipv6 = false
|
||||
}
|
||||
}
|
||||
|
||||
// GetIpv6 returns value of Ipv6 conditional field.
|
||||
func (d *DCOption) GetIpv6() (value bool) {
|
||||
if d == nil {
|
||||
return
|
||||
}
|
||||
return d.Flags.Has(0)
|
||||
}
|
||||
|
||||
// SetMediaOnly sets value of MediaOnly conditional field.
|
||||
func (d *DCOption) SetMediaOnly(value bool) {
|
||||
if value {
|
||||
d.Flags.Set(1)
|
||||
d.MediaOnly = true
|
||||
} else {
|
||||
d.Flags.Unset(1)
|
||||
d.MediaOnly = false
|
||||
}
|
||||
}
|
||||
|
||||
// GetMediaOnly returns value of MediaOnly conditional field.
|
||||
func (d *DCOption) GetMediaOnly() (value bool) {
|
||||
if d == nil {
|
||||
return
|
||||
}
|
||||
return d.Flags.Has(1)
|
||||
}
|
||||
|
||||
// SetTCPObfuscatedOnly sets value of TCPObfuscatedOnly conditional field.
|
||||
func (d *DCOption) SetTCPObfuscatedOnly(value bool) {
|
||||
if value {
|
||||
d.Flags.Set(2)
|
||||
d.TCPObfuscatedOnly = true
|
||||
} else {
|
||||
d.Flags.Unset(2)
|
||||
d.TCPObfuscatedOnly = false
|
||||
}
|
||||
}
|
||||
|
||||
// GetTCPObfuscatedOnly returns value of TCPObfuscatedOnly conditional field.
|
||||
func (d *DCOption) GetTCPObfuscatedOnly() (value bool) {
|
||||
if d == nil {
|
||||
return
|
||||
}
|
||||
return d.Flags.Has(2)
|
||||
}
|
||||
|
||||
// SetCDN sets value of CDN conditional field.
|
||||
func (d *DCOption) SetCDN(value bool) {
|
||||
if value {
|
||||
d.Flags.Set(3)
|
||||
d.CDN = true
|
||||
} else {
|
||||
d.Flags.Unset(3)
|
||||
d.CDN = false
|
||||
}
|
||||
}
|
||||
|
||||
// GetCDN returns value of CDN conditional field.
|
||||
func (d *DCOption) GetCDN() (value bool) {
|
||||
if d == nil {
|
||||
return
|
||||
}
|
||||
return d.Flags.Has(3)
|
||||
}
|
||||
|
||||
// SetStatic sets value of Static conditional field.
|
||||
func (d *DCOption) SetStatic(value bool) {
|
||||
if value {
|
||||
d.Flags.Set(4)
|
||||
d.Static = true
|
||||
} else {
|
||||
d.Flags.Unset(4)
|
||||
d.Static = false
|
||||
}
|
||||
}
|
||||
|
||||
// GetStatic returns value of Static conditional field.
|
||||
func (d *DCOption) GetStatic() (value bool) {
|
||||
if d == nil {
|
||||
return
|
||||
}
|
||||
return d.Flags.Has(4)
|
||||
}
|
||||
|
||||
// GetID returns value of ID field.
|
||||
func (d *DCOption) GetID() (value int) {
|
||||
if d == nil {
|
||||
return
|
||||
}
|
||||
return d.ID
|
||||
}
|
||||
|
||||
// GetIPAddress returns value of IPAddress field.
|
||||
func (d *DCOption) GetIPAddress() (value string) {
|
||||
if d == nil {
|
||||
return
|
||||
}
|
||||
return d.IPAddress
|
||||
}
|
||||
|
||||
// GetPort returns value of Port field.
|
||||
func (d *DCOption) GetPort() (value int) {
|
||||
if d == nil {
|
||||
return
|
||||
}
|
||||
return d.Port
|
||||
}
|
||||
|
||||
// SetSecret sets value of Secret conditional field.
|
||||
func (d *DCOption) SetSecret(value []byte) {
|
||||
d.Flags.Set(10)
|
||||
d.Secret = value
|
||||
}
|
||||
|
||||
// GetSecret returns value of Secret conditional field and
|
||||
// boolean which is true if field was set.
|
||||
func (d *DCOption) GetSecret() (value []byte, ok bool) {
|
||||
if d == nil {
|
||||
return
|
||||
}
|
||||
if !d.Flags.Has(10) {
|
||||
return value, false
|
||||
}
|
||||
return d.Secret, true
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// DoAuthRequest represents TL type `doAuth#fd2f6687`.
|
||||
//
|
||||
// See https://localhost:80/doc/method/doAuth for reference.
|
||||
type DoAuthRequest struct {
|
||||
}
|
||||
|
||||
// DoAuthRequestTypeID is TL type id of DoAuthRequest.
|
||||
const DoAuthRequestTypeID = 0xfd2f6687
|
||||
|
||||
// Ensuring interfaces in compile-time for DoAuthRequest.
|
||||
var (
|
||||
_ bin.Encoder = &DoAuthRequest{}
|
||||
_ bin.Decoder = &DoAuthRequest{}
|
||||
_ bin.BareEncoder = &DoAuthRequest{}
|
||||
_ bin.BareDecoder = &DoAuthRequest{}
|
||||
)
|
||||
|
||||
func (d *DoAuthRequest) Zero() bool {
|
||||
if d == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (d *DoAuthRequest) String() string {
|
||||
if d == nil {
|
||||
return "DoAuthRequest(nil)"
|
||||
}
|
||||
type Alias DoAuthRequest
|
||||
return fmt.Sprintf("DoAuthRequest%+v", Alias(*d))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*DoAuthRequest) TypeID() uint32 {
|
||||
return DoAuthRequestTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*DoAuthRequest) TypeName() string {
|
||||
return "doAuth"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (d *DoAuthRequest) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "doAuth",
|
||||
ID: DoAuthRequestTypeID,
|
||||
}
|
||||
if d == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (d *DoAuthRequest) Encode(b *bin.Buffer) error {
|
||||
if d == nil {
|
||||
return fmt.Errorf("can't encode doAuth#fd2f6687 as nil")
|
||||
}
|
||||
b.PutID(DoAuthRequestTypeID)
|
||||
return d.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (d *DoAuthRequest) EncodeBare(b *bin.Buffer) error {
|
||||
if d == nil {
|
||||
return fmt.Errorf("can't encode doAuth#fd2f6687 as nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (d *DoAuthRequest) Decode(b *bin.Buffer) error {
|
||||
if d == nil {
|
||||
return fmt.Errorf("can't decode doAuth#fd2f6687 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(DoAuthRequestTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode doAuth#fd2f6687: %w", err)
|
||||
}
|
||||
return d.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (d *DoAuthRequest) DecodeBare(b *bin.Buffer) error {
|
||||
if d == nil {
|
||||
return fmt.Errorf("can't decode doAuth#fd2f6687 to nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DoAuth invokes method doAuth#fd2f6687 returning error if any.
|
||||
//
|
||||
// See https://localhost:80/doc/method/doAuth for reference.
|
||||
func (c *Client) DoAuth(ctx context.Context) (AuthClass, error) {
|
||||
var result AuthBox
|
||||
|
||||
request := &DoAuthRequest{}
|
||||
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.Auth, nil
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// EchoVectorRequest represents TL type `echoVector#d4785939`.
|
||||
//
|
||||
// See https://localhost:80/doc/method/echoVector for reference.
|
||||
type EchoVectorRequest struct {
|
||||
// IDs field of EchoVectorRequest.
|
||||
IDs []int
|
||||
}
|
||||
|
||||
// EchoVectorRequestTypeID is TL type id of EchoVectorRequest.
|
||||
const EchoVectorRequestTypeID = 0xd4785939
|
||||
|
||||
// Ensuring interfaces in compile-time for EchoVectorRequest.
|
||||
var (
|
||||
_ bin.Encoder = &EchoVectorRequest{}
|
||||
_ bin.Decoder = &EchoVectorRequest{}
|
||||
_ bin.BareEncoder = &EchoVectorRequest{}
|
||||
_ bin.BareDecoder = &EchoVectorRequest{}
|
||||
)
|
||||
|
||||
func (e *EchoVectorRequest) Zero() bool {
|
||||
if e == nil {
|
||||
return true
|
||||
}
|
||||
if !(e.IDs == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (e *EchoVectorRequest) String() string {
|
||||
if e == nil {
|
||||
return "EchoVectorRequest(nil)"
|
||||
}
|
||||
type Alias EchoVectorRequest
|
||||
return fmt.Sprintf("EchoVectorRequest%+v", Alias(*e))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*EchoVectorRequest) TypeID() uint32 {
|
||||
return EchoVectorRequestTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*EchoVectorRequest) TypeName() string {
|
||||
return "echoVector"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (e *EchoVectorRequest) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "echoVector",
|
||||
ID: EchoVectorRequestTypeID,
|
||||
}
|
||||
if e == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "IDs",
|
||||
SchemaName: "ids",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (e *EchoVectorRequest) Encode(b *bin.Buffer) error {
|
||||
if e == nil {
|
||||
return fmt.Errorf("can't encode echoVector#d4785939 as nil")
|
||||
}
|
||||
b.PutID(EchoVectorRequestTypeID)
|
||||
return e.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (e *EchoVectorRequest) EncodeBare(b *bin.Buffer) error {
|
||||
if e == nil {
|
||||
return fmt.Errorf("can't encode echoVector#d4785939 as nil")
|
||||
}
|
||||
b.PutVectorHeader(len(e.IDs))
|
||||
for _, v := range e.IDs {
|
||||
b.PutInt(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (e *EchoVectorRequest) Decode(b *bin.Buffer) error {
|
||||
if e == nil {
|
||||
return fmt.Errorf("can't decode echoVector#d4785939 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(EchoVectorRequestTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode echoVector#d4785939: %w", err)
|
||||
}
|
||||
return e.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (e *EchoVectorRequest) DecodeBare(b *bin.Buffer) error {
|
||||
if e == nil {
|
||||
return fmt.Errorf("can't decode echoVector#d4785939 to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.VectorHeader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode echoVector#d4785939: field ids: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
e.IDs = 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 echoVector#d4785939: field ids: %w", err)
|
||||
}
|
||||
e.IDs = append(e.IDs, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetIDs returns value of IDs field.
|
||||
func (e *EchoVectorRequest) GetIDs() (value []int) {
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
return e.IDs
|
||||
}
|
||||
|
||||
// EchoVector invokes method echoVector#d4785939 returning error if any.
|
||||
//
|
||||
// See https://localhost:80/doc/method/echoVector for reference.
|
||||
func (c *Client) EchoVector(ctx context.Context, ids []int) ([]int, error) {
|
||||
var result IntVector
|
||||
|
||||
request := &EchoVectorRequest{
|
||||
IDs: ids,
|
||||
}
|
||||
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []int(result.Elems), nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// Error represents TL type `error#14feebbc`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/error for reference.
|
||||
type Error struct {
|
||||
// Error code; subject to future changes. If the error code is 406, the error message
|
||||
// must not be processed in any way and must not be displayed to the user
|
||||
Code int32
|
||||
// Error message; subject to future changes
|
||||
Message string
|
||||
// Temporary field of Error.
|
||||
Temporary bool
|
||||
}
|
||||
|
||||
// ErrorTypeID is TL type id of Error.
|
||||
const ErrorTypeID = 0x14feebbc
|
||||
|
||||
// Ensuring interfaces in compile-time for Error.
|
||||
var (
|
||||
_ bin.Encoder = &Error{}
|
||||
_ bin.Decoder = &Error{}
|
||||
_ bin.BareEncoder = &Error{}
|
||||
_ bin.BareDecoder = &Error{}
|
||||
)
|
||||
|
||||
func (e *Error) Zero() bool {
|
||||
if e == nil {
|
||||
return true
|
||||
}
|
||||
if !(e.Code == 0) {
|
||||
return false
|
||||
}
|
||||
if !(e.Message == "") {
|
||||
return false
|
||||
}
|
||||
if !(e.Temporary == false) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (e *Error) String() string {
|
||||
if e == nil {
|
||||
return "Error(nil)"
|
||||
}
|
||||
type Alias Error
|
||||
return fmt.Sprintf("Error%+v", Alias(*e))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*Error) TypeID() uint32 {
|
||||
return ErrorTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*Error) TypeName() string {
|
||||
return "error"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (e *Error) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "error",
|
||||
ID: ErrorTypeID,
|
||||
}
|
||||
if e == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Code",
|
||||
SchemaName: "code",
|
||||
},
|
||||
{
|
||||
Name: "Message",
|
||||
SchemaName: "message",
|
||||
},
|
||||
{
|
||||
Name: "Temporary",
|
||||
SchemaName: "temporary",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (e *Error) Encode(b *bin.Buffer) error {
|
||||
if e == nil {
|
||||
return fmt.Errorf("can't encode error#14feebbc as nil")
|
||||
}
|
||||
b.PutID(ErrorTypeID)
|
||||
return e.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (e *Error) EncodeBare(b *bin.Buffer) error {
|
||||
if e == nil {
|
||||
return fmt.Errorf("can't encode error#14feebbc as nil")
|
||||
}
|
||||
b.PutInt32(e.Code)
|
||||
b.PutString(e.Message)
|
||||
b.PutBool(e.Temporary)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (e *Error) Decode(b *bin.Buffer) error {
|
||||
if e == nil {
|
||||
return fmt.Errorf("can't decode error#14feebbc to nil")
|
||||
}
|
||||
if err := b.ConsumeID(ErrorTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode error#14feebbc: %w", err)
|
||||
}
|
||||
return e.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (e *Error) DecodeBare(b *bin.Buffer) error {
|
||||
if e == nil {
|
||||
return fmt.Errorf("can't decode error#14feebbc to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode error#14feebbc: field code: %w", err)
|
||||
}
|
||||
e.Code = value
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode error#14feebbc: field message: %w", err)
|
||||
}
|
||||
e.Message = value
|
||||
}
|
||||
{
|
||||
value, err := b.Bool()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode error#14feebbc: field temporary: %w", err)
|
||||
}
|
||||
e.Temporary = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCode returns value of Code field.
|
||||
func (e *Error) GetCode() (value int32) {
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
return e.Code
|
||||
}
|
||||
|
||||
// GetMessage returns value of Message field.
|
||||
func (e *Error) GetMessage() (value string) {
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
return e.Message
|
||||
}
|
||||
|
||||
// GetTemporary returns value of Temporary field.
|
||||
func (e *Error) GetTemporary() (value bool) {
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
return e.Temporary
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// GetUpdatesResp represents TL type `getUpdatesResp#300bb5e1`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/getUpdatesResp for reference.
|
||||
type GetUpdatesResp struct {
|
||||
// Updates field of GetUpdatesResp.
|
||||
Updates []AbstractMessageClass
|
||||
}
|
||||
|
||||
// GetUpdatesRespTypeID is TL type id of GetUpdatesResp.
|
||||
const GetUpdatesRespTypeID = 0x300bb5e1
|
||||
|
||||
// Ensuring interfaces in compile-time for GetUpdatesResp.
|
||||
var (
|
||||
_ bin.Encoder = &GetUpdatesResp{}
|
||||
_ bin.Decoder = &GetUpdatesResp{}
|
||||
_ bin.BareEncoder = &GetUpdatesResp{}
|
||||
_ bin.BareDecoder = &GetUpdatesResp{}
|
||||
)
|
||||
|
||||
func (g *GetUpdatesResp) Zero() bool {
|
||||
if g == nil {
|
||||
return true
|
||||
}
|
||||
if !(g.Updates == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (g *GetUpdatesResp) String() string {
|
||||
if g == nil {
|
||||
return "GetUpdatesResp(nil)"
|
||||
}
|
||||
type Alias GetUpdatesResp
|
||||
return fmt.Sprintf("GetUpdatesResp%+v", Alias(*g))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*GetUpdatesResp) TypeID() uint32 {
|
||||
return GetUpdatesRespTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*GetUpdatesResp) TypeName() string {
|
||||
return "getUpdatesResp"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (g *GetUpdatesResp) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "getUpdatesResp",
|
||||
ID: GetUpdatesRespTypeID,
|
||||
}
|
||||
if g == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Updates",
|
||||
SchemaName: "updates",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (g *GetUpdatesResp) Encode(b *bin.Buffer) error {
|
||||
if g == nil {
|
||||
return fmt.Errorf("can't encode getUpdatesResp#300bb5e1 as nil")
|
||||
}
|
||||
b.PutID(GetUpdatesRespTypeID)
|
||||
return g.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (g *GetUpdatesResp) EncodeBare(b *bin.Buffer) error {
|
||||
if g == nil {
|
||||
return fmt.Errorf("can't encode getUpdatesResp#300bb5e1 as nil")
|
||||
}
|
||||
b.PutVectorHeader(len(g.Updates))
|
||||
for idx, v := range g.Updates {
|
||||
if v == nil {
|
||||
return fmt.Errorf("unable to encode getUpdatesResp#300bb5e1: field updates element with index %d is nil", idx)
|
||||
}
|
||||
if err := v.Encode(b); err != nil {
|
||||
return fmt.Errorf("unable to encode getUpdatesResp#300bb5e1: field updates element with index %d: %w", idx, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (g *GetUpdatesResp) Decode(b *bin.Buffer) error {
|
||||
if g == nil {
|
||||
return fmt.Errorf("can't decode getUpdatesResp#300bb5e1 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(GetUpdatesRespTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode getUpdatesResp#300bb5e1: %w", err)
|
||||
}
|
||||
return g.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (g *GetUpdatesResp) DecodeBare(b *bin.Buffer) error {
|
||||
if g == nil {
|
||||
return fmt.Errorf("can't decode getUpdatesResp#300bb5e1 to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.VectorHeader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode getUpdatesResp#300bb5e1: field updates: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
g.Updates = make([]AbstractMessageClass, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
value, err := DecodeAbstractMessage(b)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode getUpdatesResp#300bb5e1: field updates: %w", err)
|
||||
}
|
||||
g.Updates = append(g.Updates, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUpdates returns value of Updates field.
|
||||
func (g *GetUpdatesResp) GetUpdates() (value []AbstractMessageClass) {
|
||||
if g == nil {
|
||||
return
|
||||
}
|
||||
return g.Updates
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// Int32 represents TL type `int32#5cb934fa`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/int32 for reference.
|
||||
type Int32 struct {
|
||||
}
|
||||
|
||||
// Int32TypeID is TL type id of Int32.
|
||||
const Int32TypeID = 0x5cb934fa
|
||||
|
||||
// Ensuring interfaces in compile-time for Int32.
|
||||
var (
|
||||
_ bin.Encoder = &Int32{}
|
||||
_ bin.Decoder = &Int32{}
|
||||
_ bin.BareEncoder = &Int32{}
|
||||
_ bin.BareDecoder = &Int32{}
|
||||
)
|
||||
|
||||
func (i *Int32) Zero() bool {
|
||||
if i == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (i *Int32) String() string {
|
||||
if i == nil {
|
||||
return "Int32(nil)"
|
||||
}
|
||||
type Alias Int32
|
||||
return fmt.Sprintf("Int32%+v", Alias(*i))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*Int32) TypeID() uint32 {
|
||||
return Int32TypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*Int32) TypeName() string {
|
||||
return "int32"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (i *Int32) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "int32",
|
||||
ID: Int32TypeID,
|
||||
}
|
||||
if i == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (i *Int32) Encode(b *bin.Buffer) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("can't encode int32#5cb934fa as nil")
|
||||
}
|
||||
b.PutID(Int32TypeID)
|
||||
return i.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (i *Int32) EncodeBare(b *bin.Buffer) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("can't encode int32#5cb934fa as nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (i *Int32) Decode(b *bin.Buffer) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("can't decode int32#5cb934fa to nil")
|
||||
}
|
||||
if err := b.ConsumeID(Int32TypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode int32#5cb934fa: %w", err)
|
||||
}
|
||||
return i.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (i *Int32) DecodeBare(b *bin.Buffer) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("can't decode int32#5cb934fa to nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// IntVector is a box for Vector<int>
|
||||
type IntVector struct {
|
||||
// Elements of Vector<int>
|
||||
Elems []int
|
||||
}
|
||||
|
||||
// IntVectorTypeID is TL type id of IntVector.
|
||||
const IntVectorTypeID = bin.TypeVector
|
||||
|
||||
// Ensuring interfaces in compile-time for IntVector.
|
||||
var (
|
||||
_ bin.Encoder = &IntVector{}
|
||||
_ bin.Decoder = &IntVector{}
|
||||
_ bin.BareEncoder = &IntVector{}
|
||||
_ bin.BareDecoder = &IntVector{}
|
||||
)
|
||||
|
||||
func (vec *IntVector) Zero() bool {
|
||||
if vec == nil {
|
||||
return true
|
||||
}
|
||||
if !(vec.Elems == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (vec *IntVector) String() string {
|
||||
if vec == nil {
|
||||
return "IntVector(nil)"
|
||||
}
|
||||
type Alias IntVector
|
||||
return fmt.Sprintf("IntVector%+v", Alias(*vec))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*IntVector) TypeID() uint32 {
|
||||
return IntVectorTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*IntVector) TypeName() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (vec *IntVector) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "",
|
||||
ID: IntVectorTypeID,
|
||||
}
|
||||
if vec == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Elems",
|
||||
SchemaName: "Elems",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (vec *IntVector) Encode(b *bin.Buffer) error {
|
||||
if vec == nil {
|
||||
return fmt.Errorf("can't encode Vector<int> as nil")
|
||||
}
|
||||
|
||||
return vec.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (vec *IntVector) EncodeBare(b *bin.Buffer) error {
|
||||
if vec == nil {
|
||||
return fmt.Errorf("can't encode Vector<int> as nil")
|
||||
}
|
||||
b.PutVectorHeader(len(vec.Elems))
|
||||
for _, v := range vec.Elems {
|
||||
b.PutInt(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (vec *IntVector) Decode(b *bin.Buffer) error {
|
||||
if vec == nil {
|
||||
return fmt.Errorf("can't decode Vector<int> to nil")
|
||||
}
|
||||
|
||||
return vec.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (vec *IntVector) DecodeBare(b *bin.Buffer) error {
|
||||
if vec == nil {
|
||||
return fmt.Errorf("can't decode Vector<int> to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.VectorHeader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode Vector<int>: field Elems: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
vec.Elems = 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 Vector<int>: field Elems: %w", err)
|
||||
}
|
||||
vec.Elems = append(vec.Elems, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetElems returns value of Elems field.
|
||||
func (vec *IntVector) GetElems() (value []int) {
|
||||
if vec == nil {
|
||||
return
|
||||
}
|
||||
return vec.Elems
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// InvokeWithLayer represents TL type `invokeWithLayer#da9b0d0d`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/invokeWithLayer for reference.
|
||||
type InvokeWithLayer struct {
|
||||
// Layer field of InvokeWithLayer.
|
||||
Layer int
|
||||
// Query field of InvokeWithLayer.
|
||||
Query bin.Object
|
||||
}
|
||||
|
||||
// InvokeWithLayerTypeID is TL type id of InvokeWithLayer.
|
||||
const InvokeWithLayerTypeID = 0xda9b0d0d
|
||||
|
||||
// Ensuring interfaces in compile-time for InvokeWithLayer.
|
||||
var (
|
||||
_ bin.Encoder = &InvokeWithLayer{}
|
||||
_ bin.Decoder = &InvokeWithLayer{}
|
||||
_ bin.BareEncoder = &InvokeWithLayer{}
|
||||
_ bin.BareDecoder = &InvokeWithLayer{}
|
||||
)
|
||||
|
||||
func (i *InvokeWithLayer) Zero() bool {
|
||||
if i == nil {
|
||||
return true
|
||||
}
|
||||
if !(i.Layer == 0) {
|
||||
return false
|
||||
}
|
||||
if !(i.Query == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (i *InvokeWithLayer) String() string {
|
||||
if i == nil {
|
||||
return "InvokeWithLayer(nil)"
|
||||
}
|
||||
type Alias InvokeWithLayer
|
||||
return fmt.Sprintf("InvokeWithLayer%+v", Alias(*i))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*InvokeWithLayer) TypeID() uint32 {
|
||||
return InvokeWithLayerTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*InvokeWithLayer) TypeName() string {
|
||||
return "invokeWithLayer"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (i *InvokeWithLayer) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "invokeWithLayer",
|
||||
ID: InvokeWithLayerTypeID,
|
||||
}
|
||||
if i == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Layer",
|
||||
SchemaName: "layer",
|
||||
},
|
||||
{
|
||||
Name: "Query",
|
||||
SchemaName: "query",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (i *InvokeWithLayer) Encode(b *bin.Buffer) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("can't encode invokeWithLayer#da9b0d0d as nil")
|
||||
}
|
||||
b.PutID(InvokeWithLayerTypeID)
|
||||
return i.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (i *InvokeWithLayer) EncodeBare(b *bin.Buffer) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("can't encode invokeWithLayer#da9b0d0d as nil")
|
||||
}
|
||||
b.PutInt(i.Layer)
|
||||
if err := i.Query.Encode(b); err != nil {
|
||||
return fmt.Errorf("unable to encode invokeWithLayer#da9b0d0d: field query: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (i *InvokeWithLayer) Decode(b *bin.Buffer) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("can't decode invokeWithLayer#da9b0d0d to nil")
|
||||
}
|
||||
if err := b.ConsumeID(InvokeWithLayerTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode invokeWithLayer#da9b0d0d: %w", err)
|
||||
}
|
||||
return i.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (i *InvokeWithLayer) DecodeBare(b *bin.Buffer) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("can't decode invokeWithLayer#da9b0d0d to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode invokeWithLayer#da9b0d0d: field layer: %w", err)
|
||||
}
|
||||
i.Layer = value
|
||||
}
|
||||
{
|
||||
if err := i.Query.Decode(b); err != nil {
|
||||
return fmt.Errorf("unable to decode invokeWithLayer#da9b0d0d: field query: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetLayer returns value of Layer field.
|
||||
func (i *InvokeWithLayer) GetLayer() (value int) {
|
||||
if i == nil {
|
||||
return
|
||||
}
|
||||
return i.Layer
|
||||
}
|
||||
|
||||
// GetQuery returns value of Query field.
|
||||
func (i *InvokeWithLayer) GetQuery() (value bin.Object) {
|
||||
if i == nil {
|
||||
return
|
||||
}
|
||||
return i.Query
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// Message represents TL type `message#ec200d96`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/message for reference.
|
||||
type Message struct {
|
||||
// Err field of Message.
|
||||
Err Error
|
||||
}
|
||||
|
||||
// MessageTypeID is TL type id of Message.
|
||||
const MessageTypeID = 0xec200d96
|
||||
|
||||
// Ensuring interfaces in compile-time for Message.
|
||||
var (
|
||||
_ bin.Encoder = &Message{}
|
||||
_ bin.Decoder = &Message{}
|
||||
_ bin.BareEncoder = &Message{}
|
||||
_ bin.BareDecoder = &Message{}
|
||||
)
|
||||
|
||||
func (m *Message) Zero() bool {
|
||||
if m == nil {
|
||||
return true
|
||||
}
|
||||
if !(m.Err.Zero()) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (m *Message) String() string {
|
||||
if m == nil {
|
||||
return "Message(nil)"
|
||||
}
|
||||
type Alias Message
|
||||
return fmt.Sprintf("Message%+v", Alias(*m))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*Message) TypeID() uint32 {
|
||||
return MessageTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*Message) TypeName() string {
|
||||
return "message"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (m *Message) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "message",
|
||||
ID: MessageTypeID,
|
||||
}
|
||||
if m == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Err",
|
||||
SchemaName: "err",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (m *Message) Encode(b *bin.Buffer) error {
|
||||
if m == nil {
|
||||
return fmt.Errorf("can't encode message#ec200d96 as nil")
|
||||
}
|
||||
b.PutID(MessageTypeID)
|
||||
return m.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (m *Message) EncodeBare(b *bin.Buffer) error {
|
||||
if m == nil {
|
||||
return fmt.Errorf("can't encode message#ec200d96 as nil")
|
||||
}
|
||||
if err := m.Err.Encode(b); err != nil {
|
||||
return fmt.Errorf("unable to encode message#ec200d96: field err: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (m *Message) Decode(b *bin.Buffer) error {
|
||||
if m == nil {
|
||||
return fmt.Errorf("can't decode message#ec200d96 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(MessageTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode message#ec200d96: %w", err)
|
||||
}
|
||||
return m.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (m *Message) DecodeBare(b *bin.Buffer) error {
|
||||
if m == nil {
|
||||
return fmt.Errorf("can't decode message#ec200d96 to nil")
|
||||
}
|
||||
{
|
||||
if err := m.Err.Decode(b); err != nil {
|
||||
return fmt.Errorf("unable to decode message#ec200d96: field err: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetErr returns value of Err field.
|
||||
func (m *Message) GetErr() (value Error) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
return m.Err
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// Ok represents TL type `ok#d4edbe69`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/ok for reference.
|
||||
type Ok struct {
|
||||
}
|
||||
|
||||
// OkTypeID is TL type id of Ok.
|
||||
const OkTypeID = 0xd4edbe69
|
||||
|
||||
// Ensuring interfaces in compile-time for Ok.
|
||||
var (
|
||||
_ bin.Encoder = &Ok{}
|
||||
_ bin.Decoder = &Ok{}
|
||||
_ bin.BareEncoder = &Ok{}
|
||||
_ bin.BareDecoder = &Ok{}
|
||||
)
|
||||
|
||||
func (o *Ok) Zero() bool {
|
||||
if o == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (o *Ok) String() string {
|
||||
if o == nil {
|
||||
return "Ok(nil)"
|
||||
}
|
||||
type Alias Ok
|
||||
return fmt.Sprintf("Ok%+v", Alias(*o))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*Ok) TypeID() uint32 {
|
||||
return OkTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*Ok) TypeName() string {
|
||||
return "ok"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (o *Ok) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "ok",
|
||||
ID: OkTypeID,
|
||||
}
|
||||
if o == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (o *Ok) Encode(b *bin.Buffer) error {
|
||||
if o == nil {
|
||||
return fmt.Errorf("can't encode ok#d4edbe69 as nil")
|
||||
}
|
||||
b.PutID(OkTypeID)
|
||||
return o.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (o *Ok) EncodeBare(b *bin.Buffer) error {
|
||||
if o == nil {
|
||||
return fmt.Errorf("can't encode ok#d4edbe69 as nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (o *Ok) Decode(b *bin.Buffer) error {
|
||||
if o == nil {
|
||||
return fmt.Errorf("can't decode ok#d4edbe69 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(OkTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode ok#d4edbe69: %w", err)
|
||||
}
|
||||
return o.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (o *Ok) DecodeBare(b *bin.Buffer) error {
|
||||
if o == nil {
|
||||
return fmt.Errorf("can't decode ok#d4edbe69 to nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// PingRequest represents TL type `ping#ce73048f`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/ping for reference.
|
||||
type PingRequest struct {
|
||||
// ID field of PingRequest.
|
||||
ID int32
|
||||
}
|
||||
|
||||
// PingRequestTypeID is TL type id of PingRequest.
|
||||
const PingRequestTypeID = 0xce73048f
|
||||
|
||||
// Ensuring interfaces in compile-time for PingRequest.
|
||||
var (
|
||||
_ bin.Encoder = &PingRequest{}
|
||||
_ bin.Decoder = &PingRequest{}
|
||||
_ bin.BareEncoder = &PingRequest{}
|
||||
_ bin.BareDecoder = &PingRequest{}
|
||||
)
|
||||
|
||||
func (p *PingRequest) Zero() bool {
|
||||
if p == nil {
|
||||
return true
|
||||
}
|
||||
if !(p.ID == 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (p *PingRequest) String() string {
|
||||
if p == nil {
|
||||
return "PingRequest(nil)"
|
||||
}
|
||||
type Alias PingRequest
|
||||
return fmt.Sprintf("PingRequest%+v", Alias(*p))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*PingRequest) TypeID() uint32 {
|
||||
return PingRequestTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*PingRequest) TypeName() string {
|
||||
return "ping"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (p *PingRequest) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "ping",
|
||||
ID: PingRequestTypeID,
|
||||
}
|
||||
if p == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "ID",
|
||||
SchemaName: "id",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (p *PingRequest) Encode(b *bin.Buffer) error {
|
||||
if p == nil {
|
||||
return fmt.Errorf("can't encode ping#ce73048f as nil")
|
||||
}
|
||||
b.PutID(PingRequestTypeID)
|
||||
return p.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (p *PingRequest) EncodeBare(b *bin.Buffer) error {
|
||||
if p == nil {
|
||||
return fmt.Errorf("can't encode ping#ce73048f as nil")
|
||||
}
|
||||
b.PutInt32(p.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (p *PingRequest) Decode(b *bin.Buffer) error {
|
||||
if p == nil {
|
||||
return fmt.Errorf("can't decode ping#ce73048f to nil")
|
||||
}
|
||||
if err := b.ConsumeID(PingRequestTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode ping#ce73048f: %w", err)
|
||||
}
|
||||
return p.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (p *PingRequest) DecodeBare(b *bin.Buffer) error {
|
||||
if p == nil {
|
||||
return fmt.Errorf("can't decode ping#ce73048f to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode ping#ce73048f: field id: %w", err)
|
||||
}
|
||||
p.ID = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetID returns value of ID field.
|
||||
func (p *PingRequest) GetID() (value int32) {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
return p.ID
|
||||
}
|
||||
|
||||
// Ping invokes method ping#ce73048f returning error if any.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/ping for reference.
|
||||
func (c *Client) Ping(ctx context.Context, id int32) error {
|
||||
var ok Ok
|
||||
|
||||
request := &PingRequest{
|
||||
ID: id,
|
||||
}
|
||||
if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TypesMap returns mapping from type ids to TL type names.
|
||||
func TypesMap() map[uint32]string {
|
||||
return map[uint32]string{
|
||||
Int32TypeID: "int32#5cb934fa",
|
||||
StringTypeID: "string#b5286e24",
|
||||
FalseTypeID: "false#bc799737",
|
||||
TrueTypeID: "true#997275b5",
|
||||
BytesTypeID: "bytes#e937bb82",
|
||||
ErrorTypeID: "error#14feebbc",
|
||||
OkTypeID: "ok#d4edbe69",
|
||||
MessageTypeID: "message#ec200d96",
|
||||
SMSTypeID: "sms#ed8bebfe",
|
||||
ResponseIDTypeID: "responseID#85d7fd8b",
|
||||
ResponseTextTypeID: "responseText#cb0244f2",
|
||||
BigMessageTypeID: "bigMessage#7490dcc5",
|
||||
NoMessageTypeID: "noMessage#ee6324c4",
|
||||
TargetsMessageTypeID: "targetsMessage#cc6136f1",
|
||||
UpdateTypeID: "update#b03e2ef8",
|
||||
GetUpdatesRespTypeID: "getUpdatesResp#300bb5e1",
|
||||
FieldsMessageTypeID: "fieldsMessage#947225b5",
|
||||
BytesMessageTypeID: "bytesMessage#f990a67d",
|
||||
TextEntityTypeMentionTypeID: "textEntityTypeMention#37b3df65",
|
||||
TextEntityTypeHashtagTypeID: "textEntityTypeHashtag#c2f7a2dd",
|
||||
TextEntityTypeCashtagTypeID: "textEntityTypeCashtag#48e4374b",
|
||||
TextEntityTypeBotCommandTypeID: "textEntityTypeBotCommand#bb652bb3",
|
||||
TextEntityTypeURLTypeID: "textEntityTypeUrl#b1c0d47c",
|
||||
TextEntityTypeEmailAddressTypeID: "textEntityTypeEmailAddress#54f81821",
|
||||
TextEntityTypePhoneNumberTypeID: "textEntityTypePhoneNumber#bad9aa2a",
|
||||
TextEntityTypeBankCardNumberTypeID: "textEntityTypeBankCardNumber#6513910",
|
||||
TextEntityTypeBoldTypeID: "textEntityTypeBold#bcc0e1b0",
|
||||
TextEntityTypeItalicTypeID: "textEntityTypeItalic#f8f3965d",
|
||||
TextEntityTypeUnderlineTypeID: "textEntityTypeUnderline#2f39cf92",
|
||||
TextEntityTypeStrikethroughTypeID: "textEntityTypeStrikethrough#394fc4fa",
|
||||
TextEntityTypeCodeTypeID: "textEntityTypeCode#c5e9c94a",
|
||||
TextEntityTypePreTypeID: "textEntityTypePre#62491c8e",
|
||||
TextEntityTypePreCodeTypeID: "textEntityTypePreCode#c7a77aab",
|
||||
TextEntityTypeTextURLTypeID: "textEntityTypeTextUrl#1a912463",
|
||||
TextEntityTypeMentionNameTypeID: "textEntityTypeMentionName#d0d2685d",
|
||||
TextEntityTypeID: "textEntity#8bab99a8",
|
||||
TextEntitiesTypeID: "textEntities#cf89c258",
|
||||
TestIntTypeID: "testInt#ddbd2c09",
|
||||
TestStringTypeID: "testString#fe56688c",
|
||||
TestBytesTypeID: "testBytes#a422c4de",
|
||||
TestVectorIntTypeID: "testVectorInt#df9eb113",
|
||||
TestVectorIntObjectTypeID: "testVectorIntObject#f152999b",
|
||||
TestVectorStringTypeID: "testVectorString#5d6f85bc",
|
||||
TestVectorStringObjectTypeID: "testVectorStringObject#e5ecc0d",
|
||||
TestVectorBytesTypeID: "testVectorBytes#a590fb25",
|
||||
TestVectorVectorTypeID: "testVectorVector#69e8846c",
|
||||
ClientDHInnerDataTypeID: "client_DH_inner_data#6643b654",
|
||||
DCOptionTypeID: "dcOption#18b7a10d",
|
||||
ConfigTypeID: "config#330b4067",
|
||||
InvokeWithLayerTypeID: "invokeWithLayer#da9b0d0d",
|
||||
AuthTypeID: "auth#f8bb4a38",
|
||||
AuthPasswordTypeID: "authPassword#29bacabb",
|
||||
UserAuthTypeID: "user.auth#f4815592",
|
||||
UserAuthPasswordTypeID: "user.authPassword#5981e317",
|
||||
ThemeTypeID: "theme#28f1114",
|
||||
AccountThemesNotModifiedTypeID: "account.themesNotModified#f41eb622",
|
||||
AccountThemesTypeID: "account.themes#7f676421",
|
||||
PingRequestTypeID: "ping#ce73048f",
|
||||
SendRequestTypeID: "send#f74488a",
|
||||
SendMultipleSMSRequestTypeID: "sendMultipleSMS#df18e5ca",
|
||||
DoAuthRequestTypeID: "doAuth#fd2f6687",
|
||||
EchoVectorRequestTypeID: "echoVector#d4785939",
|
||||
}
|
||||
}
|
||||
|
||||
// NamesMap returns mapping from type names to TL type ids.
|
||||
func NamesMap() map[string]uint32 {
|
||||
return map[string]uint32{
|
||||
"int32": Int32TypeID,
|
||||
"string": StringTypeID,
|
||||
"false": FalseTypeID,
|
||||
"true": TrueTypeID,
|
||||
"bytes": BytesTypeID,
|
||||
"error": ErrorTypeID,
|
||||
"ok": OkTypeID,
|
||||
"message": MessageTypeID,
|
||||
"sms": SMSTypeID,
|
||||
"responseID": ResponseIDTypeID,
|
||||
"responseText": ResponseTextTypeID,
|
||||
"bigMessage": BigMessageTypeID,
|
||||
"noMessage": NoMessageTypeID,
|
||||
"targetsMessage": TargetsMessageTypeID,
|
||||
"update": UpdateTypeID,
|
||||
"getUpdatesResp": GetUpdatesRespTypeID,
|
||||
"fieldsMessage": FieldsMessageTypeID,
|
||||
"bytesMessage": BytesMessageTypeID,
|
||||
"textEntityTypeMention": TextEntityTypeMentionTypeID,
|
||||
"textEntityTypeHashtag": TextEntityTypeHashtagTypeID,
|
||||
"textEntityTypeCashtag": TextEntityTypeCashtagTypeID,
|
||||
"textEntityTypeBotCommand": TextEntityTypeBotCommandTypeID,
|
||||
"textEntityTypeUrl": TextEntityTypeURLTypeID,
|
||||
"textEntityTypeEmailAddress": TextEntityTypeEmailAddressTypeID,
|
||||
"textEntityTypePhoneNumber": TextEntityTypePhoneNumberTypeID,
|
||||
"textEntityTypeBankCardNumber": TextEntityTypeBankCardNumberTypeID,
|
||||
"textEntityTypeBold": TextEntityTypeBoldTypeID,
|
||||
"textEntityTypeItalic": TextEntityTypeItalicTypeID,
|
||||
"textEntityTypeUnderline": TextEntityTypeUnderlineTypeID,
|
||||
"textEntityTypeStrikethrough": TextEntityTypeStrikethroughTypeID,
|
||||
"textEntityTypeCode": TextEntityTypeCodeTypeID,
|
||||
"textEntityTypePre": TextEntityTypePreTypeID,
|
||||
"textEntityTypePreCode": TextEntityTypePreCodeTypeID,
|
||||
"textEntityTypeTextUrl": TextEntityTypeTextURLTypeID,
|
||||
"textEntityTypeMentionName": TextEntityTypeMentionNameTypeID,
|
||||
"textEntity": TextEntityTypeID,
|
||||
"textEntities": TextEntitiesTypeID,
|
||||
"testInt": TestIntTypeID,
|
||||
"testString": TestStringTypeID,
|
||||
"testBytes": TestBytesTypeID,
|
||||
"testVectorInt": TestVectorIntTypeID,
|
||||
"testVectorIntObject": TestVectorIntObjectTypeID,
|
||||
"testVectorString": TestVectorStringTypeID,
|
||||
"testVectorStringObject": TestVectorStringObjectTypeID,
|
||||
"testVectorBytes": TestVectorBytesTypeID,
|
||||
"testVectorVector": TestVectorVectorTypeID,
|
||||
"client_DH_inner_data": ClientDHInnerDataTypeID,
|
||||
"dcOption": DCOptionTypeID,
|
||||
"config": ConfigTypeID,
|
||||
"invokeWithLayer": InvokeWithLayerTypeID,
|
||||
"auth": AuthTypeID,
|
||||
"authPassword": AuthPasswordTypeID,
|
||||
"user.auth": UserAuthTypeID,
|
||||
"user.authPassword": UserAuthPasswordTypeID,
|
||||
"theme": ThemeTypeID,
|
||||
"account.themesNotModified": AccountThemesNotModifiedTypeID,
|
||||
"account.themes": AccountThemesTypeID,
|
||||
"ping": PingRequestTypeID,
|
||||
"send": SendRequestTypeID,
|
||||
"sendMultipleSMS": SendMultipleSMSRequestTypeID,
|
||||
"doAuth": DoAuthRequestTypeID,
|
||||
"echoVector": EchoVectorRequestTypeID,
|
||||
}
|
||||
}
|
||||
|
||||
// TypesConstructorMap maps type ids to constructors.
|
||||
func TypesConstructorMap() map[uint32]func() bin.Object {
|
||||
return map[uint32]func() bin.Object{
|
||||
Int32TypeID: func() bin.Object { return &Int32{} },
|
||||
StringTypeID: func() bin.Object { return &String{} },
|
||||
FalseTypeID: func() bin.Object { return &False{} },
|
||||
TrueTypeID: func() bin.Object { return &True{} },
|
||||
BytesTypeID: func() bin.Object { return &Bytes{} },
|
||||
ErrorTypeID: func() bin.Object { return &Error{} },
|
||||
OkTypeID: func() bin.Object { return &Ok{} },
|
||||
MessageTypeID: func() bin.Object { return &Message{} },
|
||||
SMSTypeID: func() bin.Object { return &SMS{} },
|
||||
ResponseIDTypeID: func() bin.Object { return &ResponseID{} },
|
||||
ResponseTextTypeID: func() bin.Object { return &ResponseText{} },
|
||||
BigMessageTypeID: func() bin.Object { return &BigMessage{} },
|
||||
NoMessageTypeID: func() bin.Object { return &NoMessage{} },
|
||||
TargetsMessageTypeID: func() bin.Object { return &TargetsMessage{} },
|
||||
UpdateTypeID: func() bin.Object { return &Update{} },
|
||||
GetUpdatesRespTypeID: func() bin.Object { return &GetUpdatesResp{} },
|
||||
FieldsMessageTypeID: func() bin.Object { return &FieldsMessage{} },
|
||||
BytesMessageTypeID: func() bin.Object { return &BytesMessage{} },
|
||||
TextEntityTypeMentionTypeID: func() bin.Object { return &TextEntityTypeMention{} },
|
||||
TextEntityTypeHashtagTypeID: func() bin.Object { return &TextEntityTypeHashtag{} },
|
||||
TextEntityTypeCashtagTypeID: func() bin.Object { return &TextEntityTypeCashtag{} },
|
||||
TextEntityTypeBotCommandTypeID: func() bin.Object { return &TextEntityTypeBotCommand{} },
|
||||
TextEntityTypeURLTypeID: func() bin.Object { return &TextEntityTypeURL{} },
|
||||
TextEntityTypeEmailAddressTypeID: func() bin.Object { return &TextEntityTypeEmailAddress{} },
|
||||
TextEntityTypePhoneNumberTypeID: func() bin.Object { return &TextEntityTypePhoneNumber{} },
|
||||
TextEntityTypeBankCardNumberTypeID: func() bin.Object { return &TextEntityTypeBankCardNumber{} },
|
||||
TextEntityTypeBoldTypeID: func() bin.Object { return &TextEntityTypeBold{} },
|
||||
TextEntityTypeItalicTypeID: func() bin.Object { return &TextEntityTypeItalic{} },
|
||||
TextEntityTypeUnderlineTypeID: func() bin.Object { return &TextEntityTypeUnderline{} },
|
||||
TextEntityTypeStrikethroughTypeID: func() bin.Object { return &TextEntityTypeStrikethrough{} },
|
||||
TextEntityTypeCodeTypeID: func() bin.Object { return &TextEntityTypeCode{} },
|
||||
TextEntityTypePreTypeID: func() bin.Object { return &TextEntityTypePre{} },
|
||||
TextEntityTypePreCodeTypeID: func() bin.Object { return &TextEntityTypePreCode{} },
|
||||
TextEntityTypeTextURLTypeID: func() bin.Object { return &TextEntityTypeTextURL{} },
|
||||
TextEntityTypeMentionNameTypeID: func() bin.Object { return &TextEntityTypeMentionName{} },
|
||||
TextEntityTypeID: func() bin.Object { return &TextEntity{} },
|
||||
TextEntitiesTypeID: func() bin.Object { return &TextEntities{} },
|
||||
TestIntTypeID: func() bin.Object { return &TestInt{} },
|
||||
TestStringTypeID: func() bin.Object { return &TestString{} },
|
||||
TestBytesTypeID: func() bin.Object { return &TestBytes{} },
|
||||
TestVectorIntTypeID: func() bin.Object { return &TestVectorInt{} },
|
||||
TestVectorIntObjectTypeID: func() bin.Object { return &TestVectorIntObject{} },
|
||||
TestVectorStringTypeID: func() bin.Object { return &TestVectorString{} },
|
||||
TestVectorStringObjectTypeID: func() bin.Object { return &TestVectorStringObject{} },
|
||||
TestVectorBytesTypeID: func() bin.Object { return &TestVectorBytes{} },
|
||||
TestVectorVectorTypeID: func() bin.Object { return &TestVectorVector{} },
|
||||
ClientDHInnerDataTypeID: func() bin.Object { return &ClientDHInnerData{} },
|
||||
DCOptionTypeID: func() bin.Object { return &DCOption{} },
|
||||
ConfigTypeID: func() bin.Object { return &Config{} },
|
||||
InvokeWithLayerTypeID: func() bin.Object { return &InvokeWithLayer{} },
|
||||
AuthTypeID: func() bin.Object { return &Auth{} },
|
||||
AuthPasswordTypeID: func() bin.Object { return &AuthPassword{} },
|
||||
UserAuthTypeID: func() bin.Object { return &UserAuth{} },
|
||||
UserAuthPasswordTypeID: func() bin.Object { return &UserAuthPassword{} },
|
||||
ThemeTypeID: func() bin.Object { return &Theme{} },
|
||||
AccountThemesNotModifiedTypeID: func() bin.Object { return &AccountThemesNotModified{} },
|
||||
AccountThemesTypeID: func() bin.Object { return &AccountThemes{} },
|
||||
PingRequestTypeID: func() bin.Object { return &PingRequest{} },
|
||||
SendRequestTypeID: func() bin.Object { return &SendRequest{} },
|
||||
SendMultipleSMSRequestTypeID: func() bin.Object { return &SendMultipleSMSRequest{} },
|
||||
DoAuthRequestTypeID: func() bin.Object { return &DoAuthRequest{} },
|
||||
EchoVectorRequestTypeID: func() bin.Object { return &EchoVectorRequest{} },
|
||||
}
|
||||
}
|
||||
|
||||
// ClassConstructorsMap maps class schema name to constructors type ids.
|
||||
func ClassConstructorsMap() map[string][]uint32 {
|
||||
return map[string][]uint32{
|
||||
AbstractMessageClassName: {
|
||||
BigMessageTypeID,
|
||||
NoMessageTypeID,
|
||||
TargetsMessageTypeID,
|
||||
FieldsMessageTypeID,
|
||||
BytesMessageTypeID,
|
||||
},
|
||||
AccountThemesClassName: {
|
||||
AccountThemesNotModifiedTypeID,
|
||||
AccountThemesTypeID,
|
||||
},
|
||||
AuthClassName: {
|
||||
AuthTypeID,
|
||||
AuthPasswordTypeID,
|
||||
},
|
||||
BoolClassName: {
|
||||
FalseTypeID,
|
||||
TrueTypeID,
|
||||
},
|
||||
ResponseClassName: {
|
||||
ResponseIDTypeID,
|
||||
ResponseTextTypeID,
|
||||
},
|
||||
TextEntityTypeClassName: {
|
||||
TextEntityTypeMentionTypeID,
|
||||
TextEntityTypeHashtagTypeID,
|
||||
TextEntityTypeCashtagTypeID,
|
||||
TextEntityTypeBotCommandTypeID,
|
||||
TextEntityTypeURLTypeID,
|
||||
TextEntityTypeEmailAddressTypeID,
|
||||
TextEntityTypePhoneNumberTypeID,
|
||||
TextEntityTypeBankCardNumberTypeID,
|
||||
TextEntityTypeBoldTypeID,
|
||||
TextEntityTypeItalicTypeID,
|
||||
TextEntityTypeUnderlineTypeID,
|
||||
TextEntityTypeStrikethroughTypeID,
|
||||
TextEntityTypeCodeTypeID,
|
||||
TextEntityTypePreTypeID,
|
||||
TextEntityTypePreCodeTypeID,
|
||||
TextEntityTypeTextURLTypeID,
|
||||
TextEntityTypeMentionNameTypeID,
|
||||
},
|
||||
UserAuthClassName: {
|
||||
UserAuthTypeID,
|
||||
UserAuthPasswordTypeID,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,375 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// ResponseID represents TL type `responseID#85d7fd8b`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/responseID for reference.
|
||||
type ResponseID struct {
|
||||
// ID field of ResponseID.
|
||||
ID int32
|
||||
}
|
||||
|
||||
// ResponseIDTypeID is TL type id of ResponseID.
|
||||
const ResponseIDTypeID = 0x85d7fd8b
|
||||
|
||||
// construct implements constructor of ResponseClass.
|
||||
func (r ResponseID) construct() ResponseClass { return &r }
|
||||
|
||||
// Ensuring interfaces in compile-time for ResponseID.
|
||||
var (
|
||||
_ bin.Encoder = &ResponseID{}
|
||||
_ bin.Decoder = &ResponseID{}
|
||||
_ bin.BareEncoder = &ResponseID{}
|
||||
_ bin.BareDecoder = &ResponseID{}
|
||||
|
||||
_ ResponseClass = &ResponseID{}
|
||||
)
|
||||
|
||||
func (r *ResponseID) Zero() bool {
|
||||
if r == nil {
|
||||
return true
|
||||
}
|
||||
if !(r.ID == 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (r *ResponseID) String() string {
|
||||
if r == nil {
|
||||
return "ResponseID(nil)"
|
||||
}
|
||||
type Alias ResponseID
|
||||
return fmt.Sprintf("ResponseID%+v", Alias(*r))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*ResponseID) TypeID() uint32 {
|
||||
return ResponseIDTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*ResponseID) TypeName() string {
|
||||
return "responseID"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (r *ResponseID) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "responseID",
|
||||
ID: ResponseIDTypeID,
|
||||
}
|
||||
if r == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "ID",
|
||||
SchemaName: "id",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (r *ResponseID) Encode(b *bin.Buffer) error {
|
||||
if r == nil {
|
||||
return fmt.Errorf("can't encode responseID#85d7fd8b as nil")
|
||||
}
|
||||
b.PutID(ResponseIDTypeID)
|
||||
return r.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (r *ResponseID) EncodeBare(b *bin.Buffer) error {
|
||||
if r == nil {
|
||||
return fmt.Errorf("can't encode responseID#85d7fd8b as nil")
|
||||
}
|
||||
b.PutInt32(r.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (r *ResponseID) Decode(b *bin.Buffer) error {
|
||||
if r == nil {
|
||||
return fmt.Errorf("can't decode responseID#85d7fd8b to nil")
|
||||
}
|
||||
if err := b.ConsumeID(ResponseIDTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode responseID#85d7fd8b: %w", err)
|
||||
}
|
||||
return r.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (r *ResponseID) DecodeBare(b *bin.Buffer) error {
|
||||
if r == nil {
|
||||
return fmt.Errorf("can't decode responseID#85d7fd8b to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode responseID#85d7fd8b: field id: %w", err)
|
||||
}
|
||||
r.ID = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetID returns value of ID field.
|
||||
func (r *ResponseID) GetID() (value int32) {
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
return r.ID
|
||||
}
|
||||
|
||||
// ResponseText represents TL type `responseText#cb0244f2`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/responseText for reference.
|
||||
type ResponseText struct {
|
||||
// Text field of ResponseText.
|
||||
Text string
|
||||
}
|
||||
|
||||
// ResponseTextTypeID is TL type id of ResponseText.
|
||||
const ResponseTextTypeID = 0xcb0244f2
|
||||
|
||||
// construct implements constructor of ResponseClass.
|
||||
func (r ResponseText) construct() ResponseClass { return &r }
|
||||
|
||||
// Ensuring interfaces in compile-time for ResponseText.
|
||||
var (
|
||||
_ bin.Encoder = &ResponseText{}
|
||||
_ bin.Decoder = &ResponseText{}
|
||||
_ bin.BareEncoder = &ResponseText{}
|
||||
_ bin.BareDecoder = &ResponseText{}
|
||||
|
||||
_ ResponseClass = &ResponseText{}
|
||||
)
|
||||
|
||||
func (r *ResponseText) Zero() bool {
|
||||
if r == nil {
|
||||
return true
|
||||
}
|
||||
if !(r.Text == "") {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (r *ResponseText) String() string {
|
||||
if r == nil {
|
||||
return "ResponseText(nil)"
|
||||
}
|
||||
type Alias ResponseText
|
||||
return fmt.Sprintf("ResponseText%+v", Alias(*r))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*ResponseText) TypeID() uint32 {
|
||||
return ResponseTextTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*ResponseText) TypeName() string {
|
||||
return "responseText"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (r *ResponseText) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "responseText",
|
||||
ID: ResponseTextTypeID,
|
||||
}
|
||||
if r == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Text",
|
||||
SchemaName: "text",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (r *ResponseText) Encode(b *bin.Buffer) error {
|
||||
if r == nil {
|
||||
return fmt.Errorf("can't encode responseText#cb0244f2 as nil")
|
||||
}
|
||||
b.PutID(ResponseTextTypeID)
|
||||
return r.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (r *ResponseText) EncodeBare(b *bin.Buffer) error {
|
||||
if r == nil {
|
||||
return fmt.Errorf("can't encode responseText#cb0244f2 as nil")
|
||||
}
|
||||
b.PutString(r.Text)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (r *ResponseText) Decode(b *bin.Buffer) error {
|
||||
if r == nil {
|
||||
return fmt.Errorf("can't decode responseText#cb0244f2 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(ResponseTextTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode responseText#cb0244f2: %w", err)
|
||||
}
|
||||
return r.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (r *ResponseText) DecodeBare(b *bin.Buffer) error {
|
||||
if r == nil {
|
||||
return fmt.Errorf("can't decode responseText#cb0244f2 to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode responseText#cb0244f2: field text: %w", err)
|
||||
}
|
||||
r.Text = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetText returns value of Text field.
|
||||
func (r *ResponseText) GetText() (value string) {
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
return r.Text
|
||||
}
|
||||
|
||||
// ResponseClassName is schema name of ResponseClass.
|
||||
const ResponseClassName = "Response"
|
||||
|
||||
// ResponseClass represents Response generic type.
|
||||
//
|
||||
// See https://localhost:80/doc/type/Response for reference.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// g, err := td.DecodeResponse(buf)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// switch v := g.(type) {
|
||||
// case *td.ResponseID: // responseID#85d7fd8b
|
||||
// case *td.ResponseText: // responseText#cb0244f2
|
||||
// default: panic(v)
|
||||
// }
|
||||
type ResponseClass interface {
|
||||
bin.Encoder
|
||||
bin.Decoder
|
||||
bin.BareEncoder
|
||||
bin.BareDecoder
|
||||
construct() ResponseClass
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
TypeID() uint32
|
||||
// TypeName returns name of type in TL schema.
|
||||
TypeName() string
|
||||
// String implements fmt.Stringer.
|
||||
String() string
|
||||
// Zero returns true if current object has a zero value.
|
||||
Zero() bool
|
||||
}
|
||||
|
||||
// DecodeResponse implements binary de-serialization for ResponseClass.
|
||||
func DecodeResponse(buf *bin.Buffer) (ResponseClass, error) {
|
||||
id, err := buf.PeekID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch id {
|
||||
case ResponseIDTypeID:
|
||||
// Decoding responseID#85d7fd8b.
|
||||
v := ResponseID{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode ResponseClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
case ResponseTextTypeID:
|
||||
// Decoding responseText#cb0244f2.
|
||||
v := ResponseText{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode ResponseClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to decode ResponseClass: %w", bin.NewUnexpectedID(id))
|
||||
}
|
||||
}
|
||||
|
||||
// Response boxes the ResponseClass providing a helper.
|
||||
type ResponseBox struct {
|
||||
Response ResponseClass
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder for ResponseBox.
|
||||
func (b *ResponseBox) Decode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("unable to decode ResponseBox to nil")
|
||||
}
|
||||
v, err := DecodeResponse(buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode boxed value: %w", err)
|
||||
}
|
||||
b.Response = v
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode implements bin.Encode for ResponseBox.
|
||||
func (b *ResponseBox) Encode(buf *bin.Buffer) error {
|
||||
if b == nil || b.Response == nil {
|
||||
return fmt.Errorf("unable to encode ResponseClass as nil")
|
||||
}
|
||||
return b.Response.Encode(buf)
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// SendRequest represents TL type `send#f74488a`.
|
||||
//
|
||||
// See https://localhost:80/doc/method/send for reference.
|
||||
type SendRequest struct {
|
||||
// Msg field of SendRequest.
|
||||
Msg SMS
|
||||
}
|
||||
|
||||
// SendRequestTypeID is TL type id of SendRequest.
|
||||
const SendRequestTypeID = 0xf74488a
|
||||
|
||||
// Ensuring interfaces in compile-time for SendRequest.
|
||||
var (
|
||||
_ bin.Encoder = &SendRequest{}
|
||||
_ bin.Decoder = &SendRequest{}
|
||||
_ bin.BareEncoder = &SendRequest{}
|
||||
_ bin.BareDecoder = &SendRequest{}
|
||||
)
|
||||
|
||||
func (s *SendRequest) Zero() bool {
|
||||
if s == nil {
|
||||
return true
|
||||
}
|
||||
if !(s.Msg.Zero()) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (s *SendRequest) String() string {
|
||||
if s == nil {
|
||||
return "SendRequest(nil)"
|
||||
}
|
||||
type Alias SendRequest
|
||||
return fmt.Sprintf("SendRequest%+v", Alias(*s))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*SendRequest) TypeID() uint32 {
|
||||
return SendRequestTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*SendRequest) TypeName() string {
|
||||
return "send"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (s *SendRequest) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "send",
|
||||
ID: SendRequestTypeID,
|
||||
}
|
||||
if s == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Msg",
|
||||
SchemaName: "msg",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (s *SendRequest) Encode(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't encode send#f74488a as nil")
|
||||
}
|
||||
b.PutID(SendRequestTypeID)
|
||||
return s.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (s *SendRequest) EncodeBare(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't encode send#f74488a as nil")
|
||||
}
|
||||
if err := s.Msg.Encode(b); err != nil {
|
||||
return fmt.Errorf("unable to encode send#f74488a: field msg: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (s *SendRequest) Decode(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't decode send#f74488a to nil")
|
||||
}
|
||||
if err := b.ConsumeID(SendRequestTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode send#f74488a: %w", err)
|
||||
}
|
||||
return s.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (s *SendRequest) DecodeBare(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't decode send#f74488a to nil")
|
||||
}
|
||||
{
|
||||
if err := s.Msg.Decode(b); err != nil {
|
||||
return fmt.Errorf("unable to decode send#f74488a: field msg: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetMsg returns value of Msg field.
|
||||
func (s *SendRequest) GetMsg() (value SMS) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
return s.Msg
|
||||
}
|
||||
|
||||
// Send invokes method send#f74488a returning error if any.
|
||||
//
|
||||
// See https://localhost:80/doc/method/send for reference.
|
||||
func (c *Client) Send(ctx context.Context, msg SMS) (*SMS, error) {
|
||||
var result SMS
|
||||
|
||||
request := &SendRequest{
|
||||
Msg: msg,
|
||||
}
|
||||
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// SendMultipleSMSRequest represents TL type `sendMultipleSMS#df18e5ca`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/sendMultipleSMS for reference.
|
||||
type SendMultipleSMSRequest struct {
|
||||
// Messages field of SendMultipleSMSRequest.
|
||||
Messages []SMS
|
||||
}
|
||||
|
||||
// SendMultipleSMSRequestTypeID is TL type id of SendMultipleSMSRequest.
|
||||
const SendMultipleSMSRequestTypeID = 0xdf18e5ca
|
||||
|
||||
// Ensuring interfaces in compile-time for SendMultipleSMSRequest.
|
||||
var (
|
||||
_ bin.Encoder = &SendMultipleSMSRequest{}
|
||||
_ bin.Decoder = &SendMultipleSMSRequest{}
|
||||
_ bin.BareEncoder = &SendMultipleSMSRequest{}
|
||||
_ bin.BareDecoder = &SendMultipleSMSRequest{}
|
||||
)
|
||||
|
||||
func (s *SendMultipleSMSRequest) Zero() bool {
|
||||
if s == nil {
|
||||
return true
|
||||
}
|
||||
if !(s.Messages == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (s *SendMultipleSMSRequest) String() string {
|
||||
if s == nil {
|
||||
return "SendMultipleSMSRequest(nil)"
|
||||
}
|
||||
type Alias SendMultipleSMSRequest
|
||||
return fmt.Sprintf("SendMultipleSMSRequest%+v", Alias(*s))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*SendMultipleSMSRequest) TypeID() uint32 {
|
||||
return SendMultipleSMSRequestTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*SendMultipleSMSRequest) TypeName() string {
|
||||
return "sendMultipleSMS"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (s *SendMultipleSMSRequest) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "sendMultipleSMS",
|
||||
ID: SendMultipleSMSRequestTypeID,
|
||||
}
|
||||
if s == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Messages",
|
||||
SchemaName: "messages",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (s *SendMultipleSMSRequest) Encode(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't encode sendMultipleSMS#df18e5ca as nil")
|
||||
}
|
||||
b.PutID(SendMultipleSMSRequestTypeID)
|
||||
return s.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (s *SendMultipleSMSRequest) EncodeBare(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't encode sendMultipleSMS#df18e5ca as nil")
|
||||
}
|
||||
b.PutInt(len(s.Messages))
|
||||
for idx, v := range s.Messages {
|
||||
if err := v.Encode(b); err != nil {
|
||||
return fmt.Errorf("unable to encode sendMultipleSMS#df18e5ca: field messages element with index %d: %w", idx, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (s *SendMultipleSMSRequest) Decode(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't decode sendMultipleSMS#df18e5ca to nil")
|
||||
}
|
||||
if err := b.ConsumeID(SendMultipleSMSRequestTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode sendMultipleSMS#df18e5ca: %w", err)
|
||||
}
|
||||
return s.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (s *SendMultipleSMSRequest) DecodeBare(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't decode sendMultipleSMS#df18e5ca to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode sendMultipleSMS#df18e5ca: field messages: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
s.Messages = make([]SMS, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
var value SMS
|
||||
if err := value.Decode(b); err != nil {
|
||||
return fmt.Errorf("unable to decode sendMultipleSMS#df18e5ca: field messages: %w", err)
|
||||
}
|
||||
s.Messages = append(s.Messages, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetMessages returns value of Messages field.
|
||||
func (s *SendMultipleSMSRequest) GetMessages() (value []SMS) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
return s.Messages
|
||||
}
|
||||
|
||||
// SendMultipleSMS invokes method sendMultipleSMS#df18e5ca returning error if any.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/sendMultipleSMS for reference.
|
||||
func (c *Client) SendMultipleSMS(ctx context.Context, messages []SMS) error {
|
||||
var ok Ok
|
||||
|
||||
request := &SendMultipleSMSRequest{
|
||||
Messages: messages,
|
||||
}
|
||||
if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
type ServerDispatcher struct {
|
||||
fallback func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error)
|
||||
handlers map[uint32]func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error)
|
||||
}
|
||||
|
||||
func NewServerDispatcher(fallback func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error)) *ServerDispatcher {
|
||||
return &ServerDispatcher{
|
||||
fallback: fallback,
|
||||
handlers: map[uint32]func(context.Context, *bin.Buffer) (bin.Encoder, error){},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerDispatcher) Handle(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
|
||||
id, err := b.PeekID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f, ok := s.handlers[id]
|
||||
if !ok {
|
||||
return s.fallback(ctx, b)
|
||||
}
|
||||
|
||||
return f(ctx, b)
|
||||
}
|
||||
|
||||
func (s *ServerDispatcher) OnPing(f func(ctx context.Context, id int32) error) {
|
||||
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
|
||||
var request PingRequest
|
||||
if err := request.Decode(b); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := f(ctx, request.ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Ok{}, nil
|
||||
}
|
||||
|
||||
s.handlers[PingRequestTypeID] = handler
|
||||
}
|
||||
|
||||
func (s *ServerDispatcher) OnSend(f func(ctx context.Context, msg SMS) (*SMS, error)) {
|
||||
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
|
||||
var request SendRequest
|
||||
if err := request.Decode(b); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response, err := f(ctx, request.Msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
s.handlers[SendRequestTypeID] = handler
|
||||
}
|
||||
|
||||
func (s *ServerDispatcher) OnSendMultipleSMS(f func(ctx context.Context, messages []SMS) error) {
|
||||
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
|
||||
var request SendMultipleSMSRequest
|
||||
if err := request.Decode(b); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := f(ctx, request.Messages); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Ok{}, nil
|
||||
}
|
||||
|
||||
s.handlers[SendMultipleSMSRequestTypeID] = handler
|
||||
}
|
||||
|
||||
func (s *ServerDispatcher) OnDoAuth(f func(ctx context.Context) (AuthClass, error)) {
|
||||
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
|
||||
var request DoAuthRequest
|
||||
if err := request.Decode(b); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response, err := f(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AuthBox{Auth: response}, nil
|
||||
}
|
||||
|
||||
s.handlers[DoAuthRequestTypeID] = handler
|
||||
}
|
||||
|
||||
func (s *ServerDispatcher) OnEchoVector(f func(ctx context.Context, ids []int) ([]int, error)) {
|
||||
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
|
||||
var request EchoVectorRequest
|
||||
if err := request.Decode(b); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response, err := f(ctx, request.IDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &IntVector{Elems: response}, nil
|
||||
}
|
||||
|
||||
s.handlers[EchoVectorRequestTypeID] = handler
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// SMS represents TL type `sms#ed8bebfe`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/sms for reference.
|
||||
type SMS struct {
|
||||
// Text field of SMS.
|
||||
Text string
|
||||
}
|
||||
|
||||
// SMSTypeID is TL type id of SMS.
|
||||
const SMSTypeID = 0xed8bebfe
|
||||
|
||||
// Ensuring interfaces in compile-time for SMS.
|
||||
var (
|
||||
_ bin.Encoder = &SMS{}
|
||||
_ bin.Decoder = &SMS{}
|
||||
_ bin.BareEncoder = &SMS{}
|
||||
_ bin.BareDecoder = &SMS{}
|
||||
)
|
||||
|
||||
func (s *SMS) Zero() bool {
|
||||
if s == nil {
|
||||
return true
|
||||
}
|
||||
if !(s.Text == "") {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (s *SMS) String() string {
|
||||
if s == nil {
|
||||
return "SMS(nil)"
|
||||
}
|
||||
type Alias SMS
|
||||
return fmt.Sprintf("SMS%+v", Alias(*s))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*SMS) TypeID() uint32 {
|
||||
return SMSTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*SMS) TypeName() string {
|
||||
return "sms"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (s *SMS) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "sms",
|
||||
ID: SMSTypeID,
|
||||
}
|
||||
if s == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Text",
|
||||
SchemaName: "text",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (s *SMS) Encode(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't encode sms#ed8bebfe as nil")
|
||||
}
|
||||
b.PutID(SMSTypeID)
|
||||
return s.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (s *SMS) EncodeBare(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't encode sms#ed8bebfe as nil")
|
||||
}
|
||||
b.PutString(s.Text)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (s *SMS) Decode(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't decode sms#ed8bebfe to nil")
|
||||
}
|
||||
if err := b.ConsumeID(SMSTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode sms#ed8bebfe: %w", err)
|
||||
}
|
||||
return s.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (s *SMS) DecodeBare(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't decode sms#ed8bebfe to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode sms#ed8bebfe: field text: %w", err)
|
||||
}
|
||||
s.Text = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetText returns value of Text field.
|
||||
func (s *SMS) GetText() (value string) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
return s.Text
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// String represents TL type `string#b5286e24`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/string for reference.
|
||||
type String struct {
|
||||
}
|
||||
|
||||
// StringTypeID is TL type id of String.
|
||||
const StringTypeID = 0xb5286e24
|
||||
|
||||
// Ensuring interfaces in compile-time for String.
|
||||
var (
|
||||
_ bin.Encoder = &String{}
|
||||
_ bin.Decoder = &String{}
|
||||
_ bin.BareEncoder = &String{}
|
||||
_ bin.BareDecoder = &String{}
|
||||
)
|
||||
|
||||
func (s *String) Zero() bool {
|
||||
if s == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (s *String) String() string {
|
||||
if s == nil {
|
||||
return "String(nil)"
|
||||
}
|
||||
type Alias String
|
||||
return fmt.Sprintf("String%+v", Alias(*s))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*String) TypeID() uint32 {
|
||||
return StringTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*String) TypeName() string {
|
||||
return "string"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (s *String) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "string",
|
||||
ID: StringTypeID,
|
||||
}
|
||||
if s == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (s *String) Encode(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't encode string#b5286e24 as nil")
|
||||
}
|
||||
b.PutID(StringTypeID)
|
||||
return s.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (s *String) EncodeBare(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't encode string#b5286e24 as nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (s *String) Decode(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't decode string#b5286e24 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(StringTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode string#b5286e24: %w", err)
|
||||
}
|
||||
return s.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (s *String) DecodeBare(b *bin.Buffer) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("can't decode string#b5286e24 to nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TestBytes represents TL type `testBytes#a422c4de`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/testBytes for reference.
|
||||
type TestBytes struct {
|
||||
// Bytes
|
||||
Value []byte
|
||||
}
|
||||
|
||||
// TestBytesTypeID is TL type id of TestBytes.
|
||||
const TestBytesTypeID = 0xa422c4de
|
||||
|
||||
// Ensuring interfaces in compile-time for TestBytes.
|
||||
var (
|
||||
_ bin.Encoder = &TestBytes{}
|
||||
_ bin.Decoder = &TestBytes{}
|
||||
_ bin.BareEncoder = &TestBytes{}
|
||||
_ bin.BareDecoder = &TestBytes{}
|
||||
)
|
||||
|
||||
func (t *TestBytes) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Value == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TestBytes) String() string {
|
||||
if t == nil {
|
||||
return "TestBytes(nil)"
|
||||
}
|
||||
type Alias TestBytes
|
||||
return fmt.Sprintf("TestBytes%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TestBytes) TypeID() uint32 {
|
||||
return TestBytesTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TestBytes) TypeName() string {
|
||||
return "testBytes"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TestBytes) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "testBytes",
|
||||
ID: TestBytesTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Value",
|
||||
SchemaName: "value",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TestBytes) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testBytes#a422c4de as nil")
|
||||
}
|
||||
b.PutID(TestBytesTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TestBytes) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testBytes#a422c4de as nil")
|
||||
}
|
||||
b.PutBytes(t.Value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TestBytes) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testBytes#a422c4de to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TestBytesTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode testBytes#a422c4de: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TestBytes) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testBytes#a422c4de to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.Bytes()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testBytes#a422c4de: field value: %w", err)
|
||||
}
|
||||
t.Value = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns value of Value field.
|
||||
func (t *TestBytes) GetValue() (value []byte) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Value
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TestInt represents TL type `testInt#ddbd2c09`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/testInt for reference.
|
||||
type TestInt struct {
|
||||
// Number
|
||||
Value int32
|
||||
}
|
||||
|
||||
// TestIntTypeID is TL type id of TestInt.
|
||||
const TestIntTypeID = 0xddbd2c09
|
||||
|
||||
// Ensuring interfaces in compile-time for TestInt.
|
||||
var (
|
||||
_ bin.Encoder = &TestInt{}
|
||||
_ bin.Decoder = &TestInt{}
|
||||
_ bin.BareEncoder = &TestInt{}
|
||||
_ bin.BareDecoder = &TestInt{}
|
||||
)
|
||||
|
||||
func (t *TestInt) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Value == 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TestInt) String() string {
|
||||
if t == nil {
|
||||
return "TestInt(nil)"
|
||||
}
|
||||
type Alias TestInt
|
||||
return fmt.Sprintf("TestInt%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TestInt) TypeID() uint32 {
|
||||
return TestIntTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TestInt) TypeName() string {
|
||||
return "testInt"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TestInt) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "testInt",
|
||||
ID: TestIntTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Value",
|
||||
SchemaName: "value",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TestInt) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testInt#ddbd2c09 as nil")
|
||||
}
|
||||
b.PutID(TestIntTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TestInt) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testInt#ddbd2c09 as nil")
|
||||
}
|
||||
b.PutInt32(t.Value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TestInt) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testInt#ddbd2c09 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TestIntTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode testInt#ddbd2c09: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TestInt) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testInt#ddbd2c09 to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testInt#ddbd2c09: field value: %w", err)
|
||||
}
|
||||
t.Value = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns value of Value field.
|
||||
func (t *TestInt) GetValue() (value int32) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Value
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TestString represents TL type `testString#fe56688c`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/testString for reference.
|
||||
type TestString struct {
|
||||
// String
|
||||
Value string
|
||||
}
|
||||
|
||||
// TestStringTypeID is TL type id of TestString.
|
||||
const TestStringTypeID = 0xfe56688c
|
||||
|
||||
// Ensuring interfaces in compile-time for TestString.
|
||||
var (
|
||||
_ bin.Encoder = &TestString{}
|
||||
_ bin.Decoder = &TestString{}
|
||||
_ bin.BareEncoder = &TestString{}
|
||||
_ bin.BareDecoder = &TestString{}
|
||||
)
|
||||
|
||||
func (t *TestString) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Value == "") {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TestString) String() string {
|
||||
if t == nil {
|
||||
return "TestString(nil)"
|
||||
}
|
||||
type Alias TestString
|
||||
return fmt.Sprintf("TestString%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TestString) TypeID() uint32 {
|
||||
return TestStringTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TestString) TypeName() string {
|
||||
return "testString"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TestString) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "testString",
|
||||
ID: TestStringTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Value",
|
||||
SchemaName: "value",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TestString) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testString#fe56688c as nil")
|
||||
}
|
||||
b.PutID(TestStringTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TestString) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testString#fe56688c as nil")
|
||||
}
|
||||
b.PutString(t.Value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TestString) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testString#fe56688c to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TestStringTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode testString#fe56688c: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TestString) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testString#fe56688c to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testString#fe56688c: field value: %w", err)
|
||||
}
|
||||
t.Value = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns value of Value field.
|
||||
func (t *TestString) GetValue() (value string) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Value
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TestVectorBytes represents TL type `testVectorBytes#a590fb25`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/testVectorBytes for reference.
|
||||
type TestVectorBytes struct {
|
||||
// Value field of TestVectorBytes.
|
||||
Value [][]byte
|
||||
}
|
||||
|
||||
// TestVectorBytesTypeID is TL type id of TestVectorBytes.
|
||||
const TestVectorBytesTypeID = 0xa590fb25
|
||||
|
||||
// Ensuring interfaces in compile-time for TestVectorBytes.
|
||||
var (
|
||||
_ bin.Encoder = &TestVectorBytes{}
|
||||
_ bin.Decoder = &TestVectorBytes{}
|
||||
_ bin.BareEncoder = &TestVectorBytes{}
|
||||
_ bin.BareDecoder = &TestVectorBytes{}
|
||||
)
|
||||
|
||||
func (t *TestVectorBytes) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Value == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TestVectorBytes) String() string {
|
||||
if t == nil {
|
||||
return "TestVectorBytes(nil)"
|
||||
}
|
||||
type Alias TestVectorBytes
|
||||
return fmt.Sprintf("TestVectorBytes%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TestVectorBytes) TypeID() uint32 {
|
||||
return TestVectorBytesTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TestVectorBytes) TypeName() string {
|
||||
return "testVectorBytes"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TestVectorBytes) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "testVectorBytes",
|
||||
ID: TestVectorBytesTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Value",
|
||||
SchemaName: "value",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TestVectorBytes) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorBytes#a590fb25 as nil")
|
||||
}
|
||||
b.PutID(TestVectorBytesTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TestVectorBytes) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorBytes#a590fb25 as nil")
|
||||
}
|
||||
b.PutInt(len(t.Value))
|
||||
for _, v := range t.Value {
|
||||
b.PutBytes(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TestVectorBytes) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorBytes#a590fb25 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TestVectorBytesTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorBytes#a590fb25: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TestVectorBytes) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorBytes#a590fb25 to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorBytes#a590fb25: field value: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
t.Value = make([][]byte, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
value, err := b.Bytes()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorBytes#a590fb25: field value: %w", err)
|
||||
}
|
||||
t.Value = append(t.Value, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns value of Value field.
|
||||
func (t *TestVectorBytes) GetValue() (value [][]byte) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Value
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TestVectorInt represents TL type `testVectorInt#df9eb113`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/testVectorInt for reference.
|
||||
type TestVectorInt struct {
|
||||
// Vector of numbers
|
||||
Value []int32
|
||||
}
|
||||
|
||||
// TestVectorIntTypeID is TL type id of TestVectorInt.
|
||||
const TestVectorIntTypeID = 0xdf9eb113
|
||||
|
||||
// Ensuring interfaces in compile-time for TestVectorInt.
|
||||
var (
|
||||
_ bin.Encoder = &TestVectorInt{}
|
||||
_ bin.Decoder = &TestVectorInt{}
|
||||
_ bin.BareEncoder = &TestVectorInt{}
|
||||
_ bin.BareDecoder = &TestVectorInt{}
|
||||
)
|
||||
|
||||
func (t *TestVectorInt) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Value == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TestVectorInt) String() string {
|
||||
if t == nil {
|
||||
return "TestVectorInt(nil)"
|
||||
}
|
||||
type Alias TestVectorInt
|
||||
return fmt.Sprintf("TestVectorInt%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TestVectorInt) TypeID() uint32 {
|
||||
return TestVectorIntTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TestVectorInt) TypeName() string {
|
||||
return "testVectorInt"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TestVectorInt) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "testVectorInt",
|
||||
ID: TestVectorIntTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Value",
|
||||
SchemaName: "value",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TestVectorInt) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorInt#df9eb113 as nil")
|
||||
}
|
||||
b.PutID(TestVectorIntTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TestVectorInt) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorInt#df9eb113 as nil")
|
||||
}
|
||||
b.PutInt(len(t.Value))
|
||||
for _, v := range t.Value {
|
||||
b.PutInt32(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TestVectorInt) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorInt#df9eb113 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TestVectorIntTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorInt#df9eb113: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TestVectorInt) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorInt#df9eb113 to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorInt#df9eb113: field value: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
t.Value = make([]int32, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
value, err := b.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorInt#df9eb113: field value: %w", err)
|
||||
}
|
||||
t.Value = append(t.Value, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns value of Value field.
|
||||
func (t *TestVectorInt) GetValue() (value []int32) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Value
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TestVectorIntObject represents TL type `testVectorIntObject#f152999b`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/testVectorIntObject for reference.
|
||||
type TestVectorIntObject struct {
|
||||
// Vector of objects
|
||||
Value []TestInt
|
||||
}
|
||||
|
||||
// TestVectorIntObjectTypeID is TL type id of TestVectorIntObject.
|
||||
const TestVectorIntObjectTypeID = 0xf152999b
|
||||
|
||||
// Ensuring interfaces in compile-time for TestVectorIntObject.
|
||||
var (
|
||||
_ bin.Encoder = &TestVectorIntObject{}
|
||||
_ bin.Decoder = &TestVectorIntObject{}
|
||||
_ bin.BareEncoder = &TestVectorIntObject{}
|
||||
_ bin.BareDecoder = &TestVectorIntObject{}
|
||||
)
|
||||
|
||||
func (t *TestVectorIntObject) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Value == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TestVectorIntObject) String() string {
|
||||
if t == nil {
|
||||
return "TestVectorIntObject(nil)"
|
||||
}
|
||||
type Alias TestVectorIntObject
|
||||
return fmt.Sprintf("TestVectorIntObject%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TestVectorIntObject) TypeID() uint32 {
|
||||
return TestVectorIntObjectTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TestVectorIntObject) TypeName() string {
|
||||
return "testVectorIntObject"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TestVectorIntObject) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "testVectorIntObject",
|
||||
ID: TestVectorIntObjectTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Value",
|
||||
SchemaName: "value",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TestVectorIntObject) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorIntObject#f152999b as nil")
|
||||
}
|
||||
b.PutID(TestVectorIntObjectTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TestVectorIntObject) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorIntObject#f152999b as nil")
|
||||
}
|
||||
b.PutInt(len(t.Value))
|
||||
for idx, v := range t.Value {
|
||||
if err := v.EncodeBare(b); err != nil {
|
||||
return fmt.Errorf("unable to encode bare testVectorIntObject#f152999b: field value element with index %d: %w", idx, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TestVectorIntObject) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorIntObject#f152999b to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TestVectorIntObjectTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorIntObject#f152999b: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TestVectorIntObject) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorIntObject#f152999b to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorIntObject#f152999b: field value: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
t.Value = make([]TestInt, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
var value TestInt
|
||||
if err := value.DecodeBare(b); err != nil {
|
||||
return fmt.Errorf("unable to decode bare testVectorIntObject#f152999b: field value: %w", err)
|
||||
}
|
||||
t.Value = append(t.Value, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns value of Value field.
|
||||
func (t *TestVectorIntObject) GetValue() (value []TestInt) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Value
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TestVectorString represents TL type `testVectorString#5d6f85bc`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/testVectorString for reference.
|
||||
type TestVectorString struct {
|
||||
// Vector of strings
|
||||
Value []string
|
||||
}
|
||||
|
||||
// TestVectorStringTypeID is TL type id of TestVectorString.
|
||||
const TestVectorStringTypeID = 0x5d6f85bc
|
||||
|
||||
// Ensuring interfaces in compile-time for TestVectorString.
|
||||
var (
|
||||
_ bin.Encoder = &TestVectorString{}
|
||||
_ bin.Decoder = &TestVectorString{}
|
||||
_ bin.BareEncoder = &TestVectorString{}
|
||||
_ bin.BareDecoder = &TestVectorString{}
|
||||
)
|
||||
|
||||
func (t *TestVectorString) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Value == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TestVectorString) String() string {
|
||||
if t == nil {
|
||||
return "TestVectorString(nil)"
|
||||
}
|
||||
type Alias TestVectorString
|
||||
return fmt.Sprintf("TestVectorString%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TestVectorString) TypeID() uint32 {
|
||||
return TestVectorStringTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TestVectorString) TypeName() string {
|
||||
return "testVectorString"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TestVectorString) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "testVectorString",
|
||||
ID: TestVectorStringTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Value",
|
||||
SchemaName: "value",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TestVectorString) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorString#5d6f85bc as nil")
|
||||
}
|
||||
b.PutID(TestVectorStringTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TestVectorString) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorString#5d6f85bc as nil")
|
||||
}
|
||||
b.PutInt(len(t.Value))
|
||||
for _, v := range t.Value {
|
||||
b.PutString(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TestVectorString) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorString#5d6f85bc to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TestVectorStringTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorString#5d6f85bc: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TestVectorString) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorString#5d6f85bc to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorString#5d6f85bc: field value: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
t.Value = make([]string, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorString#5d6f85bc: field value: %w", err)
|
||||
}
|
||||
t.Value = append(t.Value, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns value of Value field.
|
||||
func (t *TestVectorString) GetValue() (value []string) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Value
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TestVectorStringObject represents TL type `testVectorStringObject#e5ecc0d`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/testVectorStringObject for reference.
|
||||
type TestVectorStringObject struct {
|
||||
// Vector of objects
|
||||
Value []TestString
|
||||
}
|
||||
|
||||
// TestVectorStringObjectTypeID is TL type id of TestVectorStringObject.
|
||||
const TestVectorStringObjectTypeID = 0xe5ecc0d
|
||||
|
||||
// Ensuring interfaces in compile-time for TestVectorStringObject.
|
||||
var (
|
||||
_ bin.Encoder = &TestVectorStringObject{}
|
||||
_ bin.Decoder = &TestVectorStringObject{}
|
||||
_ bin.BareEncoder = &TestVectorStringObject{}
|
||||
_ bin.BareDecoder = &TestVectorStringObject{}
|
||||
)
|
||||
|
||||
func (t *TestVectorStringObject) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Value == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TestVectorStringObject) String() string {
|
||||
if t == nil {
|
||||
return "TestVectorStringObject(nil)"
|
||||
}
|
||||
type Alias TestVectorStringObject
|
||||
return fmt.Sprintf("TestVectorStringObject%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TestVectorStringObject) TypeID() uint32 {
|
||||
return TestVectorStringObjectTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TestVectorStringObject) TypeName() string {
|
||||
return "testVectorStringObject"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TestVectorStringObject) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "testVectorStringObject",
|
||||
ID: TestVectorStringObjectTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Value",
|
||||
SchemaName: "value",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TestVectorStringObject) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorStringObject#e5ecc0d as nil")
|
||||
}
|
||||
b.PutID(TestVectorStringObjectTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TestVectorStringObject) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorStringObject#e5ecc0d as nil")
|
||||
}
|
||||
b.PutInt(len(t.Value))
|
||||
for idx, v := range t.Value {
|
||||
if err := v.EncodeBare(b); err != nil {
|
||||
return fmt.Errorf("unable to encode bare testVectorStringObject#e5ecc0d: field value element with index %d: %w", idx, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TestVectorStringObject) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorStringObject#e5ecc0d to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TestVectorStringObjectTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorStringObject#e5ecc0d: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TestVectorStringObject) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorStringObject#e5ecc0d to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorStringObject#e5ecc0d: field value: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
t.Value = make([]TestString, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
var value TestString
|
||||
if err := value.DecodeBare(b); err != nil {
|
||||
return fmt.Errorf("unable to decode bare testVectorStringObject#e5ecc0d: field value: %w", err)
|
||||
}
|
||||
t.Value = append(t.Value, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns value of Value field.
|
||||
func (t *TestVectorStringObject) GetValue() (value []TestString) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Value
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TestVectorVector represents TL type `testVectorVector#69e8846c`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/testVectorVector for reference.
|
||||
type TestVectorVector struct {
|
||||
// Value field of TestVectorVector.
|
||||
Value [][]string
|
||||
}
|
||||
|
||||
// TestVectorVectorTypeID is TL type id of TestVectorVector.
|
||||
const TestVectorVectorTypeID = 0x69e8846c
|
||||
|
||||
// Ensuring interfaces in compile-time for TestVectorVector.
|
||||
var (
|
||||
_ bin.Encoder = &TestVectorVector{}
|
||||
_ bin.Decoder = &TestVectorVector{}
|
||||
_ bin.BareEncoder = &TestVectorVector{}
|
||||
_ bin.BareDecoder = &TestVectorVector{}
|
||||
)
|
||||
|
||||
func (t *TestVectorVector) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Value == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TestVectorVector) String() string {
|
||||
if t == nil {
|
||||
return "TestVectorVector(nil)"
|
||||
}
|
||||
type Alias TestVectorVector
|
||||
return fmt.Sprintf("TestVectorVector%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TestVectorVector) TypeID() uint32 {
|
||||
return TestVectorVectorTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TestVectorVector) TypeName() string {
|
||||
return "testVectorVector"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TestVectorVector) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "testVectorVector",
|
||||
ID: TestVectorVectorTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Value",
|
||||
SchemaName: "value",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TestVectorVector) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorVector#69e8846c as nil")
|
||||
}
|
||||
b.PutID(TestVectorVectorTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TestVectorVector) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode testVectorVector#69e8846c as nil")
|
||||
}
|
||||
b.PutInt(len(t.Value))
|
||||
for _, row := range t.Value {
|
||||
b.PutVectorHeader(len(row))
|
||||
for _, v := range row {
|
||||
b.PutString(v)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TestVectorVector) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorVector#69e8846c to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TestVectorVectorTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorVector#69e8846c: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TestVectorVector) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode testVectorVector#69e8846c to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorVector#69e8846c: field value: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
t.Value = make([][]string, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
innerLen, err := b.VectorHeader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorVector#69e8846c: field value: %w", err)
|
||||
}
|
||||
|
||||
var row []string
|
||||
if innerLen > 0 {
|
||||
row = make([]string, 0, innerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for innerIndex := 0; innerIndex < innerLen; innerLen++ {
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode testVectorVector#69e8846c: field value: %w", err)
|
||||
}
|
||||
row = append(row, value)
|
||||
}
|
||||
t.Value = append(t.Value, row)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns value of Value field.
|
||||
func (t *TestVectorVector) GetValue() (value [][]string) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Value
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TextEntities represents TL type `textEntities#cf89c258`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/textEntities for reference.
|
||||
type TextEntities struct {
|
||||
// List of text entities
|
||||
Entities []TextEntity
|
||||
}
|
||||
|
||||
// TextEntitiesTypeID is TL type id of TextEntities.
|
||||
const TextEntitiesTypeID = 0xcf89c258
|
||||
|
||||
// Ensuring interfaces in compile-time for TextEntities.
|
||||
var (
|
||||
_ bin.Encoder = &TextEntities{}
|
||||
_ bin.Decoder = &TextEntities{}
|
||||
_ bin.BareEncoder = &TextEntities{}
|
||||
_ bin.BareDecoder = &TextEntities{}
|
||||
)
|
||||
|
||||
func (t *TextEntities) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Entities == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TextEntities) String() string {
|
||||
if t == nil {
|
||||
return "TextEntities(nil)"
|
||||
}
|
||||
type Alias TextEntities
|
||||
return fmt.Sprintf("TextEntities%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TextEntities) TypeID() uint32 {
|
||||
return TextEntitiesTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TextEntities) TypeName() string {
|
||||
return "textEntities"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TextEntities) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "textEntities",
|
||||
ID: TextEntitiesTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Entities",
|
||||
SchemaName: "entities",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TextEntities) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode textEntities#cf89c258 as nil")
|
||||
}
|
||||
b.PutID(TextEntitiesTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TextEntities) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode textEntities#cf89c258 as nil")
|
||||
}
|
||||
b.PutInt(len(t.Entities))
|
||||
for idx, v := range t.Entities {
|
||||
if err := v.EncodeBare(b); err != nil {
|
||||
return fmt.Errorf("unable to encode bare textEntities#cf89c258: field entities element with index %d: %w", idx, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TextEntities) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode textEntities#cf89c258 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TextEntitiesTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode textEntities#cf89c258: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TextEntities) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode textEntities#cf89c258 to nil")
|
||||
}
|
||||
{
|
||||
headerLen, err := b.Int()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode textEntities#cf89c258: field entities: %w", err)
|
||||
}
|
||||
|
||||
if headerLen > 0 {
|
||||
t.Entities = make([]TextEntity, 0, headerLen%bin.PreallocateLimit)
|
||||
}
|
||||
for idx := 0; idx < headerLen; idx++ {
|
||||
var value TextEntity
|
||||
if err := value.DecodeBare(b); err != nil {
|
||||
return fmt.Errorf("unable to decode bare textEntities#cf89c258: field entities: %w", err)
|
||||
}
|
||||
t.Entities = append(t.Entities, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetEntities returns value of Entities field.
|
||||
func (t *TextEntities) GetEntities() (value []TextEntity) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Entities
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// TextEntity represents TL type `textEntity#8bab99a8`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/textEntity for reference.
|
||||
type TextEntity struct {
|
||||
// Offset of the entity, in UTF-16 code units
|
||||
Offset int32
|
||||
// Length of the entity, in UTF-16 code units
|
||||
Length int32
|
||||
// Type of the entity
|
||||
Type TextEntityTypeClass
|
||||
}
|
||||
|
||||
// TextEntityTypeID is TL type id of TextEntity.
|
||||
const TextEntityTypeID = 0x8bab99a8
|
||||
|
||||
// Ensuring interfaces in compile-time for TextEntity.
|
||||
var (
|
||||
_ bin.Encoder = &TextEntity{}
|
||||
_ bin.Decoder = &TextEntity{}
|
||||
_ bin.BareEncoder = &TextEntity{}
|
||||
_ bin.BareDecoder = &TextEntity{}
|
||||
)
|
||||
|
||||
func (t *TextEntity) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Offset == 0) {
|
||||
return false
|
||||
}
|
||||
if !(t.Length == 0) {
|
||||
return false
|
||||
}
|
||||
if !(t.Type == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *TextEntity) String() string {
|
||||
if t == nil {
|
||||
return "TextEntity(nil)"
|
||||
}
|
||||
type Alias TextEntity
|
||||
return fmt.Sprintf("TextEntity%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*TextEntity) TypeID() uint32 {
|
||||
return TextEntityTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*TextEntity) TypeName() string {
|
||||
return "textEntity"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *TextEntity) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "textEntity",
|
||||
ID: TextEntityTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Offset",
|
||||
SchemaName: "offset",
|
||||
},
|
||||
{
|
||||
Name: "Length",
|
||||
SchemaName: "length",
|
||||
},
|
||||
{
|
||||
Name: "Type",
|
||||
SchemaName: "type",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *TextEntity) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode textEntity#8bab99a8 as nil")
|
||||
}
|
||||
b.PutID(TextEntityTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *TextEntity) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode textEntity#8bab99a8 as nil")
|
||||
}
|
||||
b.PutInt32(t.Offset)
|
||||
b.PutInt32(t.Length)
|
||||
if t.Type == nil {
|
||||
return fmt.Errorf("unable to encode textEntity#8bab99a8: field type is nil")
|
||||
}
|
||||
if err := t.Type.Encode(b); err != nil {
|
||||
return fmt.Errorf("unable to encode textEntity#8bab99a8: field type: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *TextEntity) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode textEntity#8bab99a8 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(TextEntityTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode textEntity#8bab99a8: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *TextEntity) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode textEntity#8bab99a8 to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode textEntity#8bab99a8: field offset: %w", err)
|
||||
}
|
||||
t.Offset = value
|
||||
}
|
||||
{
|
||||
value, err := b.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode textEntity#8bab99a8: field length: %w", err)
|
||||
}
|
||||
t.Length = value
|
||||
}
|
||||
{
|
||||
value, err := DecodeTextEntityType(b)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode textEntity#8bab99a8: field type: %w", err)
|
||||
}
|
||||
t.Type = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOffset returns value of Offset field.
|
||||
func (t *TextEntity) GetOffset() (value int32) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Offset
|
||||
}
|
||||
|
||||
// GetLength returns value of Length field.
|
||||
func (t *TextEntity) GetLength() (value int32) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Length
|
||||
}
|
||||
|
||||
// GetType returns value of Type field.
|
||||
func (t *TextEntity) GetType() (value TextEntityTypeClass) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Type
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,154 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// Theme represents TL type `theme#28f1114`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/theme for reference.
|
||||
type Theme struct {
|
||||
// Name field of Theme.
|
||||
Name string
|
||||
}
|
||||
|
||||
// ThemeTypeID is TL type id of Theme.
|
||||
const ThemeTypeID = 0x28f1114
|
||||
|
||||
// Ensuring interfaces in compile-time for Theme.
|
||||
var (
|
||||
_ bin.Encoder = &Theme{}
|
||||
_ bin.Decoder = &Theme{}
|
||||
_ bin.BareEncoder = &Theme{}
|
||||
_ bin.BareDecoder = &Theme{}
|
||||
)
|
||||
|
||||
func (t *Theme) Zero() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if !(t.Name == "") {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (t *Theme) String() string {
|
||||
if t == nil {
|
||||
return "Theme(nil)"
|
||||
}
|
||||
type Alias Theme
|
||||
return fmt.Sprintf("Theme%+v", Alias(*t))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*Theme) TypeID() uint32 {
|
||||
return ThemeTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*Theme) TypeName() string {
|
||||
return "theme"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (t *Theme) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "theme",
|
||||
ID: ThemeTypeID,
|
||||
}
|
||||
if t == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Name",
|
||||
SchemaName: "name",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (t *Theme) Encode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode theme#28f1114 as nil")
|
||||
}
|
||||
b.PutID(ThemeTypeID)
|
||||
return t.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (t *Theme) EncodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't encode theme#28f1114 as nil")
|
||||
}
|
||||
b.PutString(t.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (t *Theme) Decode(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode theme#28f1114 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(ThemeTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode theme#28f1114: %w", err)
|
||||
}
|
||||
return t.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (t *Theme) DecodeBare(b *bin.Buffer) error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("can't decode theme#28f1114 to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode theme#28f1114: field name: %w", err)
|
||||
}
|
||||
t.Name = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetName returns value of Name field.
|
||||
func (t *Theme) GetName() (value string) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
return t.Name
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// Update represents TL type `update#b03e2ef8`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/update for reference.
|
||||
type Update struct {
|
||||
// Msg field of Update.
|
||||
Msg AbstractMessageClass
|
||||
// Delay field of Update.
|
||||
Delay int32
|
||||
}
|
||||
|
||||
// UpdateTypeID is TL type id of Update.
|
||||
const UpdateTypeID = 0xb03e2ef8
|
||||
|
||||
// Ensuring interfaces in compile-time for Update.
|
||||
var (
|
||||
_ bin.Encoder = &Update{}
|
||||
_ bin.Decoder = &Update{}
|
||||
_ bin.BareEncoder = &Update{}
|
||||
_ bin.BareDecoder = &Update{}
|
||||
)
|
||||
|
||||
func (u *Update) Zero() bool {
|
||||
if u == nil {
|
||||
return true
|
||||
}
|
||||
if !(u.Msg == nil) {
|
||||
return false
|
||||
}
|
||||
if !(u.Delay == 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (u *Update) String() string {
|
||||
if u == nil {
|
||||
return "Update(nil)"
|
||||
}
|
||||
type Alias Update
|
||||
return fmt.Sprintf("Update%+v", Alias(*u))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*Update) TypeID() uint32 {
|
||||
return UpdateTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*Update) TypeName() string {
|
||||
return "update"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (u *Update) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "update",
|
||||
ID: UpdateTypeID,
|
||||
}
|
||||
if u == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Msg",
|
||||
SchemaName: "msg",
|
||||
},
|
||||
{
|
||||
Name: "Delay",
|
||||
SchemaName: "delay",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (u *Update) Encode(b *bin.Buffer) error {
|
||||
if u == nil {
|
||||
return fmt.Errorf("can't encode update#b03e2ef8 as nil")
|
||||
}
|
||||
b.PutID(UpdateTypeID)
|
||||
return u.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (u *Update) EncodeBare(b *bin.Buffer) error {
|
||||
if u == nil {
|
||||
return fmt.Errorf("can't encode update#b03e2ef8 as nil")
|
||||
}
|
||||
if u.Msg == nil {
|
||||
return fmt.Errorf("unable to encode update#b03e2ef8: field msg is nil")
|
||||
}
|
||||
if err := u.Msg.Encode(b); err != nil {
|
||||
return fmt.Errorf("unable to encode update#b03e2ef8: field msg: %w", err)
|
||||
}
|
||||
b.PutInt32(u.Delay)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (u *Update) Decode(b *bin.Buffer) error {
|
||||
if u == nil {
|
||||
return fmt.Errorf("can't decode update#b03e2ef8 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(UpdateTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode update#b03e2ef8: %w", err)
|
||||
}
|
||||
return u.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (u *Update) DecodeBare(b *bin.Buffer) error {
|
||||
if u == nil {
|
||||
return fmt.Errorf("can't decode update#b03e2ef8 to nil")
|
||||
}
|
||||
{
|
||||
value, err := DecodeAbstractMessage(b)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode update#b03e2ef8: field msg: %w", err)
|
||||
}
|
||||
u.Msg = value
|
||||
}
|
||||
{
|
||||
value, err := b.Int32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode update#b03e2ef8: field delay: %w", err)
|
||||
}
|
||||
u.Delay = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetMsg returns value of Msg field.
|
||||
func (u *Update) GetMsg() (value AbstractMessageClass) {
|
||||
if u == nil {
|
||||
return
|
||||
}
|
||||
return u.Msg
|
||||
}
|
||||
|
||||
// GetDelay returns value of Delay field.
|
||||
func (u *Update) GetDelay() (value int32) {
|
||||
if u == nil {
|
||||
return
|
||||
}
|
||||
return u.Delay
|
||||
}
|
||||
@@ -0,0 +1,375 @@
|
||||
// Code generated by gotdgen, DO NOT EDIT.
|
||||
|
||||
package td
|
||||
|
||||
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{}
|
||||
)
|
||||
|
||||
// UserAuth represents TL type `user.auth#f4815592`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/user.auth for reference.
|
||||
type UserAuth struct {
|
||||
// Foo field of UserAuth.
|
||||
Foo string
|
||||
}
|
||||
|
||||
// UserAuthTypeID is TL type id of UserAuth.
|
||||
const UserAuthTypeID = 0xf4815592
|
||||
|
||||
// construct implements constructor of UserAuthClass.
|
||||
func (a UserAuth) construct() UserAuthClass { return &a }
|
||||
|
||||
// Ensuring interfaces in compile-time for UserAuth.
|
||||
var (
|
||||
_ bin.Encoder = &UserAuth{}
|
||||
_ bin.Decoder = &UserAuth{}
|
||||
_ bin.BareEncoder = &UserAuth{}
|
||||
_ bin.BareDecoder = &UserAuth{}
|
||||
|
||||
_ UserAuthClass = &UserAuth{}
|
||||
)
|
||||
|
||||
func (a *UserAuth) Zero() bool {
|
||||
if a == nil {
|
||||
return true
|
||||
}
|
||||
if !(a.Foo == "") {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (a *UserAuth) String() string {
|
||||
if a == nil {
|
||||
return "UserAuth(nil)"
|
||||
}
|
||||
type Alias UserAuth
|
||||
return fmt.Sprintf("UserAuth%+v", Alias(*a))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*UserAuth) TypeID() uint32 {
|
||||
return UserAuthTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*UserAuth) TypeName() string {
|
||||
return "user.auth"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (a *UserAuth) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "user.auth",
|
||||
ID: UserAuthTypeID,
|
||||
}
|
||||
if a == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Foo",
|
||||
SchemaName: "foo",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (a *UserAuth) Encode(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't encode user.auth#f4815592 as nil")
|
||||
}
|
||||
b.PutID(UserAuthTypeID)
|
||||
return a.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (a *UserAuth) EncodeBare(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't encode user.auth#f4815592 as nil")
|
||||
}
|
||||
b.PutString(a.Foo)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (a *UserAuth) Decode(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't decode user.auth#f4815592 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(UserAuthTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode user.auth#f4815592: %w", err)
|
||||
}
|
||||
return a.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (a *UserAuth) DecodeBare(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't decode user.auth#f4815592 to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode user.auth#f4815592: field foo: %w", err)
|
||||
}
|
||||
a.Foo = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetFoo returns value of Foo field.
|
||||
func (a *UserAuth) GetFoo() (value string) {
|
||||
if a == nil {
|
||||
return
|
||||
}
|
||||
return a.Foo
|
||||
}
|
||||
|
||||
// UserAuthPassword represents TL type `user.authPassword#5981e317`.
|
||||
//
|
||||
// See https://localhost:80/doc/constructor/user.authPassword for reference.
|
||||
type UserAuthPassword struct {
|
||||
// Pwd field of UserAuthPassword.
|
||||
Pwd string
|
||||
}
|
||||
|
||||
// UserAuthPasswordTypeID is TL type id of UserAuthPassword.
|
||||
const UserAuthPasswordTypeID = 0x5981e317
|
||||
|
||||
// construct implements constructor of UserAuthClass.
|
||||
func (a UserAuthPassword) construct() UserAuthClass { return &a }
|
||||
|
||||
// Ensuring interfaces in compile-time for UserAuthPassword.
|
||||
var (
|
||||
_ bin.Encoder = &UserAuthPassword{}
|
||||
_ bin.Decoder = &UserAuthPassword{}
|
||||
_ bin.BareEncoder = &UserAuthPassword{}
|
||||
_ bin.BareDecoder = &UserAuthPassword{}
|
||||
|
||||
_ UserAuthClass = &UserAuthPassword{}
|
||||
)
|
||||
|
||||
func (a *UserAuthPassword) Zero() bool {
|
||||
if a == nil {
|
||||
return true
|
||||
}
|
||||
if !(a.Pwd == "") {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (a *UserAuthPassword) String() string {
|
||||
if a == nil {
|
||||
return "UserAuthPassword(nil)"
|
||||
}
|
||||
type Alias UserAuthPassword
|
||||
return fmt.Sprintf("UserAuthPassword%+v", Alias(*a))
|
||||
}
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
func (*UserAuthPassword) TypeID() uint32 {
|
||||
return UserAuthPasswordTypeID
|
||||
}
|
||||
|
||||
// TypeName returns name of type in TL schema.
|
||||
func (*UserAuthPassword) TypeName() string {
|
||||
return "user.authPassword"
|
||||
}
|
||||
|
||||
// TypeInfo returns info about TL type.
|
||||
func (a *UserAuthPassword) TypeInfo() tdp.Type {
|
||||
typ := tdp.Type{
|
||||
Name: "user.authPassword",
|
||||
ID: UserAuthPasswordTypeID,
|
||||
}
|
||||
if a == nil {
|
||||
typ.Null = true
|
||||
return typ
|
||||
}
|
||||
typ.Fields = []tdp.Field{
|
||||
{
|
||||
Name: "Pwd",
|
||||
SchemaName: "pwd",
|
||||
},
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// Encode implements bin.Encoder.
|
||||
func (a *UserAuthPassword) Encode(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't encode user.authPassword#5981e317 as nil")
|
||||
}
|
||||
b.PutID(UserAuthPasswordTypeID)
|
||||
return a.EncodeBare(b)
|
||||
}
|
||||
|
||||
// EncodeBare implements bin.BareEncoder.
|
||||
func (a *UserAuthPassword) EncodeBare(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't encode user.authPassword#5981e317 as nil")
|
||||
}
|
||||
b.PutString(a.Pwd)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder.
|
||||
func (a *UserAuthPassword) Decode(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't decode user.authPassword#5981e317 to nil")
|
||||
}
|
||||
if err := b.ConsumeID(UserAuthPasswordTypeID); err != nil {
|
||||
return fmt.Errorf("unable to decode user.authPassword#5981e317: %w", err)
|
||||
}
|
||||
return a.DecodeBare(b)
|
||||
}
|
||||
|
||||
// DecodeBare implements bin.BareDecoder.
|
||||
func (a *UserAuthPassword) DecodeBare(b *bin.Buffer) error {
|
||||
if a == nil {
|
||||
return fmt.Errorf("can't decode user.authPassword#5981e317 to nil")
|
||||
}
|
||||
{
|
||||
value, err := b.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode user.authPassword#5981e317: field pwd: %w", err)
|
||||
}
|
||||
a.Pwd = value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPwd returns value of Pwd field.
|
||||
func (a *UserAuthPassword) GetPwd() (value string) {
|
||||
if a == nil {
|
||||
return
|
||||
}
|
||||
return a.Pwd
|
||||
}
|
||||
|
||||
// UserAuthClassName is schema name of UserAuthClass.
|
||||
const UserAuthClassName = "user.Auth"
|
||||
|
||||
// UserAuthClass represents user.Auth generic type.
|
||||
//
|
||||
// See https://localhost:80/doc/type/user.Auth for reference.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// g, err := td.DecodeUserAuth(buf)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// switch v := g.(type) {
|
||||
// case *td.UserAuth: // user.auth#f4815592
|
||||
// case *td.UserAuthPassword: // user.authPassword#5981e317
|
||||
// default: panic(v)
|
||||
// }
|
||||
type UserAuthClass interface {
|
||||
bin.Encoder
|
||||
bin.Decoder
|
||||
bin.BareEncoder
|
||||
bin.BareDecoder
|
||||
construct() UserAuthClass
|
||||
|
||||
// TypeID returns type id in TL schema.
|
||||
//
|
||||
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
||||
TypeID() uint32
|
||||
// TypeName returns name of type in TL schema.
|
||||
TypeName() string
|
||||
// String implements fmt.Stringer.
|
||||
String() string
|
||||
// Zero returns true if current object has a zero value.
|
||||
Zero() bool
|
||||
}
|
||||
|
||||
// DecodeUserAuth implements binary de-serialization for UserAuthClass.
|
||||
func DecodeUserAuth(buf *bin.Buffer) (UserAuthClass, error) {
|
||||
id, err := buf.PeekID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch id {
|
||||
case UserAuthTypeID:
|
||||
// Decoding user.auth#f4815592.
|
||||
v := UserAuth{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode UserAuthClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
case UserAuthPasswordTypeID:
|
||||
// Decoding user.authPassword#5981e317.
|
||||
v := UserAuthPassword{}
|
||||
if err := v.Decode(buf); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode UserAuthClass: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to decode UserAuthClass: %w", bin.NewUnexpectedID(id))
|
||||
}
|
||||
}
|
||||
|
||||
// UserAuth boxes the UserAuthClass providing a helper.
|
||||
type UserAuthBox struct {
|
||||
Auth UserAuthClass
|
||||
}
|
||||
|
||||
// Decode implements bin.Decoder for UserAuthBox.
|
||||
func (b *UserAuthBox) Decode(buf *bin.Buffer) error {
|
||||
if b == nil {
|
||||
return fmt.Errorf("unable to decode UserAuthBox to nil")
|
||||
}
|
||||
v, err := DecodeUserAuth(buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode boxed value: %w", err)
|
||||
}
|
||||
b.Auth = v
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode implements bin.Encode for UserAuthBox.
|
||||
func (b *UserAuthBox) Encode(buf *bin.Buffer) error {
|
||||
if b == nil || b.Auth == nil {
|
||||
return fmt.Errorf("unable to encode UserAuthClass as nil")
|
||||
}
|
||||
return b.Auth.Encode(buf)
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func optionalField(s structDef, f fieldDef) bool {
|
||||
switch {
|
||||
case f.Conditional:
|
||||
return true
|
||||
case f.Type == "string" && f.Name == "ThumbSize":
|
||||
return s.RawName == "inputDocumentFileLocation"
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func hasField(fields []fieldDef, name, typ string) bool {
|
||||
for _, f := range fields {
|
||||
if f.Name == name && f.Type == typ {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func mappableFields(constructor, to structDef) (constructorMapping, bool) {
|
||||
var r []fieldPair
|
||||
mapped := map[string]struct{}{}
|
||||
for _, a := range constructor.Fields {
|
||||
if a.Type == flagsType {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, b := range to.Fields {
|
||||
if b.Type == flagsType {
|
||||
continue
|
||||
}
|
||||
|
||||
if a.SameType(b) && strings.Contains(b.Name, a.Name) {
|
||||
r = append(r, fieldPair{a, b})
|
||||
mapped[b.Name] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return false if we can't fill all fields.
|
||||
if len(mapped) != len(to.Fields) {
|
||||
for _, field := range to.Fields {
|
||||
if _, ok := mapped[field.Name]; !ok && !optionalField(to, field) {
|
||||
return constructorMapping{}, false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mapperName := to.Name
|
||||
// Mapping: User => InputUser, so mapperName = "Input"
|
||||
// Mapping: Document => InputDocumentFileLocation, so mapperName = "InputDocumentFileLocation"
|
||||
if strings.HasSuffix(to.Name, constructor.Name) {
|
||||
mapperName = strings.TrimSuffix(to.Name, constructor.Name)
|
||||
}
|
||||
|
||||
mapping := constructorMapping{
|
||||
Name: to.Name,
|
||||
Constructor: constructor.Name,
|
||||
Concrete: true,
|
||||
MapperName: mapperName,
|
||||
Fields: r,
|
||||
}
|
||||
|
||||
return mapping, true
|
||||
}
|
||||
|
||||
func intersectFields(a, b []fieldDef) []fieldDef {
|
||||
return intersectFieldsBy(a, b, fieldDef.EqualAsField)
|
||||
}
|
||||
|
||||
func intersectFieldsBy(a, b []fieldDef, compare func(a, b fieldDef) bool) []fieldDef {
|
||||
// If a is empty, copy all from b to a.
|
||||
if a == nil {
|
||||
a = make([]fieldDef, len(b))
|
||||
copy(a, b)
|
||||
} else { // Otherwise intersect.
|
||||
a = commonFields(a, b, compare)
|
||||
}
|
||||
|
||||
return filterFields(a, func(def fieldDef) bool {
|
||||
// Filter bin.Flags fields.
|
||||
return def.Type != flagsType
|
||||
})
|
||||
}
|
||||
|
||||
func commonFields(a, b []fieldDef, compare func(a, b fieldDef) bool) []fieldDef {
|
||||
return filterFields(a, func(def fieldDef) bool {
|
||||
for _, x := range b {
|
||||
if compare(x, def) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
func filterFields(a []fieldDef, filter func(def fieldDef) bool) []fieldDef {
|
||||
n := 0
|
||||
for _, f := range a {
|
||||
if filter(f) {
|
||||
a[n] = f
|
||||
n++
|
||||
}
|
||||
}
|
||||
a = a[:n]
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func filterFieldsTo(a, b []fieldDef, filter func(def fieldDef) bool) []fieldDef {
|
||||
for _, f := range a {
|
||||
if filter(f) {
|
||||
b = append(b, f)
|
||||
}
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package gen
|
||||
|
||||
// This file defines how to generate templates and example
|
||||
// generated files.
|
||||
|
||||
//go:generate go run go.mau.fi/mautrix-telegram/pkg/gotd/cmd/gotdgen --doc "https://localhost:80/doc" --clean --package td --target example --schema _testdata/example.tl --server
|
||||
@@ -0,0 +1,89 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"github.com/gotd/getdoc"
|
||||
"github.com/gotd/tl"
|
||||
)
|
||||
|
||||
func definitionType(d tl.Definition) string {
|
||||
if len(d.Namespace) == 0 {
|
||||
return d.Name
|
||||
}
|
||||
return fmt.Sprintf("%s.%s", strings.Join(d.Namespace, "."), d.Name)
|
||||
}
|
||||
|
||||
// Generator generates go types from tl.Schema.
|
||||
type Generator struct {
|
||||
schema *tl.Schema
|
||||
|
||||
// classes type bindings, key is TL type.
|
||||
classes map[string]classBinding
|
||||
// types bindings, key is TL type.
|
||||
types map[string]typeBinding
|
||||
|
||||
// structs definitions.
|
||||
structs []structDef
|
||||
// interfaces definitions.
|
||||
interfaces []interfaceDef
|
||||
// errorChecks definitions.
|
||||
errorChecks []errCheckDef
|
||||
|
||||
// constructor mappings.
|
||||
mappings map[string][]constructorMapping
|
||||
|
||||
// registry of type ids.
|
||||
registry []bindingDef
|
||||
|
||||
// docBase is base url for documentation.
|
||||
docBase *url.URL
|
||||
doc *getdoc.Doc
|
||||
docLineLimit int
|
||||
|
||||
generateFlags GenerateFlags
|
||||
}
|
||||
|
||||
// NewGenerator initializes and returns new Generator from tl.Schema.
|
||||
func NewGenerator(s *tl.Schema, genOpt GeneratorOptions) (*Generator, error) {
|
||||
genOpt.setDefaults()
|
||||
g := &Generator{
|
||||
schema: s,
|
||||
classes: map[string]classBinding{},
|
||||
types: map[string]typeBinding{},
|
||||
mappings: map[string][]constructorMapping{},
|
||||
docLineLimit: genOpt.DocLineLimit,
|
||||
generateFlags: genOpt.GenerateFlags,
|
||||
}
|
||||
if genOpt.DocBaseURL != "" {
|
||||
u, err := url.Parse(genOpt.DocBaseURL)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "parse docBase")
|
||||
}
|
||||
g.docBase = u
|
||||
|
||||
if u.Host == "core.telegram.org" {
|
||||
// Using embedded documentation.
|
||||
// TODO(ernado): Get actual layer
|
||||
doc, err := getdoc.Load(getdoc.LayerLatest)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get documentation")
|
||||
}
|
||||
g.doc = doc
|
||||
}
|
||||
}
|
||||
if err := g.makeBindings(); err != nil {
|
||||
return nil, errors.Wrap(err, "make type bindings")
|
||||
}
|
||||
if err := g.makeStructures(); err != nil {
|
||||
return nil, errors.Wrap(err, "generate go structures")
|
||||
}
|
||||
g.makeInterfaces()
|
||||
g.makeErrors()
|
||||
|
||||
return g, nil
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"go/format"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"github.com/gotd/tl"
|
||||
)
|
||||
|
||||
type formattedSource struct{}
|
||||
|
||||
func (t formattedSource) WriteFile(name string, content []byte) error {
|
||||
if name == "" {
|
||||
return errors.New("name is blank")
|
||||
}
|
||||
_, err := format.Source(content)
|
||||
return err
|
||||
}
|
||||
|
||||
func TestGenerator(t *testing.T) {
|
||||
data, err := os.ReadFile("_testdata/example.tl")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
schema, err := tl.Parse(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
g, err := NewGenerator(schema, GeneratorOptions{
|
||||
GenerateFlags: GenerateFlags{
|
||||
Client: true,
|
||||
Registry: true,
|
||||
Server: true,
|
||||
Handlers: true,
|
||||
GetSet: true,
|
||||
Mapping: true,
|
||||
Slices: true,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := g.WriteSource(formattedSource{}, "pkg", Template()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratorTelegram(t *testing.T) {
|
||||
data, err := os.ReadFile("_testdata/telegram.tl")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
schema, err := tl.Parse(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
g, err := NewGenerator(schema, GeneratorOptions{DocBaseURL: "https://core.telegram.org/"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := g.WriteSource(formattedSource{}, "pkg", Template()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"github.com/gotd/tl"
|
||||
)
|
||||
|
||||
type typeBinding struct {
|
||||
Namespace []string
|
||||
Class string // user.Auth, class in TL
|
||||
Name string // go type name, like in type Name struct{}
|
||||
Interface string // go type interface, like UserAuthClass
|
||||
InterfaceFunc string // go encoding/decoding function postfix, like UserAuth in DecodeUserAuth
|
||||
Method string // go method name if function
|
||||
}
|
||||
|
||||
type classBinding struct {
|
||||
// Name as used in go interface type definition,
|
||||
// i.e. type Name interface {}.
|
||||
Name string
|
||||
// Func is used as postfix for Decode and Encode functions.
|
||||
Func string
|
||||
Namespace []string
|
||||
// Singular is special case for class where single constructor replaces
|
||||
// class.
|
||||
Singular bool
|
||||
Vector bool
|
||||
Constructors []string
|
||||
|
||||
// BaseName is "Auth" for user.Auth interface.
|
||||
BaseName string
|
||||
// RawType of class from TL.
|
||||
RawType string
|
||||
}
|
||||
|
||||
// namespacedName returns camel-case name with namespace prefix.
|
||||
func namespacedName(name string, namespace []string) string {
|
||||
goName := pascal(name)
|
||||
if len(namespace) > 0 {
|
||||
var b strings.Builder
|
||||
for _, ns := range namespace {
|
||||
b.WriteString(pascal(ns))
|
||||
}
|
||||
b.WriteString(goName)
|
||||
goName = b.String()
|
||||
}
|
||||
return goName
|
||||
}
|
||||
|
||||
// makeBindings fills classes and types fields of Generator.
|
||||
func (g *Generator) makeBindings() error {
|
||||
// 1) Searching for all classes with single constructor.
|
||||
// If class has single constructor, it can be reduced to specific type.
|
||||
constructors := map[string]int{}
|
||||
for _, d := range g.schema.Definitions {
|
||||
if d.Category != tl.CategoryType {
|
||||
continue
|
||||
}
|
||||
constructors[d.Definition.Type.String()]++
|
||||
}
|
||||
|
||||
// 2) Binding TL types to structures and interfaces.
|
||||
for _, sd := range g.schema.Definitions {
|
||||
var (
|
||||
d = sd.Definition
|
||||
classKey = d.Type.String()
|
||||
typeKey = definitionType(d)
|
||||
goName = namespacedName(d.Name, d.Namespace)
|
||||
)
|
||||
|
||||
// Binding bare type.
|
||||
tb := typeBinding{
|
||||
Namespace: d.Namespace,
|
||||
Class: classKey,
|
||||
Name: goName,
|
||||
}
|
||||
|
||||
switch sd.Category {
|
||||
case tl.CategoryType:
|
||||
constructorsCount, ok := constructors[classKey]
|
||||
if constructorsCount == 0 || !ok {
|
||||
return errors.Errorf("constructors[%s] not found", classKey)
|
||||
}
|
||||
if constructorsCount == 1 {
|
||||
// Using this constructor instead of generic class for all definitions
|
||||
// that depends on that class.
|
||||
b := classBinding{
|
||||
Namespace: d.Namespace,
|
||||
Singular: true,
|
||||
Name: goName,
|
||||
BaseName: d.Type.Name,
|
||||
}
|
||||
g.classes[classKey] = b
|
||||
g.types[typeKey] = tb
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := g.classes[classKey]; !ok {
|
||||
// interfaceDef has multiple constructors and is new.
|
||||
className := namespacedName(d.Type.Name, d.Type.Namespace)
|
||||
g.classes[classKey] = classBinding{
|
||||
Namespace: d.Namespace,
|
||||
Singular: false,
|
||||
Func: className,
|
||||
Name: className + "Class",
|
||||
BaseName: d.Type.Name,
|
||||
RawType: d.Type.String(),
|
||||
}
|
||||
}
|
||||
|
||||
c := g.classes[classKey]
|
||||
c.Constructors = append(c.Constructors, goName)
|
||||
g.classes[classKey] = c
|
||||
|
||||
tb.Interface = c.Name
|
||||
tb.InterfaceFunc = c.Func
|
||||
case tl.CategoryFunction:
|
||||
// Just creating new bare type.
|
||||
tb.Method = tb.Name
|
||||
tb.Name += "Request"
|
||||
}
|
||||
g.types[typeKey] = tb
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/gotd/getdoc"
|
||||
)
|
||||
|
||||
// errCheckDef is helper for checking errors.
|
||||
type errCheckDef struct {
|
||||
// Name of check without "Is" prefix.
|
||||
Name string
|
||||
// Type of error.
|
||||
Type string
|
||||
}
|
||||
|
||||
func (Generator) errDef(err getdoc.Error) errCheckDef {
|
||||
var parts []string
|
||||
for _, p := range strings.Split(err.Type, "_") {
|
||||
switch p {
|
||||
case "X", "*", "%d":
|
||||
continue
|
||||
default:
|
||||
p = strings.ReplaceAll(p, "%d", "")
|
||||
parts = append(parts, p)
|
||||
}
|
||||
}
|
||||
var partsLower []string
|
||||
for _, p := range parts {
|
||||
partsLower = append(partsLower, strings.ToLower(p))
|
||||
}
|
||||
return errCheckDef{
|
||||
Name: pascalWords(partsLower),
|
||||
Type: strings.Join(parts, "_"),
|
||||
}
|
||||
}
|
||||
|
||||
// makeErrors created go definitions for possible errors.
|
||||
func (g *Generator) makeErrors() {
|
||||
if g.doc == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// For each unique error Type, create error check definition.
|
||||
// Like IsNeedMigration(err) function.
|
||||
seen := make(map[string]struct{})
|
||||
for _, m := range g.structs {
|
||||
for _, e := range m.Errors {
|
||||
d := g.errDef(e)
|
||||
|
||||
if _, ok := seen[d.Type]; ok {
|
||||
continue
|
||||
}
|
||||
seen[d.Type] = struct{}{}
|
||||
|
||||
g.errorChecks = append(g.errorChecks, d)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure error order.
|
||||
sort.SliceStable(g.errorChecks, func(i, j int) bool {
|
||||
a, b := g.errorChecks[i], g.errorChecks[j]
|
||||
return a.Type < b.Type
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"github.com/gotd/tl"
|
||||
)
|
||||
|
||||
const flagsType = "bin.Fields"
|
||||
|
||||
// fieldDef represents structDef field.
|
||||
type fieldDef struct {
|
||||
// Name of field. Should be in camel case.
|
||||
Name string
|
||||
// Comment for field. Currently only one-line.
|
||||
Comment []string
|
||||
// Type is go type for field.
|
||||
Type string
|
||||
// Func is name for bin.* functions, e.g. String will render
|
||||
// to bin.Buffer.String and bin.Buffer.PutString.
|
||||
Func string
|
||||
// Encoder denotes whether fieldDef implements bin.Encoder and bin.Decoder.
|
||||
Encoder bool
|
||||
// RawName is raw name from TL Schema.
|
||||
RawName string
|
||||
// RawType is type from TL Schema.
|
||||
RawType string
|
||||
// BareVector denotes whether fieldDef TL type is a bare vector.
|
||||
BareVector bool
|
||||
// Vector denotes whether fieldDef TL type is vector.
|
||||
Vector bool
|
||||
// DoubleVector denotes whether fieldDef TL type is vector of vectors.
|
||||
DoubleVector bool
|
||||
// Slice denotes whether slice should be used for this field.
|
||||
Slice bool
|
||||
// DoubleSlice denotes whether double slicing should be used, e.g. [][]bytes.
|
||||
DoubleSlice bool
|
||||
// BareEncoder denotes whether field type should use bare encoder.
|
||||
BareEncoder bool
|
||||
// Interface is name of interface type if field type is constructor.
|
||||
Interface string
|
||||
// InterfaceFunc is encoding func postfix if Interface is set.
|
||||
InterfaceFunc string
|
||||
// Conditional denotes whether fieldDef is conditional.
|
||||
Conditional bool
|
||||
// ConditionalField if name of bitset param.
|
||||
ConditionalField string
|
||||
// ConditionalIndex is fieldDef bit in ConditionalField.
|
||||
ConditionalIndex int
|
||||
// ConditionalBool denotes whether value is fully encoded in ConditionalField as bit.
|
||||
ConditionalBool bool
|
||||
// Links from documentation
|
||||
Links []string
|
||||
}
|
||||
|
||||
type fieldPair struct {
|
||||
L, R fieldDef
|
||||
}
|
||||
|
||||
func (f fieldDef) String() string {
|
||||
b := strings.Builder{}
|
||||
b.Grow(len(f.Name) + len(f.Type) + 16)
|
||||
b.WriteString(f.Name)
|
||||
b.WriteByte(' ')
|
||||
|
||||
switch {
|
||||
case f.Slice || f.Vector:
|
||||
b.WriteString("[]")
|
||||
case f.DoubleSlice || f.DoubleVector:
|
||||
b.WriteString("[][]")
|
||||
}
|
||||
b.WriteString(f.Type)
|
||||
switch {
|
||||
case f.Conditional:
|
||||
b.WriteString("?")
|
||||
case f.ConditionalBool:
|
||||
b.WriteString("?true")
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (f fieldDef) SameType(b fieldDef) bool {
|
||||
return f.Type == b.Type &&
|
||||
f.Func == b.Func &&
|
||||
f.Vector == b.Vector &&
|
||||
f.DoubleVector == b.DoubleVector &&
|
||||
f.Slice == b.Slice &&
|
||||
f.DoubleSlice == b.DoubleSlice
|
||||
}
|
||||
|
||||
func (f fieldDef) EqualAsField(b fieldDef) bool {
|
||||
return f.Name == b.Name &&
|
||||
f.SameType(b) &&
|
||||
f.Interface == b.Interface &&
|
||||
f.InterfaceFunc == b.InterfaceFunc &&
|
||||
f.Conditional == b.Conditional &&
|
||||
f.ConditionalBool == b.ConditionalBool
|
||||
}
|
||||
|
||||
// nolint:gocognit,gocyclo
|
||||
//
|
||||
// TODO(ernado) Split into multiple sections: base type, encoder and conditional.
|
||||
func (g *Generator) makeField(param tl.Parameter, annotations []tl.Annotation) (fieldDef, error) {
|
||||
const bareVectorName = "vector"
|
||||
|
||||
f := fieldDef{
|
||||
Name: pascal(param.Name),
|
||||
RawName: param.Name,
|
||||
RawType: param.Type.String(),
|
||||
}
|
||||
// Unwrapping up to 2 levels of vectors.
|
||||
baseType := param.Type
|
||||
for _, a := range annotations {
|
||||
if a.Name == param.Name {
|
||||
if a.Value != "" {
|
||||
f.Comment = []string{a.Value}
|
||||
}
|
||||
}
|
||||
}
|
||||
if baseType.Name == bareVectorName || baseType.Name == "Vector" {
|
||||
f.BareVector = baseType.Name == bareVectorName
|
||||
baseType = *baseType.GenericArg
|
||||
f.Vector = true
|
||||
f.Slice = true
|
||||
f.BareVector = f.BareVector || baseType.Percent
|
||||
}
|
||||
if baseType.Name == bareVectorName || baseType.Name == "Vector" {
|
||||
baseType = *baseType.GenericArg
|
||||
f.DoubleSlice = true
|
||||
f.DoubleVector = true
|
||||
}
|
||||
if param.Flags {
|
||||
f.Type = flagsType
|
||||
}
|
||||
f.Type = baseType.Name
|
||||
switch baseType.Name {
|
||||
case "int":
|
||||
f.Func = "Int"
|
||||
case "int32":
|
||||
f.Func = "Int32"
|
||||
case "int128":
|
||||
f.Func = "Int128"
|
||||
f.Type = "bin.Int128"
|
||||
case "int256":
|
||||
f.Func = "Int256"
|
||||
f.Type = "bin.Int256"
|
||||
case "double":
|
||||
f.Func = "Double"
|
||||
f.Type = "float64"
|
||||
case "int53":
|
||||
f.Func = "Int53"
|
||||
f.Type = "int64"
|
||||
case "long", "int64":
|
||||
f.Func = "Long"
|
||||
f.Type = "int64"
|
||||
case "string":
|
||||
f.Func = "String"
|
||||
case "Bool", "bool", "true", "false":
|
||||
f.Func = "Bool"
|
||||
f.Type = "bool"
|
||||
case "bytes":
|
||||
f.Func = "Bytes"
|
||||
f.Type = "byte"
|
||||
if f.Slice {
|
||||
f.DoubleSlice = true
|
||||
}
|
||||
f.Slice = true
|
||||
default:
|
||||
f.Encoder = true
|
||||
f.BareEncoder = f.BareVector
|
||||
|
||||
if param.Flags {
|
||||
f.Type = flagsType
|
||||
break
|
||||
}
|
||||
|
||||
if baseType.Bare {
|
||||
// Using exact go type for bare types.
|
||||
tn := strings.TrimPrefix(baseType.String(), "%")
|
||||
t, ok := g.types[tn]
|
||||
if !ok {
|
||||
return fieldDef{}, errors.Errorf("types[%s] not found", baseType)
|
||||
}
|
||||
f.Type = t.Name
|
||||
} else {
|
||||
// Type is generic.
|
||||
t, ok := g.classes[baseType.String()]
|
||||
if param.Type.GenericRef {
|
||||
ok = true
|
||||
t.RawType = param.Type.Name
|
||||
t.Name = "bin.Object"
|
||||
}
|
||||
if !ok {
|
||||
return fieldDef{}, errors.Errorf("classes[%s] not found", baseType)
|
||||
}
|
||||
f.Type = t.Name
|
||||
if !baseType.Percent && t.Singular && !param.Type.GenericRef {
|
||||
f.BareEncoder = false
|
||||
}
|
||||
if !t.Singular && !param.Type.GenericRef {
|
||||
f.Interface = t.Name
|
||||
f.InterfaceFunc = t.Func
|
||||
}
|
||||
}
|
||||
}
|
||||
if flag := param.Flag; flag != nil {
|
||||
f.Conditional = true
|
||||
f.ConditionalIndex = flag.Index
|
||||
f.ConditionalField = pascal(flag.Name)
|
||||
if f.Type == "bool" && !f.Vector && baseType.Name == "true" {
|
||||
f.ConditionalBool = true
|
||||
}
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type constructorMapping struct {
|
||||
// Name is go name of interface or struct.
|
||||
Name string
|
||||
// Constructor is go name of mapped constructor.
|
||||
// May be empty.
|
||||
Constructor string
|
||||
// Concrete is flag which is true when Name address a struct, not interface.
|
||||
Concrete bool
|
||||
// MapperName is name of mapper which created this sub.
|
||||
MapperName string
|
||||
// Fields is slice of field mappings from this struct to target.
|
||||
Fields []fieldPair
|
||||
}
|
||||
|
||||
// interfaceDef represents generic interface, type which has multiple constructors.
|
||||
type interfaceDef struct {
|
||||
// Name of interface.
|
||||
Name string
|
||||
// RawType is raw type from TL schema.
|
||||
RawType string
|
||||
|
||||
// Fields, common for every constructor.
|
||||
SharedFields map[string][]fieldDef
|
||||
// Sub interfaces of this TL class.
|
||||
// Need to create As${sub.MapperName}() ${sub.Name} mappers.
|
||||
Mappings []constructorMapping
|
||||
// Constructors of interface.
|
||||
Constructors []structDef
|
||||
Func string
|
||||
Namespace []string
|
||||
BaseName string
|
||||
URL string
|
||||
}
|
||||
|
||||
func interfaceHasOneSuffix(suffixes ...string) func(s structDef) bool {
|
||||
return func(s structDef) bool {
|
||||
for _, suffix := range suffixes {
|
||||
if strings.HasSuffix(s.Name, suffix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func makeMapping(def *interfaceDef, name string, emptyFilter func(s structDef) bool) {
|
||||
var (
|
||||
// Fields, common for every non-empty constructor.
|
||||
nonEmptyFields []fieldDef
|
||||
// Non-empty constructors.
|
||||
nonEmptyConstructors []structDef
|
||||
// Index of optional empty constructor.
|
||||
emptyIdx = -1
|
||||
)
|
||||
for _, s := range def.Constructors {
|
||||
if emptyFilter(s) {
|
||||
emptyIdx = len(def.Constructors)
|
||||
} else {
|
||||
nonEmptyFields = intersectFields(nonEmptyFields, s.Fields)
|
||||
nonEmptyConstructors = append(nonEmptyConstructors, s)
|
||||
}
|
||||
}
|
||||
|
||||
// If have at least one empty constructor.
|
||||
hasEmpty := emptyIdx >= 0
|
||||
|
||||
// If all non-empty constructors have common fields.
|
||||
nonEmptyHasCommonFields := len(nonEmptyFields) > 0
|
||||
|
||||
if hasEmpty && nonEmptyHasCommonFields && len(nonEmptyConstructors) > 0 {
|
||||
def.SharedFields[name] = nonEmptyFields
|
||||
|
||||
// If there are only one non-empty constructor, so we use concrete type.
|
||||
concrete := len(nonEmptyConstructors) < 2
|
||||
goName := name + strings.TrimSuffix(def.Name, "Class")
|
||||
if concrete {
|
||||
goName = nonEmptyConstructors[0].Name
|
||||
}
|
||||
|
||||
mapping := constructorMapping{
|
||||
Name: goName,
|
||||
Concrete: concrete,
|
||||
MapperName: name,
|
||||
}
|
||||
def.Mappings = append(def.Mappings, mapping)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) collectMappings(def *interfaceDef) {
|
||||
for _, s := range g.structs {
|
||||
// Filter constructors from same Class and empty constructors.
|
||||
if s.Interface == def.Name || len(s.Fields) < 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, constructor := range def.Constructors {
|
||||
// Filter constructors which have not similar name.
|
||||
if !strings.HasPrefix(s.Name, "Input") || !strings.Contains(s.Name, constructor.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
mapping, ok := mappableFields(constructor, s)
|
||||
// Filter constructors which we can't fill completely.
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
def.Mappings = append(def.Mappings, mapping)
|
||||
}
|
||||
}
|
||||
|
||||
emptyAnnotations := []struct {
|
||||
name string
|
||||
filter func(s structDef) bool
|
||||
}{
|
||||
{"NotEmpty", interfaceHasOneSuffix("Empty")},
|
||||
{"Modified", interfaceHasOneSuffix("NotModified")},
|
||||
{"Available", interfaceHasOneSuffix("Unavailable")},
|
||||
{"NotForbidden", interfaceHasOneSuffix("Forbidden")},
|
||||
{"Full", interfaceHasOneSuffix("Empty", "NotModified", "Forbidden")},
|
||||
}
|
||||
for _, annotation := range emptyAnnotations {
|
||||
// Full annotation is necessary only if there are more than two empty annotations.
|
||||
if annotation.name == "Full" && len(def.SharedFields) <= 2 {
|
||||
continue
|
||||
}
|
||||
makeMapping(def, annotation.name, annotation.filter)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) makeInterfaces() {
|
||||
// Make interfaces for classes.
|
||||
for _, c := range g.classes {
|
||||
if c.Singular {
|
||||
continue
|
||||
}
|
||||
def := interfaceDef{
|
||||
Name: c.Name,
|
||||
Namespace: c.Namespace,
|
||||
Func: c.Func,
|
||||
BaseName: c.BaseName,
|
||||
RawType: c.RawType,
|
||||
SharedFields: map[string][]fieldDef{},
|
||||
URL: g.docURL("type", c.RawType),
|
||||
}
|
||||
|
||||
for _, s := range g.structs {
|
||||
if s.Interface != def.Name {
|
||||
continue
|
||||
}
|
||||
|
||||
def.SharedFields["Common"] = intersectFields(def.SharedFields["Common"], s.Fields)
|
||||
def.Constructors = append(def.Constructors, s)
|
||||
}
|
||||
g.collectMappings(&def)
|
||||
|
||||
g.interfaces = append(g.interfaces, def)
|
||||
g.mappings[def.Name] = append(g.mappings[def.Name], def.Mappings...)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"github.com/gotd/getdoc"
|
||||
)
|
||||
|
||||
// structDef represents go structure definition.
|
||||
type structDef struct {
|
||||
// Name of struct, just like that: `type Name struct {`.
|
||||
Name string
|
||||
// Comment for struct, in one line.
|
||||
Comment string
|
||||
// Receiver name. E.g. "m" for Message.
|
||||
Receiver string
|
||||
// HexID is hex-encoded id, like 29bacabb.
|
||||
HexID string
|
||||
// BufArg is name of Encode and Decode argument of bin.Buffer type
|
||||
// that is used in those functions.
|
||||
//
|
||||
// Should not equal to Name.
|
||||
BufArg string
|
||||
// RawType is type name from TL schema, like authPassword#29bacabb.
|
||||
RawType string
|
||||
// RawName is type name from TL schema without HexID (CRC code), like authPassword.
|
||||
RawName string
|
||||
|
||||
// Interface refers to interface of generic type.
|
||||
Interface string
|
||||
InterfaceFunc string
|
||||
|
||||
// Method name if function definition.
|
||||
Method string
|
||||
// Result type name.
|
||||
Result string
|
||||
// ResultSingular denotes whether Result is singular type an can be used
|
||||
// directly.
|
||||
ResultSingular bool
|
||||
// ResultBaseName is BaseName of result interface.
|
||||
ResultBaseName string
|
||||
ResultFunc string
|
||||
ResultVector bool
|
||||
|
||||
UnpackParameters bool
|
||||
Vector bool
|
||||
// Fields of structure.
|
||||
Fields []fieldDef
|
||||
// Tuples of Conditional fields.
|
||||
ConditionalTuples [32][]fieldDef
|
||||
|
||||
// Namespace for file structure generation.
|
||||
Namespace []string
|
||||
// BaseName for file structure generation.
|
||||
BaseName string
|
||||
|
||||
// URL to documentation.
|
||||
// Like https://core.telegram.org/method/account.getPrivacy
|
||||
// Or https://core.telegram.org/constructor/account.privacyRules
|
||||
URL string
|
||||
// Docs is comments from documentation.
|
||||
Docs []string
|
||||
// Links from documentation
|
||||
Links []string
|
||||
// BotCanUse denotes whether method can be used by bots.
|
||||
BotCanUse bool
|
||||
// Errors is list of possible errors.
|
||||
Errors []getdoc.Error
|
||||
}
|
||||
|
||||
func (s *structDef) fillFromClass(class classBinding) {
|
||||
s.Result = class.Name
|
||||
s.ResultSingular = class.Singular
|
||||
s.ResultBaseName = class.BaseName
|
||||
s.ResultFunc = class.Func
|
||||
s.ResultVector = class.Vector
|
||||
}
|
||||
|
||||
type bindingDef struct {
|
||||
HexID string // id in hex
|
||||
Raw string // raw tl type
|
||||
Name string // go type
|
||||
}
|
||||
|
||||
func (g *Generator) docStruct(k string) getdoc.Constructor {
|
||||
if g.doc == nil {
|
||||
return getdoc.Constructor{}
|
||||
}
|
||||
return g.doc.Constructors[k]
|
||||
}
|
||||
|
||||
func (g *Generator) docMethod(k string) getdoc.Method {
|
||||
if g.doc == nil {
|
||||
return getdoc.Method{}
|
||||
}
|
||||
return g.doc.Methods[k]
|
||||
}
|
||||
|
||||
// makeStructures generates go structure definition representations.
|
||||
//
|
||||
// nolint:gocognit,gocyclo // TODO(ernado): simplify
|
||||
func (g *Generator) makeStructures() error {
|
||||
for _, sd := range g.schema.Definitions {
|
||||
var (
|
||||
d = sd.Definition
|
||||
typeKey = definitionType(d)
|
||||
docStruct = g.docStruct(typeKey)
|
||||
docMethod = g.docMethod(typeKey)
|
||||
)
|
||||
t, ok := g.types[typeKey]
|
||||
if !ok {
|
||||
return errors.Errorf("find type binding for %q", typeKey)
|
||||
}
|
||||
s := structDef{
|
||||
Namespace: t.Namespace,
|
||||
Name: t.Name,
|
||||
BaseName: d.Name,
|
||||
|
||||
HexID: fmt.Sprintf("%x", d.ID),
|
||||
BufArg: "b",
|
||||
RawType: fmt.Sprintf("%s#%x", typeKey, d.ID),
|
||||
RawName: typeKey,
|
||||
|
||||
Interface: t.Interface,
|
||||
InterfaceFunc: t.InterfaceFunc,
|
||||
|
||||
Method: t.Method,
|
||||
Docs: docStruct.Description,
|
||||
Links: docStruct.Links,
|
||||
}
|
||||
if t.Method != "" {
|
||||
s.Docs = docMethod.Description
|
||||
s.Links = docMethod.Links
|
||||
s.BotCanUse = docMethod.BotCanUse
|
||||
for _, e := range docMethod.Errors {
|
||||
if strings.Contains(e.Type, ",") {
|
||||
// HACK(ernado): fix in getdoc
|
||||
continue
|
||||
}
|
||||
s.Errors = append(s.Errors, e)
|
||||
}
|
||||
}
|
||||
if g.docBase != nil {
|
||||
// Assuming constructor by default.
|
||||
s.URL = g.docURL("constructor", typeKey)
|
||||
}
|
||||
s.Docs = splitLines(s.Docs, g.docLineLimit)
|
||||
|
||||
// Selecting receiver based on non-namespaced type.
|
||||
s.Receiver = strings.ToLower(d.Name[:1])
|
||||
if s.Receiver == "b" {
|
||||
// bin.Buffer argument collides with receiver.
|
||||
s.BufArg = "buf"
|
||||
}
|
||||
if strings.TrimSpace(s.Comment) == "" {
|
||||
// TODO(ernado): multi-line comments.
|
||||
s.Comment = fmt.Sprintf("%s represents TL type `%s`.", s.Name, s.RawType)
|
||||
}
|
||||
|
||||
allFieldRequired := true
|
||||
for _, param := range d.Params {
|
||||
f, err := g.makeField(param, sd.Annotations)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "make field %s", param.Name)
|
||||
}
|
||||
|
||||
f.Links = docStruct.Fields[param.Name].Links
|
||||
if t.Method != "" {
|
||||
f.Links = docMethod.Parameters[param.Name].Links
|
||||
}
|
||||
|
||||
if f.Conditional {
|
||||
if f.ConditionalIndex >= 32 || f.ConditionalIndex < 0 {
|
||||
return errors.Errorf("invalid conditional index %d", f.ConditionalIndex)
|
||||
}
|
||||
s.ConditionalTuples[f.ConditionalIndex] = append(s.ConditionalTuples[f.ConditionalIndex], f)
|
||||
allFieldRequired = false
|
||||
}
|
||||
|
||||
if len(f.Comment) < 1 || f.Comment[0] == "" {
|
||||
comment := docMethod.Parameters[param.Name].Description
|
||||
if strings.TrimSpace(comment) == "" {
|
||||
comment = docStruct.Fields[param.Name].Description
|
||||
}
|
||||
if strings.TrimSpace(comment) == "" {
|
||||
comment = fmt.Sprintf("%s field of %s.", f.Name, s.Name)
|
||||
}
|
||||
|
||||
f.Comment = []string{comment}
|
||||
}
|
||||
|
||||
f.Comment = splitLines(f.Comment, g.docLineLimit)
|
||||
s.Fields = append(s.Fields, f)
|
||||
}
|
||||
|
||||
if allFieldRequired && len(d.Params) < 2 {
|
||||
s.UnpackParameters = true
|
||||
}
|
||||
|
||||
if s.Method != "" && t.Class != "Ok" {
|
||||
// RPC call.
|
||||
class, ok := g.classes[t.Class]
|
||||
|
||||
switch {
|
||||
case !ok && strings.HasPrefix(t.Class, "Vector<"):
|
||||
var err error
|
||||
class, err = g.makeVector(t.Class)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fallthrough
|
||||
case ok:
|
||||
s.fillFromClass(class)
|
||||
s.URL = g.docURL("method", typeKey)
|
||||
default:
|
||||
// Not implemented.
|
||||
s.Method = ""
|
||||
}
|
||||
}
|
||||
|
||||
g.structs = append(g.structs, s)
|
||||
g.registry = append(g.registry, bindingDef{
|
||||
HexID: s.HexID,
|
||||
Raw: s.RawType,
|
||||
Name: s.Name,
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gotd/tl"
|
||||
)
|
||||
|
||||
func (g *Generator) makeVector(className string) (class classBinding, err error) {
|
||||
class, ok := g.classes[className]
|
||||
if ok {
|
||||
return class, nil
|
||||
}
|
||||
|
||||
elementName := strings.TrimPrefix(className[:len(className)-1], "Vector<")
|
||||
goElementName := g.classes[elementName].Name
|
||||
if goElementName == "" {
|
||||
goElementName = elementName
|
||||
}
|
||||
|
||||
f, err := g.makeField(tl.Parameter{
|
||||
Name: "Elems",
|
||||
Type: tl.Type{
|
||||
Name: "Vector",
|
||||
GenericArg: &tl.Type{
|
||||
Name: elementName,
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return class, err
|
||||
}
|
||||
f.Comment = []string{"Elements of " + className}
|
||||
|
||||
goName := strings.Title(goElementName) + "Vector"
|
||||
class = classBinding{
|
||||
Name: goName,
|
||||
Func: f.Type,
|
||||
Singular: true,
|
||||
Vector: true,
|
||||
}
|
||||
g.classes[className] = class
|
||||
|
||||
g.structs = append(g.structs, structDef{
|
||||
Name: goName,
|
||||
Receiver: "vec",
|
||||
BufArg: "b",
|
||||
RawType: className,
|
||||
Vector: true,
|
||||
Fields: []fieldDef{f},
|
||||
BaseName: goName,
|
||||
Comment: goName + " is a box for " + className,
|
||||
})
|
||||
|
||||
return class, nil
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/go-openapi/inflect"
|
||||
)
|
||||
|
||||
func pascalWords(words []string) string {
|
||||
for i, w := range words {
|
||||
upper := strings.ToUpper(w)
|
||||
if alias, ok := aliases[upper]; ok {
|
||||
words[i] = alias
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := acronyms[upper]; ok {
|
||||
words[i] = upper
|
||||
continue
|
||||
}
|
||||
|
||||
// check for acronym + any letter: IDs, IPs, UIDs
|
||||
if _, ok := acronyms[upper[:len(upper)-1]]; ok {
|
||||
words[i] = upper[:len(upper)-1] + strings.ToLower(upper[len(upper)-1:])
|
||||
continue
|
||||
}
|
||||
|
||||
words[i] = rules.Capitalize(w)
|
||||
}
|
||||
|
||||
return strings.Join(words, "")
|
||||
}
|
||||
|
||||
var (
|
||||
rules = ruleset()
|
||||
acronyms = make(map[string]struct{})
|
||||
aliases = make(map[string]string)
|
||||
)
|
||||
|
||||
// CodeMD5Test -> cODEmd5tEST
|
||||
|
||||
// splitByWords split name into words by separators and capital letters
|
||||
func splitByWords(s string) []string {
|
||||
if s == "" {
|
||||
return []string{s}
|
||||
}
|
||||
|
||||
if strings.ContainsAny(s, "_-") {
|
||||
return strings.FieldsFunc(s, func(r rune) bool {
|
||||
return r == '_' || r == '-'
|
||||
})
|
||||
}
|
||||
|
||||
words := make([]string, 0)
|
||||
word := make([]rune, 0, len(s))
|
||||
var prev rune
|
||||
|
||||
for i, current := range s {
|
||||
if i == 0 {
|
||||
prev = current
|
||||
continue
|
||||
}
|
||||
|
||||
switch {
|
||||
case unicode.IsNumber(prev) || unicode.IsNumber(current):
|
||||
word = append(word, prev)
|
||||
case unicode.IsUpper(prev) && unicode.IsLower(current): // Ab
|
||||
if len(word) != 0 {
|
||||
words = append(words, string(word))
|
||||
word = word[:0]
|
||||
}
|
||||
|
||||
word = append(word, prev)
|
||||
case unicode.IsLower(prev) && unicode.IsUpper(current): // aB
|
||||
words = append(words, string(append(word, prev)))
|
||||
word = word[:0]
|
||||
default:
|
||||
word = append(word, prev)
|
||||
}
|
||||
|
||||
prev = current
|
||||
}
|
||||
|
||||
words = append(words, string(append(word, prev)))
|
||||
|
||||
return words
|
||||
}
|
||||
|
||||
// pascal converts the given name into a PascalCase.
|
||||
//
|
||||
// user_info => UserInfo
|
||||
// full_name => FullName
|
||||
// user_id => UserID
|
||||
// full-admin => FullAdmin
|
||||
// cdnConfig => CDNConfig
|
||||
// cdn_1_config => CDN1Config
|
||||
func pascal(s string) string {
|
||||
words := splitByWords(s)
|
||||
return pascalWords(words)
|
||||
}
|
||||
|
||||
// camel converts the given name into a camelCase.
|
||||
//
|
||||
// user_info => userInfo
|
||||
// full_name => fullName
|
||||
// user_id => userID
|
||||
// full-admin => fullAdmin
|
||||
func camel(s string) string {
|
||||
words := splitByWords(s)
|
||||
if len(words) == 1 {
|
||||
return strings.ToLower(words[0])
|
||||
}
|
||||
return strings.ToLower(words[0]) + pascalWords(words[1:])
|
||||
}
|
||||
|
||||
func ruleset() *inflect.Ruleset {
|
||||
r := inflect.NewDefaultRuleset()
|
||||
// Add common initialisms from golint and more.
|
||||
//
|
||||
// You can commit this with following message:
|
||||
// chore(gen): update acronym list
|
||||
for _, w := range []string{
|
||||
"ACL", "API", "ASCII", "AWS", "CPU", "CSS", "DNS", "EOF", "GB", "GUID",
|
||||
"HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "KB", "LHS", "MAC", "MB",
|
||||
"QPS", "RAM", "RHS", "RPC", "SLA", "SMTP", "SQL", "SSH", "SSO", "TCP",
|
||||
"TLS", "TTL", "UDP", "UI", "UID", "URI", "URL", "UTF8", "UUID", "VM",
|
||||
"XML", "XMPP", "XSRF", "XSS", "SMS", "CDN", "TCP", "UDP", "DC", "PFS",
|
||||
"P2P", "SHA256", "SHA1", "MD5", "SRP", "2FA", "ISO",
|
||||
} {
|
||||
acronyms[w] = struct{}{}
|
||||
r.AddAcronym(w)
|
||||
}
|
||||
|
||||
aliases = map[string]string{
|
||||
"TCPO": "TCPObfuscated",
|
||||
"SMSJOBS": "SMSJobs",
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package gen
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPascal(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "Id",
|
||||
expected: "ID",
|
||||
},
|
||||
{
|
||||
name: "user_id",
|
||||
expected: "UserID",
|
||||
},
|
||||
{
|
||||
name: "cdnConfig",
|
||||
expected: "CDNConfig",
|
||||
},
|
||||
{
|
||||
name: "cdn_1_config",
|
||||
expected: "CDN1Config",
|
||||
},
|
||||
{
|
||||
name: "p2pB2B",
|
||||
expected: "P2PB2B",
|
||||
},
|
||||
{
|
||||
name: "md5Checksum",
|
||||
expected: "MD5Checksum",
|
||||
},
|
||||
{
|
||||
name: "user_ids",
|
||||
expected: "UserIDs",
|
||||
},
|
||||
{
|
||||
name: "UserIDs",
|
||||
expected: "UserIDs",
|
||||
},
|
||||
{
|
||||
name: "tcpo_only",
|
||||
expected: "TCPObfuscatedOnly",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
test := tt
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
res := pascal(test.name)
|
||||
if res != test.expected {
|
||||
t.Fatalf("mismatch; got: %s; expected: %s", res, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCamel(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "user_id",
|
||||
expected: "userID",
|
||||
},
|
||||
{
|
||||
name: "full_name",
|
||||
expected: "fullName",
|
||||
},
|
||||
{
|
||||
name: "full-admin",
|
||||
expected: "fullAdmin",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
test := tt
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
res := camel(test.name)
|
||||
if res != test.expected {
|
||||
t.Fatalf("mismatch; got: %s; expected: %s", res, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
var goKeywords = map[string]struct{}{
|
||||
// See https://golang.org/ref/spec#Keywords.
|
||||
"break": {},
|
||||
"default": {},
|
||||
"func": {},
|
||||
"interface": {},
|
||||
"select": {},
|
||||
"case": {},
|
||||
"defer": {},
|
||||
"go": {},
|
||||
"map": {},
|
||||
"struct": {},
|
||||
"chan": {},
|
||||
"else": {},
|
||||
"goto": {},
|
||||
"package": {},
|
||||
"switch": {},
|
||||
"const": {},
|
||||
"fallthrough": {},
|
||||
"if": {},
|
||||
"range": {},
|
||||
"type": {},
|
||||
"continue": {},
|
||||
"for": {},
|
||||
"import": {},
|
||||
"return": {},
|
||||
"var": {},
|
||||
|
||||
// Not really keyword, but unlikely to shadow.
|
||||
// See go/types/universe.go.
|
||||
"append": {},
|
||||
"cap": {},
|
||||
"close": {},
|
||||
"complex": {},
|
||||
"copy": {},
|
||||
"delete": {},
|
||||
"imag": {},
|
||||
"len": {},
|
||||
"make": {},
|
||||
"new": {},
|
||||
"panic": {},
|
||||
"print": {},
|
||||
"println": {},
|
||||
"real": {},
|
||||
"recover": {},
|
||||
}
|
||||
|
||||
// Funcs returns functions which used in templates.
|
||||
func Funcs() template.FuncMap {
|
||||
return template.FuncMap{
|
||||
"trim": strings.TrimSpace,
|
||||
"lower": strings.ToLower,
|
||||
"trimPrefix": strings.TrimPrefix,
|
||||
"trimSuffix": strings.TrimSuffix,
|
||||
"hasPrefix": strings.HasPrefix,
|
||||
"hasSuffix": strings.HasSuffix,
|
||||
"contains": strings.Contains,
|
||||
"hasField": hasField,
|
||||
"optionalField": optionalField,
|
||||
"mapCollectableFields": mapCollectableFields,
|
||||
"sortableFields": sortableFields,
|
||||
"generateSliceHelper": generateSliceHelper,
|
||||
"concat": func(args ...interface{}) []interface{} {
|
||||
return args
|
||||
},
|
||||
"add": func(x, y int) int {
|
||||
return x + y
|
||||
},
|
||||
"notEmpty": func(s string) bool {
|
||||
return strings.TrimSpace(s) != ""
|
||||
},
|
||||
"lowerGo": func(input string) string {
|
||||
lower := strings.ToLower(input)
|
||||
if _, ok := goKeywords[lower]; ok {
|
||||
return lower + "_"
|
||||
}
|
||||
return lower
|
||||
},
|
||||
"hasFlags": func(def structDef) bool {
|
||||
for _, field := range def.Fields {
|
||||
if field.Type == flagsType {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
|
||||
// Argument constructors
|
||||
"newStructConfig": newStructConfig,
|
||||
"newInterfaceConfig": newInterfaceConfig,
|
||||
}
|
||||
}
|
||||
|
||||
//go:embed _template/*.tmpl
|
||||
var templates embed.FS
|
||||
|
||||
// Template parses and returns vendored code generation templates.
|
||||
func Template() *template.Template {
|
||||
tmpl := template.New("templates").Funcs(Funcs())
|
||||
tmpl = template.Must(tmpl.ParseFS(templates, "_template/*.tmpl"))
|
||||
return tmpl
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/go-faster/errors"
|
||||
)
|
||||
|
||||
// config is input data for templates.
|
||||
type config struct {
|
||||
Layer int
|
||||
Flags GenerateFlags
|
||||
Package string
|
||||
Structs []structDef
|
||||
Interfaces []interfaceDef
|
||||
Mappings map[string][]constructorMapping
|
||||
Registry []bindingDef
|
||||
Errors []errCheckDef
|
||||
}
|
||||
|
||||
// FileSystem represents a directory of generated package.
|
||||
type FileSystem interface {
|
||||
WriteFile(baseName string, source []byte) error
|
||||
}
|
||||
|
||||
// outFileName returns file name of generated go source file based on namespace
|
||||
// and baseName in snake case.
|
||||
func outFileName(baseName string, namespace []string) string {
|
||||
var s strings.Builder
|
||||
s.WriteString("tl_")
|
||||
for _, ns := range namespace {
|
||||
s.WriteString(rules.Underscore(ns))
|
||||
s.WriteString("_")
|
||||
}
|
||||
s.WriteString(rules.Underscore(baseName))
|
||||
s.WriteString("_gen.go")
|
||||
return s.String()
|
||||
}
|
||||
|
||||
func (g *Generator) shouldGenerateClassifier() bool {
|
||||
for _, s := range g.structs {
|
||||
if s.Interface == "MessageClass" {
|
||||
return g.hasUpdateClass()
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *Generator) hasUpdateClass() bool {
|
||||
for _, s := range g.structs {
|
||||
if s.Interface == "UpdateClass" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type writer struct {
|
||||
pkg string
|
||||
fs FileSystem
|
||||
t *template.Template
|
||||
buf *bytes.Buffer
|
||||
wrote map[string]bool
|
||||
|
||||
wroteConstructors map[string]struct{}
|
||||
generateFlags GenerateFlags
|
||||
}
|
||||
|
||||
// Generate executes template to file using config.
|
||||
func (w *writer) Generate(templateName, fileName string, cfg config) error {
|
||||
if cfg.Package == "" {
|
||||
cfg.Package = w.pkg
|
||||
}
|
||||
if w.wrote[fileName] {
|
||||
return errors.Errorf("name collision (already wrote %s)", fileName)
|
||||
}
|
||||
|
||||
w.buf.Reset()
|
||||
if err := w.t.ExecuteTemplate(w.buf, templateName, cfg); err != nil {
|
||||
return errors.Wrapf(err, "execute template %s for %s", templateName, fileName)
|
||||
}
|
||||
if err := w.fs.WriteFile(fileName, w.buf.Bytes()); err != nil {
|
||||
_ = os.WriteFile(fileName+".dump", w.buf.Bytes(), 0600)
|
||||
return errors.Wrapf(err, "write file %s", fileName)
|
||||
}
|
||||
w.wrote[fileName] = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *writer) write(fileName string, cfg config) error {
|
||||
if err := w.Generate("main", fileName, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if w.generateFlags.Slices {
|
||||
name := strings.TrimSuffix(fileName, "_gen.go") + "_slices_gen.go"
|
||||
if err := w.Generate("slices", name, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteInterfaces writes interface definitions to corresponding files.
|
||||
func (w *writer) WriteInterfaces(interfaces []interfaceDef) error {
|
||||
for _, class := range interfaces {
|
||||
cfg := config{
|
||||
Package: w.pkg,
|
||||
Structs: class.Constructors,
|
||||
Interfaces: []interfaceDef{class},
|
||||
Flags: w.generateFlags,
|
||||
}
|
||||
for _, s := range cfg.Structs {
|
||||
w.wroteConstructors[s.Name] = struct{}{}
|
||||
}
|
||||
|
||||
name := outFileName(class.BaseName, class.Namespace)
|
||||
if err := w.write(name, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteStructs writes structure definitions to corresponding files.
|
||||
func (w *writer) WriteStructs(structs []structDef, mappings map[string][]constructorMapping) error {
|
||||
for _, s := range structs {
|
||||
if _, ok := w.wroteConstructors[s.Name]; ok {
|
||||
continue
|
||||
}
|
||||
cfg := config{
|
||||
Package: w.pkg,
|
||||
Structs: []structDef{s},
|
||||
Mappings: mappings,
|
||||
Flags: w.generateFlags,
|
||||
}
|
||||
name := outFileName(s.BaseName, s.Namespace)
|
||||
if w.wrote[name] {
|
||||
// Name collision.
|
||||
name = outFileName(s.BaseName+"_const", s.Namespace)
|
||||
}
|
||||
if err := w.write(name, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteSource writes generated definitions to fs.
|
||||
func (g *Generator) WriteSource(fs FileSystem, pkgName string, t *template.Template) error {
|
||||
w := &writer{
|
||||
pkg: pkgName,
|
||||
fs: fs,
|
||||
t: t,
|
||||
buf: new(bytes.Buffer),
|
||||
wrote: map[string]bool{},
|
||||
|
||||
wroteConstructors: map[string]struct{}{},
|
||||
generateFlags: g.generateFlags,
|
||||
}
|
||||
|
||||
if err := w.WriteInterfaces(g.interfaces); err != nil {
|
||||
return errors.Wrap(err, "interfaces")
|
||||
}
|
||||
if err := w.WriteStructs(g.structs, g.mappings); err != nil {
|
||||
return errors.Wrap(err, "structs")
|
||||
}
|
||||
if g.generateFlags.Server {
|
||||
if err := w.Generate("server", "tl_server_gen.go", config{
|
||||
Structs: g.structs,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if g.generateFlags.Handlers && g.hasUpdateClass() {
|
||||
if err := w.Generate("handlers", "tl_handlers_gen.go", config{
|
||||
Structs: g.structs,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if g.generateFlags.UpdatesClassifier && g.shouldGenerateClassifier() {
|
||||
if err := w.Generate("updates_classifier", "tl_updates_classifier_gen.go", config{
|
||||
Structs: g.structs,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
sort.SliceStable(g.interfaces, func(i, j int) bool {
|
||||
return g.interfaces[i].Name < g.interfaces[j].Name
|
||||
})
|
||||
cfg := config{
|
||||
Registry: g.registry,
|
||||
Interfaces: g.interfaces,
|
||||
Layer: g.schema.Layer,
|
||||
Errors: g.errorChecks,
|
||||
Flags: g.generateFlags,
|
||||
}
|
||||
|
||||
if g.generateFlags.Registry {
|
||||
if err := w.Generate("registry", "tl_registry_gen.go", cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if g.generateFlags.Client {
|
||||
if err := w.Generate("client", "tl_client_gen.go", cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(cfg.Errors) > 0 {
|
||||
if err := w.Generate("errors", "tl_errors_gen.go", cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user