add list unmarshallers
This commit is contained in:
parent
cc7d37acc2
commit
ec36320d03
380
client/type.go
380
client/type.go
|
@ -5288,6 +5288,25 @@ func (*MessageSenders) GetType() string {
|
|||
return TypeMessageSenders
|
||||
}
|
||||
|
||||
func (messageSenders *MessageSenders) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
TotalCount int32 `json:"total_count"`
|
||||
Senders []json.RawMessage `json:"senders"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
messageSenders.TotalCount = tmp.TotalCount
|
||||
|
||||
fieldSenders, _ := UnmarshalListOfMessageSender(tmp.Senders)
|
||||
messageSenders.Senders = fieldSenders
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// The message was originally sent by a known user
|
||||
type MessageForwardOriginUser struct {
|
||||
meta
|
||||
|
@ -5489,6 +5508,31 @@ func (*MessageReplyInfo) GetType() string {
|
|||
return TypeMessageReplyInfo
|
||||
}
|
||||
|
||||
func (messageReplyInfo *MessageReplyInfo) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
ReplyCount int32 `json:"reply_count"`
|
||||
RecentRepliers []json.RawMessage `json:"recent_repliers"`
|
||||
LastReadInboxMessageId int64 `json:"last_read_inbox_message_id"`
|
||||
LastReadOutboxMessageId int64 `json:"last_read_outbox_message_id"`
|
||||
LastMessageId int64 `json:"last_message_id"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
messageReplyInfo.ReplyCount = tmp.ReplyCount
|
||||
messageReplyInfo.LastReadInboxMessageId = tmp.LastReadInboxMessageId
|
||||
messageReplyInfo.LastReadOutboxMessageId = tmp.LastReadOutboxMessageId
|
||||
messageReplyInfo.LastMessageId = tmp.LastMessageId
|
||||
|
||||
fieldRecentRepliers, _ := UnmarshalListOfMessageSender(tmp.RecentRepliers)
|
||||
messageReplyInfo.RecentRepliers = fieldRecentRepliers
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Contains information about interactions with a message
|
||||
type MessageInteractionInfo struct {
|
||||
meta
|
||||
|
@ -6319,6 +6363,22 @@ func (*ChatLists) GetType() string {
|
|||
return TypeChatLists
|
||||
}
|
||||
|
||||
func (chatLists *ChatLists) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
ChatLists []json.RawMessage `json:"chat_lists"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldChatLists, _ := UnmarshalListOfChatList(tmp.ChatLists)
|
||||
chatLists.ChatLists = fieldChatLists
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// The chat is sponsored by the user's MTProxy server
|
||||
type ChatSourceMtprotoProxy struct {
|
||||
meta
|
||||
|
@ -8202,6 +8262,22 @@ func (*RichTexts) RichTextType() string {
|
|||
return TypeRichTexts
|
||||
}
|
||||
|
||||
func (richTexts *RichTexts) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Texts []json.RawMessage `json:"texts"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldTexts, _ := UnmarshalListOfRichText(tmp.Texts)
|
||||
richTexts.Texts = fieldTexts
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Contains a caption of an instant view web page block, consisting of a text and a trailing credit
|
||||
type PageBlockCaption struct {
|
||||
meta
|
||||
|
@ -8272,6 +8348,25 @@ func (*PageBlockListItem) GetType() string {
|
|||
return TypePageBlockListItem
|
||||
}
|
||||
|
||||
func (pageBlockListItem *PageBlockListItem) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Label string `json:"label"`
|
||||
PageBlocks []json.RawMessage `json:"page_blocks"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageBlockListItem.Label = tmp.Label
|
||||
|
||||
fieldPageBlocks, _ := UnmarshalListOfPageBlock(tmp.PageBlocks)
|
||||
pageBlockListItem.PageBlocks = fieldPageBlocks
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// The content should be left-aligned
|
||||
type PageBlockHorizontalAlignmentLeft struct {
|
||||
meta
|
||||
|
@ -9367,6 +9462,33 @@ func (*PageBlockEmbeddedPost) PageBlockType() string {
|
|||
return TypePageBlockEmbeddedPost
|
||||
}
|
||||
|
||||
func (pageBlockEmbeddedPost *PageBlockEmbeddedPost) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Url string `json:"url"`
|
||||
Author string `json:"author"`
|
||||
AuthorPhoto *Photo `json:"author_photo"`
|
||||
Date int32 `json:"date"`
|
||||
PageBlocks []json.RawMessage `json:"page_blocks"`
|
||||
Caption *PageBlockCaption `json:"caption"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageBlockEmbeddedPost.Url = tmp.Url
|
||||
pageBlockEmbeddedPost.Author = tmp.Author
|
||||
pageBlockEmbeddedPost.AuthorPhoto = tmp.AuthorPhoto
|
||||
pageBlockEmbeddedPost.Date = tmp.Date
|
||||
pageBlockEmbeddedPost.Caption = tmp.Caption
|
||||
|
||||
fieldPageBlocks, _ := UnmarshalListOfPageBlock(tmp.PageBlocks)
|
||||
pageBlockEmbeddedPost.PageBlocks = fieldPageBlocks
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// A collage
|
||||
type PageBlockCollage struct {
|
||||
meta
|
||||
|
@ -9396,6 +9518,25 @@ func (*PageBlockCollage) PageBlockType() string {
|
|||
return TypePageBlockCollage
|
||||
}
|
||||
|
||||
func (pageBlockCollage *PageBlockCollage) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
PageBlocks []json.RawMessage `json:"page_blocks"`
|
||||
Caption *PageBlockCaption `json:"caption"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageBlockCollage.Caption = tmp.Caption
|
||||
|
||||
fieldPageBlocks, _ := UnmarshalListOfPageBlock(tmp.PageBlocks)
|
||||
pageBlockCollage.PageBlocks = fieldPageBlocks
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// A slideshow
|
||||
type PageBlockSlideshow struct {
|
||||
meta
|
||||
|
@ -9425,6 +9566,25 @@ func (*PageBlockSlideshow) PageBlockType() string {
|
|||
return TypePageBlockSlideshow
|
||||
}
|
||||
|
||||
func (pageBlockSlideshow *PageBlockSlideshow) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
PageBlocks []json.RawMessage `json:"page_blocks"`
|
||||
Caption *PageBlockCaption `json:"caption"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageBlockSlideshow.Caption = tmp.Caption
|
||||
|
||||
fieldPageBlocks, _ := UnmarshalListOfPageBlock(tmp.PageBlocks)
|
||||
pageBlockSlideshow.PageBlocks = fieldPageBlocks
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// A link to a chat
|
||||
type PageBlockChatLink struct {
|
||||
meta
|
||||
|
@ -9546,7 +9706,7 @@ func (*PageBlockDetails) PageBlockType() string {
|
|||
func (pageBlockDetails *PageBlockDetails) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Header json.RawMessage `json:"header"`
|
||||
PageBlocks []PageBlock `json:"page_blocks"`
|
||||
PageBlocks []json.RawMessage `json:"page_blocks"`
|
||||
IsOpen bool `json:"is_open"`
|
||||
}
|
||||
|
||||
|
@ -9555,12 +9715,14 @@ func (pageBlockDetails *PageBlockDetails) UnmarshalJSON(data []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
pageBlockDetails.PageBlocks = tmp.PageBlocks
|
||||
pageBlockDetails.IsOpen = tmp.IsOpen
|
||||
|
||||
fieldHeader, _ := UnmarshalRichText(tmp.Header)
|
||||
pageBlockDetails.Header = fieldHeader
|
||||
|
||||
fieldPageBlocks, _ := UnmarshalListOfPageBlock(tmp.PageBlocks)
|
||||
pageBlockDetails.PageBlocks = fieldPageBlocks
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -9678,6 +9840,31 @@ func (*WebPageInstantView) GetType() string {
|
|||
return TypeWebPageInstantView
|
||||
}
|
||||
|
||||
func (webPageInstantView *WebPageInstantView) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
PageBlocks []json.RawMessage `json:"page_blocks"`
|
||||
ViewCount int32 `json:"view_count"`
|
||||
Version int32 `json:"version"`
|
||||
IsRtl bool `json:"is_rtl"`
|
||||
IsFull bool `json:"is_full"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
webPageInstantView.ViewCount = tmp.ViewCount
|
||||
webPageInstantView.Version = tmp.Version
|
||||
webPageInstantView.IsRtl = tmp.IsRtl
|
||||
webPageInstantView.IsFull = tmp.IsFull
|
||||
|
||||
fieldPageBlocks, _ := UnmarshalListOfPageBlock(tmp.PageBlocks)
|
||||
webPageInstantView.PageBlocks = fieldPageBlocks
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Describes a web page preview
|
||||
type WebPage struct {
|
||||
meta
|
||||
|
@ -10800,7 +10987,7 @@ func (inputIdentityDocument *InputIdentityDocument) UnmarshalJSON(data []byte) e
|
|||
FrontSide json.RawMessage `json:"front_side"`
|
||||
ReverseSide json.RawMessage `json:"reverse_side"`
|
||||
Selfie json.RawMessage `json:"selfie"`
|
||||
Translation []InputFile `json:"translation"`
|
||||
Translation []json.RawMessage `json:"translation"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
|
@ -10810,7 +10997,6 @@ func (inputIdentityDocument *InputIdentityDocument) UnmarshalJSON(data []byte) e
|
|||
|
||||
inputIdentityDocument.Number = tmp.Number
|
||||
inputIdentityDocument.ExpiryDate = tmp.ExpiryDate
|
||||
inputIdentityDocument.Translation = tmp.Translation
|
||||
|
||||
fieldFrontSide, _ := UnmarshalInputFile(tmp.FrontSide)
|
||||
inputIdentityDocument.FrontSide = fieldFrontSide
|
||||
|
@ -10821,6 +11007,9 @@ func (inputIdentityDocument *InputIdentityDocument) UnmarshalJSON(data []byte) e
|
|||
fieldSelfie, _ := UnmarshalInputFile(tmp.Selfie)
|
||||
inputIdentityDocument.Selfie = fieldSelfie
|
||||
|
||||
fieldTranslation, _ := UnmarshalListOfInputFile(tmp.Translation)
|
||||
inputIdentityDocument.Translation = fieldTranslation
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -10874,6 +11063,26 @@ func (*InputPersonalDocument) GetType() string {
|
|||
return TypeInputPersonalDocument
|
||||
}
|
||||
|
||||
func (inputPersonalDocument *InputPersonalDocument) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Files []json.RawMessage `json:"files"`
|
||||
Translation []json.RawMessage `json:"translation"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldFiles, _ := UnmarshalListOfInputFile(tmp.Files)
|
||||
inputPersonalDocument.Files = fieldFiles
|
||||
|
||||
fieldTranslation, _ := UnmarshalListOfInputFile(tmp.Translation)
|
||||
inputPersonalDocument.Translation = fieldTranslation
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// A Telegram Passport element containing the user's personal details
|
||||
type PassportElementPersonalDetails struct {
|
||||
meta
|
||||
|
@ -11599,6 +11808,22 @@ func (*PassportElements) GetType() string {
|
|||
return TypePassportElements
|
||||
}
|
||||
|
||||
func (passportElements *PassportElements) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Elements []json.RawMessage `json:"elements"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldElements, _ := UnmarshalListOfPassportElement(tmp.Elements)
|
||||
passportElements.Elements = fieldElements
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// The element contains an error in an unspecified place. The error will be considered resolved when new data is added
|
||||
type PassportElementErrorSourceUnspecified struct {
|
||||
meta
|
||||
|
@ -12007,6 +12232,25 @@ func (*PassportElementsWithErrors) GetType() string {
|
|||
return TypePassportElementsWithErrors
|
||||
}
|
||||
|
||||
func (passportElementsWithErrors *PassportElementsWithErrors) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Elements []json.RawMessage `json:"elements"`
|
||||
Errors []*PassportElementError `json:"errors"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
passportElementsWithErrors.Errors = tmp.Errors
|
||||
|
||||
fieldElements, _ := UnmarshalListOfPassportElement(tmp.Elements)
|
||||
passportElementsWithErrors.Elements = fieldElements
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Contains encrypted Telegram Passport data credentials
|
||||
type EncryptedCredentials struct {
|
||||
meta
|
||||
|
@ -13578,6 +13822,22 @@ func (*MessagePassportDataSent) MessageContentType() string {
|
|||
return TypeMessagePassportDataSent
|
||||
}
|
||||
|
||||
func (messagePassportDataSent *MessagePassportDataSent) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Types []json.RawMessage `json:"types"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldTypes, _ := UnmarshalListOfPassportElementType(tmp.Types)
|
||||
messagePassportDataSent.Types = fieldTypes
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Telegram Passport data has been received; for bots only
|
||||
type MessagePassportDataReceived struct {
|
||||
meta
|
||||
|
@ -18448,6 +18708,31 @@ func (*InlineQueryResults) GetType() string {
|
|||
return TypeInlineQueryResults
|
||||
}
|
||||
|
||||
func (inlineQueryResults *InlineQueryResults) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
InlineQueryId JsonInt64 `json:"inline_query_id"`
|
||||
NextOffset string `json:"next_offset"`
|
||||
Results []json.RawMessage `json:"results"`
|
||||
SwitchPmText string `json:"switch_pm_text"`
|
||||
SwitchPmParameter string `json:"switch_pm_parameter"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
inlineQueryResults.InlineQueryId = tmp.InlineQueryId
|
||||
inlineQueryResults.NextOffset = tmp.NextOffset
|
||||
inlineQueryResults.SwitchPmText = tmp.SwitchPmText
|
||||
inlineQueryResults.SwitchPmParameter = tmp.SwitchPmParameter
|
||||
|
||||
fieldResults, _ := UnmarshalListOfInlineQueryResult(tmp.Results)
|
||||
inlineQueryResults.Results = fieldResults
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// The payload for a general callback button
|
||||
type CallbackQueryPayloadData struct {
|
||||
meta
|
||||
|
@ -21963,6 +22248,22 @@ func (*JsonValueArray) JsonValueType() string {
|
|||
return TypeJsonValueArray
|
||||
}
|
||||
|
||||
func (jsonValueArray *JsonValueArray) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Values []json.RawMessage `json:"values"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldValues, _ := UnmarshalListOfJsonValue(tmp.Values)
|
||||
jsonValueArray.Values = fieldValues
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Represents a JSON object
|
||||
type JsonValueObject struct {
|
||||
meta
|
||||
|
@ -22221,6 +22522,22 @@ func (*UserPrivacySettingRules) GetType() string {
|
|||
return TypeUserPrivacySettingRules
|
||||
}
|
||||
|
||||
func (userPrivacySettingRules *UserPrivacySettingRules) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Rules []json.RawMessage `json:"rules"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldRules, _ := UnmarshalListOfUserPrivacySettingRule(tmp.Rules)
|
||||
userPrivacySettingRules.Rules = fieldRules
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// A privacy setting for managing whether the user's online status is visible
|
||||
type UserPrivacySettingShowStatus struct {
|
||||
meta
|
||||
|
@ -23658,6 +23975,25 @@ func (*NetworkStatistics) GetType() string {
|
|||
return TypeNetworkStatistics
|
||||
}
|
||||
|
||||
func (networkStatistics *NetworkStatistics) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
SinceDate int32 `json:"since_date"`
|
||||
Entries []json.RawMessage `json:"entries"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
networkStatistics.SinceDate = tmp.SinceDate
|
||||
|
||||
fieldEntries, _ := UnmarshalListOfNetworkStatisticsEntry(tmp.Entries)
|
||||
networkStatistics.Entries = fieldEntries
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Contains auto-download settings
|
||||
type AutoDownloadSettings struct {
|
||||
meta
|
||||
|
@ -27521,6 +27857,26 @@ func (*UpdateSuggestedActions) UpdateType() string {
|
|||
return TypeUpdateSuggestedActions
|
||||
}
|
||||
|
||||
func (updateSuggestedActions *UpdateSuggestedActions) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
AddedActions []json.RawMessage `json:"added_actions"`
|
||||
RemovedActions []json.RawMessage `json:"removed_actions"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldAddedActions, _ := UnmarshalListOfSuggestedAction(tmp.AddedActions)
|
||||
updateSuggestedActions.AddedActions = fieldAddedActions
|
||||
|
||||
fieldRemovedActions, _ := UnmarshalListOfSuggestedAction(tmp.RemovedActions)
|
||||
updateSuggestedActions.RemovedActions = fieldRemovedActions
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// A new incoming inline query; for bots only
|
||||
type UpdateNewInlineQuery struct {
|
||||
meta
|
||||
|
@ -27926,6 +28282,22 @@ func (*Updates) GetType() string {
|
|||
return TypeUpdates
|
||||
}
|
||||
|
||||
func (updates *Updates) UnmarshalJSON(data []byte) error {
|
||||
var tmp struct {
|
||||
Updates []json.RawMessage `json:"updates"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldUpdates, _ := UnmarshalListOfUpdate(tmp.Updates)
|
||||
updates.Updates = fieldUpdates
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// The log is written to stderr or an OS specific log
|
||||
type LogStreamDefault struct {
|
||||
meta
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -285,10 +285,9 @@ func (entity *tdlibType) GetClass() *tlparser.Class {
|
|||
func (entity *tdlibType) HasClassProperties() bool {
|
||||
for _, prop := range entity.GetType().Properties {
|
||||
tdlibTypeProperty := TdlibTypeProperty(prop.Name, prop.Type, entity.schema)
|
||||
if tdlibTypeProperty.IsClass() && !tdlibTypeProperty.IsList() {
|
||||
if tdlibTypeProperty.IsClass() {
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false
|
||||
|
|
|
@ -3,7 +3,6 @@ package codegen
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/zelenin/go-tdlib/tlparser"
|
||||
)
|
||||
|
||||
|
@ -125,13 +124,17 @@ func (*%s) GetType() string {
|
|||
for _, property := range typ.Properties {
|
||||
tdlibTypeProperty := TdlibTypeProperty(property.Name, property.Type, schema)
|
||||
|
||||
if !tdlibTypeProperty.IsClass() || tdlibTypeProperty.IsList() {
|
||||
if !tdlibTypeProperty.IsClass() {
|
||||
buf.WriteString(fmt.Sprintf(" %s %s `json:\"%s\"`\n", tdlibTypeProperty.ToGoName(), tdlibTypeProperty.ToGoType(), property.Name))
|
||||
countSimpleProperties++
|
||||
} else {
|
||||
if tdlibTypeProperty.IsList() {
|
||||
buf.WriteString(fmt.Sprintf(" %s %s `json:\"%s\"`\n", tdlibTypeProperty.ToGoName(), "[]json.RawMessage", property.Name))
|
||||
} else {
|
||||
buf.WriteString(fmt.Sprintf(" %s %s `json:\"%s\"`\n", tdlibTypeProperty.ToGoName(), "json.RawMessage", property.Name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.WriteString(` }
|
||||
|
||||
|
@ -145,7 +148,7 @@ func (*%s) GetType() string {
|
|||
for _, property := range typ.Properties {
|
||||
tdlibTypeProperty := TdlibTypeProperty(property.Name, property.Type, schema)
|
||||
|
||||
if !tdlibTypeProperty.IsClass() || tdlibTypeProperty.IsList() {
|
||||
if !tdlibTypeProperty.IsClass() {
|
||||
buf.WriteString(fmt.Sprintf(" %s.%s = tmp.%s\n", typ.Name, tdlibTypeProperty.ToGoName(), tdlibTypeProperty.ToGoName()))
|
||||
}
|
||||
}
|
||||
|
@ -163,6 +166,12 @@ func (*%s) GetType() string {
|
|||
|
||||
`, tdlibTypeProperty.ToGoName(), tdlibTypeProperty.ToGoType(), tdlibTypeProperty.ToGoName(), typ.Name, tdlibTypeProperty.ToGoName(), tdlibTypeProperty.ToGoName()))
|
||||
}
|
||||
if tdlibTypeProperty.IsClass() && tdlibTypeProperty.IsList() {
|
||||
buf.WriteString(fmt.Sprintf(` field%s, _ := UnmarshalListOf%s(tmp.%s)
|
||||
%s.%s = field%s
|
||||
|
||||
`, tdlibTypeProperty.ToGoName(), tdlibTypeProperty.GetClass().ToGoType(), tdlibTypeProperty.ToGoName(), typ.Name, tdlibTypeProperty.ToGoName(), tdlibTypeProperty.ToGoName()))
|
||||
}
|
||||
}
|
||||
|
||||
buf.WriteString(` return nil
|
||||
|
|
|
@ -46,6 +46,23 @@ func GenerateUnmarshalers(schema *tlparser.Schema, packageName string) []byte {
|
|||
}
|
||||
|
||||
`)
|
||||
|
||||
buf.WriteString(fmt.Sprintf(`func UnmarshalListOf%s(dataList []json.RawMessage) ([]%s, error) {
|
||||
list := []%s{}
|
||||
|
||||
for _, data := range dataList {
|
||||
entity, err := Unmarshal%s(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list = append(list, entity)
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
`, tdlibClass.ToGoType(), tdlibClass.ToGoType(), tdlibClass.ToGoType(), tdlibClass.ToGoType()))
|
||||
|
||||
}
|
||||
|
||||
for _, typ := range schema.Types {
|
||||
|
|
Loading…
Reference in a new issue