From 4de11b414f686f9a840c97d8767e4587f1dcf1c0 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 9 Jan 2024 07:07:00 -0500 Subject: [PATCH] feat: implement HashQuery EncodeMsgpack --- protocol/hash_query.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/protocol/hash_query.go b/protocol/hash_query.go index c2f4ecd..50036cb 100644 --- a/protocol/hash_query.go +++ b/protocol/hash_query.go @@ -13,6 +13,7 @@ import ( ) var _ base.IncomingMessageTyped = (*HashQuery)(nil) +var _ base.EncodeableMessage = (*HashQuery)(nil) type HashQuery struct { hash *encoding.Multihash @@ -63,6 +64,28 @@ func (h *HashQuery) DecodeMessage(dec *msgpack.Decoder) error { 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 { mapLocations, err := node.GetCachedStorageLocations(h.hash, h.kinds) if err != nil {