Skip to content

Instantly share code, notes, and snippets.

@giggsoff
Created May 23, 2020 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giggsoff/65606a03d84288000f0cd01684eb1b48 to your computer and use it in GitHub Desktop.
Save giggsoff/65606a03d84288000f0cd01684eb1b48 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/vmihailenco/msgpack/v4"
"log"
)
type interfaceAlias interface{
isZInfoMsgInfoContent()
}
type interfaceEmbedded struct {
InfoContent interfaceAlias
}
type infoMsgAInfo struct {
aInfo string
}
type infoMsgDInfo struct {
extra int
dInfo string
}
func (*infoMsgAInfo) isZInfoMsgInfoContent() {}
func (*infoMsgDInfo) isZInfoMsgInfoContent() {}
func main() {
message := interfaceEmbedded{}
message.InfoContent = &infoMsgAInfo{aInfo: "123"}
log.Println("Before marshalling: ", message.InfoContent)
b, err := msgpack.Marshal(&message)
if err != nil {
log.Fatal(err)
}
newMessage := interfaceEmbedded{}
newMessage.InfoContent = &infoMsgDInfo{dInfo: "456"}
if err = msgpack.Unmarshal(b, &newMessage); err != nil {
log.Fatal(err)
}
log.Println("After marshalling: ", newMessage.InfoContent)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment