Skip to content

Commit

Permalink
fix: introduce new field for shards in metadata protocol (#2511)
Browse files Browse the repository at this point in the history
* fix: repeated fields are packed in proto3
* fix: add new field for shards in metadata protobuffers to avoid breaking change and deprecate original field
  • Loading branch information
richard-ramos committed Mar 11, 2024
1 parent dcc88ee commit f9f92b7
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions waku/waku_metadata/rpc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ proc encode*(rpc: WakuMetadataRequest): ProtoBuffer =
var pb = initProtoBuffer()

pb.write3(1, rpc.clusterId)

for shard in rpc.shards:
pb.write3(2, shard)
pb.write3(2, shard) # deprecated
pb.writePacked(3, rpc.shards)
pb.finish3()

pb
Expand All @@ -41,7 +41,13 @@ proc decode*(T: type WakuMetadataRequest, buffer: seq[byte]): ProtoResult[T] =
rpc.clusterId = some(clusterId.uint32)

var shards: seq[uint64]
if ?pb.getRepeatedField(2, shards):
if ?pb.getPackedRepeatedField(3, shards):
for shard in shards:
rpc.shards.add(shard.uint32)
elif ?pb.getPackedRepeatedField(2, shards):
for shard in shards:
rpc.shards.add(shard.uint32)
elif ?pb.getRepeatedField(2, shards):
for shard in shards:
rpc.shards.add(shard.uint32)

Expand All @@ -51,9 +57,9 @@ proc encode*(rpc: WakuMetadataResponse): ProtoBuffer =
var pb = initProtoBuffer()

pb.write3(1, rpc.clusterId)

for shard in rpc.shards:
pb.write3(2, shard)
pb.write3(2, shard) # deprecated
pb.writePacked(3, rpc.shards)
pb.finish3()

pb
Expand All @@ -69,8 +75,16 @@ proc decode*(T: type WakuMetadataResponse, buffer: seq[byte]): ProtoResult[T] =
rpc.clusterId = some(clusterId.uint32)

var shards: seq[uint64]
if ?pb.getRepeatedField(2, shards):

if ?pb.getPackedRepeatedField(3, shards):
for shard in shards:
rpc.shards.add(shard.uint32)
elif ?pb.getPackedRepeatedField(2, shards):
for shard in shards:
rpc.shards.add(shard.uint32)
elif ?pb.getRepeatedField(2, shards):
for shard in shards:
rpc.shards.add(shard.uint32)


ok(rpc)

0 comments on commit f9f92b7

Please sign in to comment.