package main
import (
"google.golang.org/protobuf/proto"
)
type NetMessage struct {
Data []byte
}
type Route struct {
}
type AbstractParse interface {
Parse(*NetMessage) proto.Message
}
type MessageParse[T proto.Message] struct {
}
func (p *MessageParse[T]) Parse(message *NetMessage) proto.Message {
protoT := &T{}
if len(message.Data) > 0 {
err := proto.Unmarshal(message.Data, protoT)
if err != nil {
return nil
}
}
return protoT
}
When I tried generic coding for Go, I encountered this problem:
./prog.go:23:13: invalid composite literal type T
What was the cause? Is there any way to fix it?
code link: https://go.dev/play/p/oRiH2AyaYb6