anthropics / anthropics/buffa

Expose the ordinal of MessageIndex / EnumIndex / ExtensionIndex for dense side tables

Open
#433 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
883
Forks
88
Avg merge
3d 19h
Merged PRs (30d)
42

Description

`MessageIndex`, `EnumIndex`, and `ExtensionIndex` are opaque `u32` newtypes with `pub(crate)` contents. That is the right default, but it leaves a consumer that wants a per-message side table (per-type caches, lowering metadata, lookup tables keyed by message type) with no dense key: the options today are a `HashMap`, or keeping a sorted `Vec` and binary-searching it on every access, because the ordinal inside the index is not readable and the pool does not enumerate its messages with their indices.

Either of these would do, and both are additive:

- `MessageIndex::index(self) -> usize` (and the same on `EnumIndex` / `ExtensionIndex`), documented as dense in `0..pool.message_count()` for the pool that issued it and meaningless across pools (the same caveat the type's docs already give for comparison); plus `DescriptorPool::message_count()` and friends so a side table can be sized up front.
- or `DescriptorPool::messages(&self) -> impl Iterator` and `extensions_of(&self, MessageIndex) -> impl Iterator`, so the table can be built by enumeration and then indexed by the ordinal.

The first is the smaller change and enough on its own. Related to, but independent of, #413 (which is about obtaining a `MessageIndex` from a generated type at all).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.