mapbox / mapbox/protozero

`basic_pbf_builder<TBuffer, T>` submessage constructor does not enforce correct parent tag type.

Open
#155 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
381
Forks
82
PR merge metrics
No merged PRs in 30d

Description

This constructor of `basic_pbf_builder`:

```cpp
/**
* Construct a pbf_builder for a submessage from the pbf_message or
* pbf_writer of the parent message.
*
* @param parent_writer The parent pbf_message or pbf_writer
* @param tag Tag of the field that will be written
*/
template
basic_pbf_builder(basic_pbf_writer& parent_writer, P tag) :
basic_pbf_writer{parent_writer, pbf_tag_type(tag)} {
}
```

Does not enforce that `P` is the correct tag type of `parent_writer`.

Would it be acceptable to submit a PR that replaces or overloads this constructor with:

```cpp
/**
* Construct a pbf_builder for a submessage from the pbf_builder of the parent message.
*
* @param parent_writer The parent pbf_builder
* @param tag Tag of the field that will be written
*/
template
basic_pbf_builder(basic_pbf_builder& parent_builder, P tag) :
basic_pbf_writer{parent_builder, pbf_tag_type(tag)} {
}
```

I did not verify that this compiles, but I think it explains the idea.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the basic_pbf_builder submessage constructor shown in the issue and inspect the related basic_pbf_writer, pbf_tag_type, and tag-type definitions. Verify how parent and tag types are represented, then add coverage showing that valid construction remains possible and an incorrect parent tag type is rejected at compile time.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.