mirror of
https://github.com/lux-tel/libsession-util.git
synced 2026-10-30 20:25:11 +00:00
`string8` (`{char* data; size_t size}`) was a structural duplicate of the
existing `span_u8` (`{uint8_t* data; size_t size}`) -- same ptr+len byte span,
right down to a duplicate pair of alloc/copy_or_throw helpers. Once its uses are
mapped, none actually need a string-with-length:
- SESSION_PROTOCOL_STRINGS (24 fields) and session_protocol_pro_features_for_msg
`error` are static, null-terminated strings -> `const char*`. The `error`
string_view only ever views static literals ("..." + simdutf::error_to_string,
which returns string_view over literals), so there is nothing to free and no
dangling. SESSION_PROTOCOL_STRINGS drops the `string8_literal` macro for plain
string literals.
- session_pro_backend_request `data` is an opaque (possibly binary) payload that
genuinely needs ptr+len -> `span_u8`, the type already used for sig/msg.
Then delete the dead string8_alloc_or_throw/string8_copy_or_throw helpers (no
callers; duplicates of span_u8_*), and the `string8` struct + `string8_literal`
macro. Test helper string8_equals -> span_u8_equals, now a std::string_view
compare instead of a hand-rolled memcmp.
C-API change (clients): session_protocol_strings fields and
session_protocol_pro_features_for_msg.error are now `const char*`;
session_pro_backend_request.data is now `span_u8`.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
#include "types.h"
|
|
|
|
namespace session {
|
|
|
|
template <typename T, typename... U>
|
|
static constexpr bool is_one_of = (std::is_same_v<T, U> || ...);
|
|
|
|
using array_uc32 = std::array<std::uint8_t, 32>;
|
|
using array_uc33 = std::array<std::uint8_t, 33>;
|
|
using array_uc64 = std::array<std::uint8_t, 64>;
|
|
|
|
enum class SessionIDPrefix {
|
|
standard = 0,
|
|
group = 0x3,
|
|
community_blinded_legacy = 0x5,
|
|
community_blinded = 0x15,
|
|
version_blinded = 0x25,
|
|
unblinded = 0x7,
|
|
};
|
|
|
|
namespace config {
|
|
using seqno_t = std::int64_t;
|
|
}
|
|
|
|
/// Create a span of bytes that owns the `size` bytes of memory requested. If allocation fails, this
|
|
/// function throws a runtime exception. The `data` pointer is span must be freed once the span
|
|
/// is no longer needed.
|
|
span_u8 span_u8_alloc_or_throw(size_t size);
|
|
|
|
/// Create a span of bytes that copies the payload at `data` for `size` bytes. If allocation fails
|
|
/// this function throws a runtime exception. The `data` pointer is span must be freed once the span
|
|
/// is no longer needed.
|
|
span_u8 span_u8_copy_or_throw(const void* data, size_t size);
|
|
|
|
} // namespace session
|