Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json unmarshal loss field value #86

Open
FunkyYang opened this issue May 29, 2021 · 4 comments
Open

json unmarshal loss field value #86

FunkyYang opened this issue May 29, 2021 · 4 comments

Comments

@FunkyYang
Copy link

when I receive a message from tdlib,I saw the original string contains textEntityTypeTextUrl,but when I use tdlib.UpdateNewMessage to umarshal it,I can't find which field contains textEntityTypeTextUrl,so any one could help

@FunkyYang
Copy link
Author

and message type is updateNewMessage

@FunkyYang
Copy link
Author

this is the code

                               ack := &tdlib.UpdateNewMessage{}
				if err := json.Unmarshal(update.Raw, ack); err != nil {
					log.Printf("解码失败,原因:%s", err.Error())
					continue
				}
				log.Printf("会话id:%d", ack.Message.ChatID)
				switch ack.Message.Content.(type) {
				case *tdlib.MessageText:
					content := ack.Message.Content.(*tdlib.MessageText)
					if content.Text != nil {
						log.Printf("内容:%s", content.Text.Text)
						entityes := content.Text.Entities
						for _, e := range entityes {
							log.Printf("offset:%d,length:%d,type:%v", e.Offset, e.Length, e.Type)
							switch e.Type.(type) {
							case *tdlib.TextEntityTypeTextURL:
								eType := e.Type.(*tdlib.TextEntityTypeTextURL)
								log.Printf("URL:%s", eType.URL)
							}
						}
					}
				default:
				}

@FunkyYang
Copy link
Author

I can't get e.Type

@er-azh
Copy link

er-azh commented Jul 13, 2021

the issue is in the code generator.
the parser runs replaceKeyWords on enum type names and this causes words like Url to become URL.
but tdlib returns the original types in the @type field so when the library tries to compare textEntityTypeTextUrl with textEntityTypeTextURL this happens.
link to what causes this

I actually re-wrote the entire codegen and parser parts but they're private for now (I'm planning on open-sourcing it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants