refactor: store incoming message as a child property vs overriding itself via pointer magic

This commit is contained in:
Derrick Hammer 2024-01-07 22:55:57 -05:00
parent 0d083e8567
commit 2f5a853ff8
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 8 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import (
type IncomingMessage interface {
HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error
SetIncomingMessage(msg IncomingMessage)
IncomingMessage() IncomingMessage
Self() IncomingMessage
SetSelf(self IncomingMessage)
msgpack.CustomDecoder

View File

@ -22,6 +22,7 @@ type IncomingMessageImpl struct {
original []byte
known bool
self IncomingMessage
incoming IncomingMessage
}
func (i *IncomingMessageImpl) Self() IncomingMessage {
@ -53,13 +54,12 @@ func (i *IncomingMessageImpl) Original() []byte {
}
func (i *IncomingMessageImpl) SetIncomingMessage(msg IncomingMessage) {
if msgImpl, ok := msg.(*IncomingMessageImpl); ok {
*i = *msgImpl
i.incoming = msg
i.known = true
} else {
// Handle the error or panic
panic("msg is not of type *IncomingMessageImpl")
}
func (i *IncomingMessageImpl) IncomingMessage() IncomingMessage {
return i.incoming
}
func (i *IncomingMessageImpl) GetKind() types.ProtocolMethod {