Skip to content

Extract shared basic_name<Traits> template from sysio::name#64

Open
heifner wants to merge 2 commits into
masterfrom
feature/templated-name
Open

Extract shared basic_name<Traits> template from sysio::name#64
heifner wants to merge 2 commits into
masterfrom
feature/templated-name

Conversation

@heifner
Copy link
Copy Markdown
Contributor

@heifner heifner commented May 22, 2026

Change Description

sysio::name packs a short string into a uint64_t. It and slug_name are near-duplicate packed-identifier types, so this extracts the encoding and value semantics into a reusable sysio::basic_name<Traits> that either can build on.

  • A Traits type supplies the alphabet, max length, and sysio::check messages; the template derives the symbol width and MSB-first bit layout.
  • name becomes a thin derived type that keeps only the contract-side surface — raw, char_to_value, length, prefix()/suffix(), operator raw, write_as_string, print. Encoding is byte-identical.
  • basic_name compares via a defaulted operator<=> / operator== (C++20).

The host side is a parallel change in wire-sysio (fc::basic_name); the two are meant to be merged together.

sysio::name packs a short string into a uint64_t. To share that scheme
with sysio::slug_name, factor the encoding and value semantics into a
generic sysio::basic_name<Traits>: a Traits type supplies the alphabet,
max length, and sysio::check messages; the template derives the symbol
width and MSB-first bit layout.

name becomes a thin derived type holding only the contract-side surface:
raw, char_to_value, length, prefix()/suffix(), operator raw,
write_as_string, and print. Encoding is byte-identical.

basic_name compares via a defaulted operator<=> / operator== (C++20).
@heifner heifner changed the title name: extract shared basic_name<Traits> template Extract shared basic_name<Traits> template from sysio::name May 22, 2026
Mirrors the wire-sysio review changes onto the contract-side basic_name
so it is ready to back a slug-style identifier:

- Add a basic_name_traits concept and constrain basic_name<Traits> with
  it, replacing the prose list of trait requirements.
- to_string() honours a Traits::zero_terminates flag: true ends the
  string at the first symbol-0 slot (slug-style), false keeps symbol 0
  as an ordinary interior character (name's '.'). sysio_name_traits sets
  it false, so name decoding is byte-identical.

Add tests/unit/basic_name_tests.cpp: native unit tests covering
basic_name through a slug-style Traits policy — the concept, encoding
round-trips, the zero-terminated to_string (incl. an interior-zero
value), defaulted comparisons, and constructor validation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant