onflow / atree

Atree provides scalable arrays and scalable ordered maps.
https://onflow.org
Apache License 2.0
39 stars 16 forks source link

Add a callback to the Encoder #287

Closed SupunS closed 1 year ago

SupunS commented 1 year ago

Work towards https://github.com/dapperlabs/cadence-private-issues/issues/64

Description

It can be useful to have a callback function that gets called during the encoding (e.g: https://github.com/dapperlabs/cadence-private-issues/issues/64), to keep track of the operation.

This PR adds a generic Callback field to the Encoder, which wraps different callback functions. Users of the encoder can register callbacks when they create the encoder. For now, the callback only has one function BeforeEncode which is/should be invoked at the start of each value encoding.


codecov-commenter commented 1 year ago

Codecov Report

Merging #287 (7ad3854) into main (d5384d9) will increase coverage by 0.02%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #287      +/-   ##
==========================================
+ Coverage   69.08%   69.10%   +0.02%     
==========================================
  Files          14       14              
  Lines        7306     7311       +5     
==========================================
+ Hits         5047     5052       +5     
- Misses       1624     1627       +3     
+ Partials      635      632       -3     
Impacted Files Coverage Δ
encode.go 80.64% <ø> (ø)
array_debug.go 54.16% <100.00%> (ø)
basicarray.go 53.55% <100.00%> (ø)
map_debug.go 55.50% <100.00%> (ø)
storable.go 68.18% <100.00%> (+2.60%) :arrow_up:
storage.go 79.30% <100.00%> (+0.52%) :arrow_up:
array.go 76.15% <0.00%> (-0.34%) :arrow_down:
map.go 71.78% <0.00%> (+0.10%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

SupunS commented 1 year ago

Oh I see. So reporting at the beginning of each slab is sufficient, and don't need to report for each storable?

fxamacker commented 1 year ago

Oh I see. So reporting at the beginning of each slab is sufficient, and don't need to report for each storable?

@SupunS Yes. Storables implemented by Cadence are elements in atree (leaf) slabs. Therefore, we don't need to meter storables if we meter slabs.