Skip to content

feat: add StringReference.GetValue/GetRaw (Python parity)#34

Merged
tinysec merged 1 commit into
masterfrom
feat/string-reference-value-raw
Jul 8, 2026
Merged

feat: add StringReference.GetValue/GetRaw (Python parity)#34
tinysec merged 1 commit into
masterfrom
feat/string-reference-value-raw

Conversation

@tinysec

@tinysec tinysec commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

Closes HIGH-severity convenience gap #4. Python's StringReference exposes .value (decoded text) and .raw (raw bytes) (binaryview.py:510/:514). The C# StringReference is a handle-less Type/Start/Length carrier, so callers had to separately ReadData(Start, Length) and hand-decode per StringType.

Changes

Two durable extension methods in NavigationExtensions.cs (composition-only, no P/Invoke, no generated-file edits), plus a StringType → Encoding table mirroring Python's _decodings:

StringType Encoding
AsciiString Encoding.ASCII
Utf8String Encoding.UTF8
Utf16String Encoding.Unicode (UTF-16 LE)
Utf32String Encoding.UTF32 (UTF-32 LE)
  • GetRaw(sref, view)view.ReadData(Start, Length).
  • GetValue(sref, view) → decodes GetRaw with the type's encoding using .NET's default replacement fallback (the equivalent of Python errors='replace').

The view is a parameter (not stored on StringReference) because the C# type is a value carrier; storing a view would force a FromNative signature change threaded through the TakeStructArray pipelines, so composition-only extensions are cleaner. Python's .view property is therefore N/A here — the caller already holds the view.

E2E test (harness repo)

GetValueAndRawAreConsistentForEveryStringTypePresent — runs analysis (the string list is materialized lazily), then for a sample of the 177 strings asserts GetRaw reads exactly [Start, Start+Length) and GetValue decodes with the independently-computed expected encoding. cat.bndb yields 176 ASCII + 1 UTF-16 strings, so the test exercises both Encoding.ASCII and Encoding.Unicode dispatch — a wrong table entry would diverge for the UTF-16 string. Full harness regression 52/52.

Closes HIGH convenience gap #4. Python's StringReference exposes
.value (decoded text) and .raw (bytes) (binaryview.py:510/:514); the
C# StringReference is a handle-less Type/Start/Length carrier, so
callers had to separately ReadData(Start, Length) and hand-decode per
StringType.

Add durable GetValue(this StringReference, BinaryView) and
GetRaw(this StringReference, BinaryView) extension methods with a
StringType -> Encoding table mirroring Python's _decodings
(Ascii->ASCII, Utf8->UTF8, Utf16->Unicode/UTF-16LE, Utf32->UTF32LE).
GetValue decodes with .NET's default replacement fallback, the
equivalent of Python errors='replace'. The view is a parameter because
StringReference does not own one (unlike Python); extending its shape
would force a FromNative signature change threaded through the
TakeStructArray pipelines, so composition-only extensions are cleaner.
@tinysec tinysec merged commit e12e3fe into master Jul 8, 2026
1 check passed
@tinysec tinysec deleted the feat/string-reference-value-raw branch July 8, 2026 16:31
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