package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type JSONNull struct {
}
const JSONNullTypeID = 0x3f6d7b68
func (j JSONNull ) construct () JSONValueClass { return &j }
var (
_ bin .Encoder = &JSONNull {}
_ bin .Decoder = &JSONNull {}
_ bin .BareEncoder = &JSONNull {}
_ bin .BareDecoder = &JSONNull {}
_ JSONValueClass = &JSONNull {}
)
func (j *JSONNull ) Zero () bool {
if j == nil {
return true
}
return true
}
func (j *JSONNull ) String () string {
if j == nil {
return "JSONNull(nil)"
}
type Alias JSONNull
return fmt .Sprintf ("JSONNull%+v" , Alias (*j ))
}
func (*JSONNull ) TypeID () uint32 {
return JSONNullTypeID
}
func (*JSONNull ) TypeName () string {
return "jsonNull"
}
func (j *JSONNull ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "jsonNull" ,
ID : JSONNullTypeID ,
}
if j == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {}
return typ
}
func (j *JSONNull ) Encode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonNull#3f6d7b68 as nil" )
}
b .PutID (JSONNullTypeID )
return j .EncodeBare (b )
}
func (j *JSONNull ) EncodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonNull#3f6d7b68 as nil" )
}
return nil
}
func (j *JSONNull ) Decode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonNull#3f6d7b68 to nil" )
}
if err := b .ConsumeID (JSONNullTypeID ); err != nil {
return fmt .Errorf ("unable to decode jsonNull#3f6d7b68: %w" , err )
}
return j .DecodeBare (b )
}
func (j *JSONNull ) DecodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonNull#3f6d7b68 to nil" )
}
return nil
}
type JSONBool struct {
Value bool
}
const JSONBoolTypeID = 0xc7345e6a
func (j JSONBool ) construct () JSONValueClass { return &j }
var (
_ bin .Encoder = &JSONBool {}
_ bin .Decoder = &JSONBool {}
_ bin .BareEncoder = &JSONBool {}
_ bin .BareDecoder = &JSONBool {}
_ JSONValueClass = &JSONBool {}
)
func (j *JSONBool ) Zero () bool {
if j == nil {
return true
}
if !(j .Value == false ) {
return false
}
return true
}
func (j *JSONBool ) String () string {
if j == nil {
return "JSONBool(nil)"
}
type Alias JSONBool
return fmt .Sprintf ("JSONBool%+v" , Alias (*j ))
}
func (j *JSONBool ) FillFrom (from interface {
GetValue () (value bool )
}) {
j .Value = from .GetValue ()
}
func (*JSONBool ) TypeID () uint32 {
return JSONBoolTypeID
}
func (*JSONBool ) TypeName () string {
return "jsonBool"
}
func (j *JSONBool ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "jsonBool" ,
ID : JSONBoolTypeID ,
}
if j == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Value" ,
SchemaName : "value" ,
},
}
return typ
}
func (j *JSONBool ) Encode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonBool#c7345e6a as nil" )
}
b .PutID (JSONBoolTypeID )
return j .EncodeBare (b )
}
func (j *JSONBool ) EncodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonBool#c7345e6a as nil" )
}
b .PutBool (j .Value )
return nil
}
func (j *JSONBool ) Decode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonBool#c7345e6a to nil" )
}
if err := b .ConsumeID (JSONBoolTypeID ); err != nil {
return fmt .Errorf ("unable to decode jsonBool#c7345e6a: %w" , err )
}
return j .DecodeBare (b )
}
func (j *JSONBool ) DecodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonBool#c7345e6a to nil" )
}
{
value , err := b .Bool ()
if err != nil {
return fmt .Errorf ("unable to decode jsonBool#c7345e6a: field value: %w" , err )
}
j .Value = value
}
return nil
}
func (j *JSONBool ) GetValue () (value bool ) {
if j == nil {
return
}
return j .Value
}
type JSONNumber struct {
Value float64
}
const JSONNumberTypeID = 0x2be0dfa4
func (j JSONNumber ) construct () JSONValueClass { return &j }
var (
_ bin .Encoder = &JSONNumber {}
_ bin .Decoder = &JSONNumber {}
_ bin .BareEncoder = &JSONNumber {}
_ bin .BareDecoder = &JSONNumber {}
_ JSONValueClass = &JSONNumber {}
)
func (j *JSONNumber ) Zero () bool {
if j == nil {
return true
}
if !(j .Value == 0 ) {
return false
}
return true
}
func (j *JSONNumber ) String () string {
if j == nil {
return "JSONNumber(nil)"
}
type Alias JSONNumber
return fmt .Sprintf ("JSONNumber%+v" , Alias (*j ))
}
func (j *JSONNumber ) FillFrom (from interface {
GetValue () (value float64 )
}) {
j .Value = from .GetValue ()
}
func (*JSONNumber ) TypeID () uint32 {
return JSONNumberTypeID
}
func (*JSONNumber ) TypeName () string {
return "jsonNumber"
}
func (j *JSONNumber ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "jsonNumber" ,
ID : JSONNumberTypeID ,
}
if j == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Value" ,
SchemaName : "value" ,
},
}
return typ
}
func (j *JSONNumber ) Encode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonNumber#2be0dfa4 as nil" )
}
b .PutID (JSONNumberTypeID )
return j .EncodeBare (b )
}
func (j *JSONNumber ) EncodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonNumber#2be0dfa4 as nil" )
}
b .PutDouble (j .Value )
return nil
}
func (j *JSONNumber ) Decode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonNumber#2be0dfa4 to nil" )
}
if err := b .ConsumeID (JSONNumberTypeID ); err != nil {
return fmt .Errorf ("unable to decode jsonNumber#2be0dfa4: %w" , err )
}
return j .DecodeBare (b )
}
func (j *JSONNumber ) DecodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonNumber#2be0dfa4 to nil" )
}
{
value , err := b .Double ()
if err != nil {
return fmt .Errorf ("unable to decode jsonNumber#2be0dfa4: field value: %w" , err )
}
j .Value = value
}
return nil
}
func (j *JSONNumber ) GetValue () (value float64 ) {
if j == nil {
return
}
return j .Value
}
type JSONString struct {
Value string
}
const JSONStringTypeID = 0xb71e767a
func (j JSONString ) construct () JSONValueClass { return &j }
var (
_ bin .Encoder = &JSONString {}
_ bin .Decoder = &JSONString {}
_ bin .BareEncoder = &JSONString {}
_ bin .BareDecoder = &JSONString {}
_ JSONValueClass = &JSONString {}
)
func (j *JSONString ) Zero () bool {
if j == nil {
return true
}
if !(j .Value == "" ) {
return false
}
return true
}
func (j *JSONString ) String () string {
if j == nil {
return "JSONString(nil)"
}
type Alias JSONString
return fmt .Sprintf ("JSONString%+v" , Alias (*j ))
}
func (j *JSONString ) FillFrom (from interface {
GetValue () (value string )
}) {
j .Value = from .GetValue ()
}
func (*JSONString ) TypeID () uint32 {
return JSONStringTypeID
}
func (*JSONString ) TypeName () string {
return "jsonString"
}
func (j *JSONString ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "jsonString" ,
ID : JSONStringTypeID ,
}
if j == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Value" ,
SchemaName : "value" ,
},
}
return typ
}
func (j *JSONString ) Encode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonString#b71e767a as nil" )
}
b .PutID (JSONStringTypeID )
return j .EncodeBare (b )
}
func (j *JSONString ) EncodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonString#b71e767a as nil" )
}
b .PutString (j .Value )
return nil
}
func (j *JSONString ) Decode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonString#b71e767a to nil" )
}
if err := b .ConsumeID (JSONStringTypeID ); err != nil {
return fmt .Errorf ("unable to decode jsonString#b71e767a: %w" , err )
}
return j .DecodeBare (b )
}
func (j *JSONString ) DecodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonString#b71e767a to nil" )
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode jsonString#b71e767a: field value: %w" , err )
}
j .Value = value
}
return nil
}
func (j *JSONString ) GetValue () (value string ) {
if j == nil {
return
}
return j .Value
}
type JSONArray struct {
Value []JSONValueClass
}
const JSONArrayTypeID = 0xf7444763
func (j JSONArray ) construct () JSONValueClass { return &j }
var (
_ bin .Encoder = &JSONArray {}
_ bin .Decoder = &JSONArray {}
_ bin .BareEncoder = &JSONArray {}
_ bin .BareDecoder = &JSONArray {}
_ JSONValueClass = &JSONArray {}
)
func (j *JSONArray ) Zero () bool {
if j == nil {
return true
}
if !(j .Value == nil ) {
return false
}
return true
}
func (j *JSONArray ) String () string {
if j == nil {
return "JSONArray(nil)"
}
type Alias JSONArray
return fmt .Sprintf ("JSONArray%+v" , Alias (*j ))
}
func (j *JSONArray ) FillFrom (from interface {
GetValue () (value []JSONValueClass )
}) {
j .Value = from .GetValue ()
}
func (*JSONArray ) TypeID () uint32 {
return JSONArrayTypeID
}
func (*JSONArray ) TypeName () string {
return "jsonArray"
}
func (j *JSONArray ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "jsonArray" ,
ID : JSONArrayTypeID ,
}
if j == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Value" ,
SchemaName : "value" ,
},
}
return typ
}
func (j *JSONArray ) Encode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonArray#f7444763 as nil" )
}
b .PutID (JSONArrayTypeID )
return j .EncodeBare (b )
}
func (j *JSONArray ) EncodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonArray#f7444763 as nil" )
}
b .PutVectorHeader (len (j .Value ))
for idx , v := range j .Value {
if v == nil {
return fmt .Errorf ("unable to encode jsonArray#f7444763: field value element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode jsonArray#f7444763: field value element with index %d: %w" , idx , err )
}
}
return nil
}
func (j *JSONArray ) Decode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonArray#f7444763 to nil" )
}
if err := b .ConsumeID (JSONArrayTypeID ); err != nil {
return fmt .Errorf ("unable to decode jsonArray#f7444763: %w" , err )
}
return j .DecodeBare (b )
}
func (j *JSONArray ) DecodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonArray#f7444763 to nil" )
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode jsonArray#f7444763: field value: %w" , err )
}
if headerLen > 0 {
j .Value = make ([]JSONValueClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeJSONValue (b )
if err != nil {
return fmt .Errorf ("unable to decode jsonArray#f7444763: field value: %w" , err )
}
j .Value = append (j .Value , value )
}
}
return nil
}
func (j *JSONArray ) GetValue () (value []JSONValueClass ) {
if j == nil {
return
}
return j .Value
}
func (j *JSONArray ) MapValue () (value JSONValueClassArray ) {
return JSONValueClassArray (j .Value )
}
type JSONObject struct {
Value []JSONObjectValue
}
const JSONObjectTypeID = 0x99c1d49d
func (j JSONObject ) construct () JSONValueClass { return &j }
var (
_ bin .Encoder = &JSONObject {}
_ bin .Decoder = &JSONObject {}
_ bin .BareEncoder = &JSONObject {}
_ bin .BareDecoder = &JSONObject {}
_ JSONValueClass = &JSONObject {}
)
func (j *JSONObject ) Zero () bool {
if j == nil {
return true
}
if !(j .Value == nil ) {
return false
}
return true
}
func (j *JSONObject ) String () string {
if j == nil {
return "JSONObject(nil)"
}
type Alias JSONObject
return fmt .Sprintf ("JSONObject%+v" , Alias (*j ))
}
func (j *JSONObject ) FillFrom (from interface {
GetValue () (value []JSONObjectValue )
}) {
j .Value = from .GetValue ()
}
func (*JSONObject ) TypeID () uint32 {
return JSONObjectTypeID
}
func (*JSONObject ) TypeName () string {
return "jsonObject"
}
func (j *JSONObject ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "jsonObject" ,
ID : JSONObjectTypeID ,
}
if j == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Value" ,
SchemaName : "value" ,
},
}
return typ
}
func (j *JSONObject ) Encode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonObject#99c1d49d as nil" )
}
b .PutID (JSONObjectTypeID )
return j .EncodeBare (b )
}
func (j *JSONObject ) EncodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't encode jsonObject#99c1d49d as nil" )
}
b .PutVectorHeader (len (j .Value ))
for idx , v := range j .Value {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode jsonObject#99c1d49d: field value element with index %d: %w" , idx , err )
}
}
return nil
}
func (j *JSONObject ) Decode (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonObject#99c1d49d to nil" )
}
if err := b .ConsumeID (JSONObjectTypeID ); err != nil {
return fmt .Errorf ("unable to decode jsonObject#99c1d49d: %w" , err )
}
return j .DecodeBare (b )
}
func (j *JSONObject ) DecodeBare (b *bin .Buffer ) error {
if j == nil {
return fmt .Errorf ("can't decode jsonObject#99c1d49d to nil" )
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode jsonObject#99c1d49d: field value: %w" , err )
}
if headerLen > 0 {
j .Value = make ([]JSONObjectValue , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value JSONObjectValue
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode jsonObject#99c1d49d: field value: %w" , err )
}
j .Value = append (j .Value , value )
}
}
return nil
}
func (j *JSONObject ) GetValue () (value []JSONObjectValue ) {
if j == nil {
return
}
return j .Value
}
const JSONValueClassName = "JSONValue"
type JSONValueClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () JSONValueClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
}
func DecodeJSONValue (buf *bin .Buffer ) (JSONValueClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case JSONNullTypeID :
v := JSONNull {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode JSONValueClass: %w" , err )
}
return &v , nil
case JSONBoolTypeID :
v := JSONBool {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode JSONValueClass: %w" , err )
}
return &v , nil
case JSONNumberTypeID :
v := JSONNumber {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode JSONValueClass: %w" , err )
}
return &v , nil
case JSONStringTypeID :
v := JSONString {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode JSONValueClass: %w" , err )
}
return &v , nil
case JSONArrayTypeID :
v := JSONArray {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode JSONValueClass: %w" , err )
}
return &v , nil
case JSONObjectTypeID :
v := JSONObject {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode JSONValueClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode JSONValueClass: %w" , bin .NewUnexpectedID (id ))
}
}
type JSONValueBox struct {
JSONValue JSONValueClass
}
func (b *JSONValueBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode JSONValueBox to nil" )
}
v , err := DecodeJSONValue (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .JSONValue = v
return nil
}
func (b *JSONValueBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .JSONValue == nil {
return fmt .Errorf ("unable to encode JSONValueClass as nil" )
}
return b .JSONValue .Encode (buf )
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .