go-tdlib icon indicating copy to clipboard operation
go-tdlib copied to clipboard

json unmarshal loss field value

Open FunkyYang opened this issue 3 years ago • 4 comments

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 avatar May 29 '21 09:05 FunkyYang

and message type is updateNewMessage

FunkyYang avatar May 29 '21 09:05 FunkyYang

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 avatar May 29 '21 09:05 FunkyYang

I can't get e.Type

FunkyYang avatar May 29 '21 09:05 FunkyYang

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)

er-azh avatar Jul 13 '21 21:07 er-azh