-
Notifications
You must be signed in to change notification settings - Fork 2
/
cd.myType.go
133 lines (113 loc) · 3.21 KB
/
cd.myType.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2022 V Kontakte LLC
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// Code generated by vktl/cmd/tlgen2; DO NOT EDIT.
package tlCdMyType
import (
"github.com/vkcom/tl/internal/tlcodegen/test/gen/goldmaster/internal"
"github.com/vkcom/tl/pkg/basictl"
)
var _ = basictl.NatWrite
var _ = internal.ErrorInvalidEnumTag
type CdMyType struct {
X int32
}
func (CdMyType) TLName() string { return "cd.myType" }
func (CdMyType) TLTag() uint32 { return 0xeab6a6b4 }
func (item *CdMyType) Reset() {
item.X = 0
}
func (item *CdMyType) FillRandom(rg *basictl.RandGenerator) {
item.X = basictl.RandomInt(rg)
}
func (item *CdMyType) Read(w []byte) (_ []byte, err error) {
return basictl.IntRead(w, &item.X)
}
// This method is general version of Write, use it instead!
func (item *CdMyType) WriteGeneral(w []byte) (_ []byte, err error) {
return item.Write(w), nil
}
func (item *CdMyType) Write(w []byte) []byte {
w = basictl.IntWrite(w, item.X)
return w
}
func (item *CdMyType) ReadBoxed(w []byte) (_ []byte, err error) {
if w, err = basictl.NatReadExactTag(w, 0xeab6a6b4); err != nil {
return w, err
}
return item.Read(w)
}
// This method is general version of WriteBoxed, use it instead!
func (item *CdMyType) WriteBoxedGeneral(w []byte) (_ []byte, err error) {
return item.WriteBoxed(w), nil
}
func (item *CdMyType) WriteBoxed(w []byte) []byte {
w = basictl.NatWrite(w, 0xeab6a6b4)
return item.Write(w)
}
func (item CdMyType) String() string {
return string(item.WriteJSON(nil))
}
func (item *CdMyType) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer) error {
var propXPresented bool
if in != nil {
in.Delim('{')
if !in.Ok() {
return in.Error()
}
for !in.IsDelim('}') {
key := in.UnsafeFieldName(true)
in.WantColon()
switch key {
case "x":
if propXPresented {
return internal.ErrorInvalidJSONWithDuplicatingKeys("cd.myType", "x")
}
if err := internal.Json2ReadInt32(in, &item.X); err != nil {
return err
}
propXPresented = true
default:
return internal.ErrorInvalidJSONExcessElement("cd.myType", key)
}
in.WantComma()
}
in.Delim('}')
if !in.Ok() {
return in.Error()
}
}
if !propXPresented {
item.X = 0
}
return nil
}
// This method is general version of WriteJSON, use it instead!
func (item *CdMyType) WriteJSONGeneral(w []byte) (_ []byte, err error) {
return item.WriteJSONOpt(true, false, w), nil
}
func (item *CdMyType) WriteJSON(w []byte) []byte {
return item.WriteJSONOpt(true, false, w)
}
func (item *CdMyType) WriteJSONOpt(newTypeNames bool, short bool, w []byte) []byte {
w = append(w, '{')
backupIndexX := len(w)
w = basictl.JSONAddCommaIfNeeded(w)
w = append(w, `"x":`...)
w = basictl.JSONWriteInt32(w, item.X)
if (item.X != 0) == false {
w = w[:backupIndexX]
}
return append(w, '}')
}
func (item *CdMyType) MarshalJSON() ([]byte, error) {
return item.WriteJSON(nil), nil
}
func (item *CdMyType) UnmarshalJSON(b []byte) error {
if err := item.ReadJSON(true, &basictl.JsonLexer{Data: b}); err != nil {
return internal.ErrorInvalidJSON("cd.myType", err.Error())
}
return nil
}