About edf.RegisterTypeOf #228
Replies: 3 comments 10 replies
-
|
Could you show an example of how you’re using it? If a type implements BinaryMarshaler/BinaryUnmarshaler, RegisterTypeOf skips reflection, so the type can contain anything—private fields, pointers, and so on |
Beta Was this translation helpful? Give feedback.
-
|
btw, you may also want to try this one https://github.com/hashicorp/protoc-gen-go-binary to generate binary marshalers, and then just register those types using edf.RegisterTypeOf. should work. |
Beta Was this translation helpful? Give feedback.
-
|
my code is when running edf.Encode will return no support pointer func _NewChatMessageModel() ChatMessageModel {
return &_ChatMessage{
Id: 0,
Channel: 0,
SubChannel: "",
Sender: 0,
Receiver: 0,
SendTime: 0,
Content: "",
}
}
type GeneralModel interface {
MarshalBinary() (data []byte, err error)
UnmarshalBinary(data []byte) error
}
type ChatMessageModel interface {
GeneralModel
}
type _ChatMessage struct {
Id int64 `bson:"id" json:"Id"`
Channel int64 `bson:"channel" json:"Channel"`
SubChannel string `bson:"sub_channel" json:"SubChannel"`
Sender int64 `bson:"sender" json:"Sender"`
Receiver int64 `bson:"receiver" json:"Receiver"`
SendTime int64 `bson:"send_time" json:"SendTime"`
Content string `bson:"content" json:"Content"`
}
func (this _ChatMessage) MarshalBinary() ([]byte, error) {
return sonic.Marshal(this)
}
func (this *_ChatMessage) UnmarshalBinary(binary []byte) error {
if err := sonic.Unmarshal(binary, this); err != nil {
return err
}
return nil
}
func main() {
messageModel := _NewChatMessageModel().(*_ChatMessage )
messageModel.Id = 111
buffer := lib.TakeBuffer()
err := edf.Encode(messageModel, buffer, edf.Options{})
if err != nil {
panic(err)
}
fmt.Println(buffer.B)
} |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm using the latest V310 branch. I'm using protobuf-generated structures for data transfer between remote nodes, but the protobuf-generated structures cannot be used in non-pointer form (it's impossible under my current project architecture).
I implemented BinaryMarshaler and BinaryUnmarshaler for the protobuf-generated structures, but I still can't use edf.RegisterTypeOf(value) because it internally blocks pointer parameters.
Is it possible to avoid intercepting pointer types, or are there any alternative solutions to handle this?
Beta Was this translation helpful? Give feedback.
All reactions