refactor: store incoming message as a child property vs overriding itself via pointer magic
This commit is contained in:
parent
0d083e8567
commit
2f5a853ff8
|
@ -9,6 +9,7 @@ import (
|
||||||
type IncomingMessage interface {
|
type IncomingMessage interface {
|
||||||
HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error
|
HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error
|
||||||
SetIncomingMessage(msg IncomingMessage)
|
SetIncomingMessage(msg IncomingMessage)
|
||||||
|
IncomingMessage() IncomingMessage
|
||||||
Self() IncomingMessage
|
Self() IncomingMessage
|
||||||
SetSelf(self IncomingMessage)
|
SetSelf(self IncomingMessage)
|
||||||
msgpack.CustomDecoder
|
msgpack.CustomDecoder
|
||||||
|
|
|
@ -22,6 +22,7 @@ type IncomingMessageImpl struct {
|
||||||
original []byte
|
original []byte
|
||||||
known bool
|
known bool
|
||||||
self IncomingMessage
|
self IncomingMessage
|
||||||
|
incoming IncomingMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IncomingMessageImpl) Self() IncomingMessage {
|
func (i *IncomingMessageImpl) Self() IncomingMessage {
|
||||||
|
@ -53,13 +54,12 @@ func (i *IncomingMessageImpl) Original() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IncomingMessageImpl) SetIncomingMessage(msg IncomingMessage) {
|
func (i *IncomingMessageImpl) SetIncomingMessage(msg IncomingMessage) {
|
||||||
if msgImpl, ok := msg.(*IncomingMessageImpl); ok {
|
i.incoming = msg
|
||||||
*i = *msgImpl
|
|
||||||
i.known = true
|
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 {
|
func (i *IncomingMessageImpl) GetKind() types.ProtocolMethod {
|
||||||
|
|
Loading…
Reference in New Issue