Now that we will have two places where we need to calculate the size of an item in dynamodb, it would be good to introduce an abstraction that will do it for us. This diff introduces a function that will take a AttributeMap and return size of the item. The specific values were taken from aws docs, and this blogpost.
Differences from the current method (in terms of the final size):
- this method doesn't count length of optional attribute names if they don't exist in the final item
- lest error-prone -> e.g. the current implementation skipped value of creation_time field during size calculations
A problem with this approach is unnecessary allocations when creating the AttributeMap that will be then discarded. There's a chance that Rust will optimize it away, but I haven't tested it. In any case the "correct" solution would be something with either derive macros or custom serializers with serde. But the code in this diff is very localized so it will be easy to replace if it turned out to be a performance problem in the future.
Depends on D10402