Drvi / ProtocolBuffers.jl

4 stars 0 forks source link

Fix for containers of parametric types #15

Closed Drvi closed 2 years ago

Drvi commented 2 years ago

Fixes #13.

When we translate messages to structs, those structs may be parametrized in one of two cases:

  1. The message has a oneof field and we generated the file with parametrize_oneofs=true
  2. The message has a field referencing a different message, and the types of these two messages have mutually recursive definitions.

These parametrized structs may appear in repeated (Vector) or map (Dict) fields, but when there are multiple different parametrizations in one container, the eltype / valtype of these containers cannot be exactly resolved (typeof such type would be UnionAll, not DataType).

In an encode method which handles such containers, we used the sizeof on the eltype / valtype to preallocate some space in a target buffer, but sizeof fails, when the provided type is not complete (i.e. when it has missing params).

Since the preallocation is not precise anyway, we now only use the first element of the container to estimate the size of the vector.

codecov[bot] commented 2 years ago

Codecov Report

Merging #15 (c0fc5c3) into master (95c669d) will increase coverage by 0.00%. The diff coverage is 96.42%.

:exclamation: Current head c0fc5c3 differs from pull request most recent head 92a6a37. Consider uploading reports for the commit 92a6a37 to get more accurate results

@@           Coverage Diff           @@
##           master      #15   +/-   ##
=======================================
  Coverage   89.07%   89.07%           
=======================================
  Files          25       25           
  Lines        2754     2764   +10     
=======================================
+ Hits         2453     2462    +9     
- Misses        301      302    +1     
Impacted Files Coverage Δ
src/parsing/proto_types.jl 90.74% <66.66%> (-0.30%) :arrow_down:
src/codec/encode.jl 99.09% <100.00%> (+<0.01%) :arrow_up:
src/codegen/toplevel_definitions.jl 96.37% <100.00%> (ø)
src/codegen/types.jl 97.93% <100.00%> (+0.13%) :arrow_up:

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