Created
May 23, 2020 17:44
-
-
Save giggsoff/65606a03d84288000f0cd01684eb1b48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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