feat: implement HashQuery EncodeMsgpack

This commit is contained in:
Derrick Hammer 2024-01-09 07:07:00 -05:00
parent 88c48aa996
commit 4de11b414f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 23 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import (
) )
var _ base.IncomingMessageTyped = (*HashQuery)(nil) var _ base.IncomingMessageTyped = (*HashQuery)(nil)
var _ base.EncodeableMessage = (*HashQuery)(nil)
type HashQuery struct { type HashQuery struct {
hash *encoding.Multihash hash *encoding.Multihash
@ -63,6 +64,28 @@ func (h *HashQuery) DecodeMessage(dec *msgpack.Decoder) error {
return nil return nil
} }
func (h HashQuery) EncodeMsgpack(enc *msgpack.Encoder) error {
err := enc.EncodeInt(int64(types.ProtocolMethodHashQuery))
if err != nil {
return err
}
err = enc.EncodeBytes(h.hash.FullBytes())
if err != nil {
return err
}
err = enc.Encode(h.kinds)
if err != nil {
return err
}
return nil
}
func (h *HashQuery) HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error { func (h *HashQuery) HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error {
mapLocations, err := node.GetCachedStorageLocations(h.hash, h.kinds) mapLocations, err := node.GetCachedStorageLocations(h.hash, h.kinds)
if err != nil { if err != nil {