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 SecureValue struct {
Flags bin .Fields
Type SecureValueTypeClass
Data SecureData
FrontSide SecureFileClass
ReverseSide SecureFileClass
Selfie SecureFileClass
Translation []SecureFileClass
Files []SecureFileClass
PlainData SecurePlainDataClass
Hash []byte
}
const SecureValueTypeID = 0x187fa0ca
var (
_ bin .Encoder = &SecureValue {}
_ bin .Decoder = &SecureValue {}
_ bin .BareEncoder = &SecureValue {}
_ bin .BareDecoder = &SecureValue {}
)
func (s *SecureValue ) Zero () bool {
if s == nil {
return true
}
if !(s .Flags .Zero ()) {
return false
}
if !(s .Type == nil ) {
return false
}
if !(s .Data .Zero ()) {
return false
}
if !(s .FrontSide == nil ) {
return false
}
if !(s .ReverseSide == nil ) {
return false
}
if !(s .Selfie == nil ) {
return false
}
if !(s .Translation == nil ) {
return false
}
if !(s .Files == nil ) {
return false
}
if !(s .PlainData == nil ) {
return false
}
if !(s .Hash == nil ) {
return false
}
return true
}
func (s *SecureValue ) String () string {
if s == nil {
return "SecureValue(nil)"
}
type Alias SecureValue
return fmt .Sprintf ("SecureValue%+v" , Alias (*s ))
}
func (s *SecureValue ) FillFrom (from interface {
GetType () (value SecureValueTypeClass )
GetData () (value SecureData , ok bool )
GetFrontSide () (value SecureFileClass , ok bool )
GetReverseSide () (value SecureFileClass , ok bool )
GetSelfie () (value SecureFileClass , ok bool )
GetTranslation () (value []SecureFileClass , ok bool )
GetFiles () (value []SecureFileClass , ok bool )
GetPlainData () (value SecurePlainDataClass , ok bool )
GetHash () (value []byte )
}) {
s .Type = from .GetType ()
if val , ok := from .GetData (); ok {
s .Data = val
}
if val , ok := from .GetFrontSide (); ok {
s .FrontSide = val
}
if val , ok := from .GetReverseSide (); ok {
s .ReverseSide = val
}
if val , ok := from .GetSelfie (); ok {
s .Selfie = val
}
if val , ok := from .GetTranslation (); ok {
s .Translation = val
}
if val , ok := from .GetFiles (); ok {
s .Files = val
}
if val , ok := from .GetPlainData (); ok {
s .PlainData = val
}
s .Hash = from .GetHash ()
}
func (*SecureValue ) TypeID () uint32 {
return SecureValueTypeID
}
func (*SecureValue ) TypeName () string {
return "secureValue"
}
func (s *SecureValue ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "secureValue" ,
ID : SecureValueTypeID ,
}
if s == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Type" ,
SchemaName : "type" ,
},
{
Name : "Data" ,
SchemaName : "data" ,
Null : !s .Flags .Has (0 ),
},
{
Name : "FrontSide" ,
SchemaName : "front_side" ,
Null : !s .Flags .Has (1 ),
},
{
Name : "ReverseSide" ,
SchemaName : "reverse_side" ,
Null : !s .Flags .Has (2 ),
},
{
Name : "Selfie" ,
SchemaName : "selfie" ,
Null : !s .Flags .Has (3 ),
},
{
Name : "Translation" ,
SchemaName : "translation" ,
Null : !s .Flags .Has (6 ),
},
{
Name : "Files" ,
SchemaName : "files" ,
Null : !s .Flags .Has (4 ),
},
{
Name : "PlainData" ,
SchemaName : "plain_data" ,
Null : !s .Flags .Has (5 ),
},
{
Name : "Hash" ,
SchemaName : "hash" ,
},
}
return typ
}
func (s *SecureValue ) SetFlags () {
if !(s .Data .Zero ()) {
s .Flags .Set (0 )
}
if !(s .FrontSide == nil ) {
s .Flags .Set (1 )
}
if !(s .ReverseSide == nil ) {
s .Flags .Set (2 )
}
if !(s .Selfie == nil ) {
s .Flags .Set (3 )
}
if !(s .Translation == nil ) {
s .Flags .Set (6 )
}
if !(s .Files == nil ) {
s .Flags .Set (4 )
}
if !(s .PlainData == nil ) {
s .Flags .Set (5 )
}
}
func (s *SecureValue ) Encode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode secureValue#187fa0ca as nil" )
}
b .PutID (SecureValueTypeID )
return s .EncodeBare (b )
}
func (s *SecureValue ) EncodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode secureValue#187fa0ca as nil" )
}
s .SetFlags ()
if err := s .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field flags: %w" , err )
}
if s .Type == nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field type is nil" )
}
if err := s .Type .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field type: %w" , err )
}
if s .Flags .Has (0 ) {
if err := s .Data .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field data: %w" , err )
}
}
if s .Flags .Has (1 ) {
if s .FrontSide == nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field front_side is nil" )
}
if err := s .FrontSide .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field front_side: %w" , err )
}
}
if s .Flags .Has (2 ) {
if s .ReverseSide == nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field reverse_side is nil" )
}
if err := s .ReverseSide .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field reverse_side: %w" , err )
}
}
if s .Flags .Has (3 ) {
if s .Selfie == nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field selfie is nil" )
}
if err := s .Selfie .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field selfie: %w" , err )
}
}
if s .Flags .Has (6 ) {
b .PutVectorHeader (len (s .Translation ))
for idx , v := range s .Translation {
if v == nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field translation element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field translation element with index %d: %w" , idx , err )
}
}
}
if s .Flags .Has (4 ) {
b .PutVectorHeader (len (s .Files ))
for idx , v := range s .Files {
if v == nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field files element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field files element with index %d: %w" , idx , err )
}
}
}
if s .Flags .Has (5 ) {
if s .PlainData == nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field plain_data is nil" )
}
if err := s .PlainData .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode secureValue#187fa0ca: field plain_data: %w" , err )
}
}
b .PutBytes (s .Hash )
return nil
}
func (s *SecureValue ) Decode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode secureValue#187fa0ca to nil" )
}
if err := b .ConsumeID (SecureValueTypeID ); err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: %w" , err )
}
return s .DecodeBare (b )
}
func (s *SecureValue ) DecodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode secureValue#187fa0ca to nil" )
}
{
if err := s .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field flags: %w" , err )
}
}
{
value , err := DecodeSecureValueType (b )
if err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field type: %w" , err )
}
s .Type = value
}
if s .Flags .Has (0 ) {
if err := s .Data .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field data: %w" , err )
}
}
if s .Flags .Has (1 ) {
value , err := DecodeSecureFile (b )
if err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field front_side: %w" , err )
}
s .FrontSide = value
}
if s .Flags .Has (2 ) {
value , err := DecodeSecureFile (b )
if err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field reverse_side: %w" , err )
}
s .ReverseSide = value
}
if s .Flags .Has (3 ) {
value , err := DecodeSecureFile (b )
if err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field selfie: %w" , err )
}
s .Selfie = value
}
if s .Flags .Has (6 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field translation: %w" , err )
}
if headerLen > 0 {
s .Translation = make ([]SecureFileClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeSecureFile (b )
if err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field translation: %w" , err )
}
s .Translation = append (s .Translation , value )
}
}
if s .Flags .Has (4 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field files: %w" , err )
}
if headerLen > 0 {
s .Files = make ([]SecureFileClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeSecureFile (b )
if err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field files: %w" , err )
}
s .Files = append (s .Files , value )
}
}
if s .Flags .Has (5 ) {
value , err := DecodeSecurePlainData (b )
if err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field plain_data: %w" , err )
}
s .PlainData = value
}
{
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode secureValue#187fa0ca: field hash: %w" , err )
}
s .Hash = value
}
return nil
}
func (s *SecureValue ) GetType () (value SecureValueTypeClass ) {
if s == nil {
return
}
return s .Type
}
func (s *SecureValue ) SetData (value SecureData ) {
s .Flags .Set (0 )
s .Data = value
}
func (s *SecureValue ) GetData () (value SecureData , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (0 ) {
return value , false
}
return s .Data , true
}
func (s *SecureValue ) SetFrontSide (value SecureFileClass ) {
s .Flags .Set (1 )
s .FrontSide = value
}
func (s *SecureValue ) GetFrontSide () (value SecureFileClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (1 ) {
return value , false
}
return s .FrontSide , true
}
func (s *SecureValue ) SetReverseSide (value SecureFileClass ) {
s .Flags .Set (2 )
s .ReverseSide = value
}
func (s *SecureValue ) GetReverseSide () (value SecureFileClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (2 ) {
return value , false
}
return s .ReverseSide , true
}
func (s *SecureValue ) SetSelfie (value SecureFileClass ) {
s .Flags .Set (3 )
s .Selfie = value
}
func (s *SecureValue ) GetSelfie () (value SecureFileClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (3 ) {
return value , false
}
return s .Selfie , true
}
func (s *SecureValue ) SetTranslation (value []SecureFileClass ) {
s .Flags .Set (6 )
s .Translation = value
}
func (s *SecureValue ) GetTranslation () (value []SecureFileClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (6 ) {
return value , false
}
return s .Translation , true
}
func (s *SecureValue ) SetFiles (value []SecureFileClass ) {
s .Flags .Set (4 )
s .Files = value
}
func (s *SecureValue ) GetFiles () (value []SecureFileClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (4 ) {
return value , false
}
return s .Files , true
}
func (s *SecureValue ) SetPlainData (value SecurePlainDataClass ) {
s .Flags .Set (5 )
s .PlainData = value
}
func (s *SecureValue ) GetPlainData () (value SecurePlainDataClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (5 ) {
return value , false
}
return s .PlainData , true
}
func (s *SecureValue ) GetHash () (value []byte ) {
if s == nil {
return
}
return s .Hash
}
func (s *SecureValue ) GetFrontSideAsNotEmpty () (*SecureFile , bool ) {
if value , ok := s .GetFrontSide (); ok {
return value .AsNotEmpty ()
}
return nil , false
}
func (s *SecureValue ) GetReverseSideAsNotEmpty () (*SecureFile , bool ) {
if value , ok := s .GetReverseSide (); ok {
return value .AsNotEmpty ()
}
return nil , false
}
func (s *SecureValue ) GetSelfieAsNotEmpty () (*SecureFile , bool ) {
if value , ok := s .GetSelfie (); ok {
return value .AsNotEmpty ()
}
return nil , false
}
func (s *SecureValue ) MapTranslation () (value SecureFileClassArray , ok bool ) {
if !s .Flags .Has (6 ) {
return value , false
}
return SecureFileClassArray (s .Translation ), true
}
func (s *SecureValue ) MapFiles () (value SecureFileClassArray , ok bool ) {
if !s .Flags .Has (4 ) {
return value , false
}
return SecureFileClassArray (s .Files ), true
}
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 .