Skip to content

Foundation: Add ULID support#5129

Merged
matejk merged 10 commits intomainfrom
feat/ulid
Dec 19, 2025
Merged

Foundation: Add ULID support#5129
matejk merged 10 commits intomainfrom
feat/ulid

Conversation

@obiltschnig
Copy link
Copy Markdown
Member

Add support for Universally Unique Lexicographically Sortable Identifier (ULID), as specified in https://github.com/ulid/spec.

This is implemented similar to existing UUID support, with a ULID class holding a ULID and supporting conversion to/from string representation, as well as a ULIDGenerator class for generating ULIDs.

In addition, this PR has enhancements for Base32Encoder and Base32Decoder (supporting Crockford Base 32), although these ended up not actually used by the ULID class.

@obiltschnig obiltschnig added this to the Release 1.15.0 milestone Dec 18, 2025
@obiltschnig obiltschnig requested a review from matejk December 18, 2025 21:07
@obiltschnig obiltschnig self-assigned this Dec 18, 2025
Copy link
Copy Markdown
Contributor

@matejk matejk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some observations are potential bugs (like negative char index), others are mostly improvements.

BASE32_NO_PADDING = 0x00,
/// Don't append padding characters ('=') at end.
///
/// NOTE: This is provided for consistency with BAse64EncodingOptions.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe typo: BAse64.. (should be Base64..)

void parse(const std::string& ulid);
/// Parses the ULID from its string representation.

bool tryParse(const std::string& ulid);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use [[nodiscard]]?

/// members and returns true. Otherwise leaves the
/// object unchanged and returns false.

std::string toString() const;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use [[nodiscard]]?

/// The buffer need not be aligned.
/// There must have room for at least 16 bytes.

Poco::UInt64 time() const;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use [[nodiscard]]? Also applies to other functions.

~ULIDGenerator();
/// Destroys the ULIDGenerator.

ULID create();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use [[nodiscard]]? Also applies to other functions.

};


ULID::ULID()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= default

}


ULID& ULID::operator = (const ULID& ulid)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= default


const ULID& ULID::null()
{
static ULID nil;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static const?



const unsigned char Base32EncoderBuf::OUT_ENCODING[32] =
const unsigned char Base32EncoderBuf::DEFAULT_ENCODING[32] =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a private (cpp only) static constexpr std::array for all these arrays?

}


const char ULID::ENCODING[32] =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpp-only static constexpr std::array?

@matejk matejk merged commit b24d9ff into main Dec 19, 2025
86 checks passed
@matejk matejk deleted the feat/ulid branch December 19, 2025 18:58
@matejk matejk changed the title ULID Support Foundation: Add ULID support Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants