Skip to content

fix(objects): document RawObject's framing and add byte_len and mc_width (#83) - #281

Merged
DrunkOnJava merged 2 commits into
mainfrom
fix/83-rawobject-framing
Oct 26, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
fix/83-rawobject-framing

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

Close the RawObject length trap before the API stabilises. raw.len() and size_bytes disagree on R2010+, because the MS does not count the record's own leading MC (#77). The type now documents its framing and gains byte_len() and mc_width(), so a caller never has to know that.

Closes #83.

Spec reference

§2.6 (modular chars) and the record framing measured in #77, documented in ARCHITECTURE.md ("A record's MS excludes its own MC"):

MS size | MC handle-stream size (R2010+) | data, string and handle streams | CRC (2 bytes)

raw spans everything between the MS and the CRC. size_bytes stays the MS verbatim: it is unchanged and not renamed, so no caller breaks. byte_len() returns raw.len(); mc_width() returns byte_len() - size_bytes.

Measured

A throwaway check, not committed, tallied mc_width() over every record of the 52-file public corpus (#225). It is 0 on every R14, R2000, R2004 and R2007 record, and 1 or 2 on every R2010, R2013 and R2018 record. sample_AC1032.dwg, for example, has 772 one-byte and 70 two-byte MCs, which are the counts #77 reported:

AC1014 … AC1021   {0: n}               every file
AC1024            {1: 175..851, 2: 5..72}
AC1027            {1: 126..793, 2: 5..72}
AC1032            {1: 138..772, 2: 7..70}

No decode count moves, and tools/corpus/baseline.tsv is unchanged.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • RUSTFLAGS="-D warnings" cargo test --release --all-features
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
  • No unit tests added or changed.

Source-provenance declaration

By submitting this PR I certify that my contribution does not incorporate executable code from any source whose license is incompatible with Apache-2.0. Specifically:

  • No Autodesk DWG SDK source (RealDWG, ObjectARX, ObjectDBX) or NDA-protected Autodesk documentation was consulted or imported.
  • No Open Design Alliance Teigha / Drawings SDK source was consulted or imported. The ODA's public Open Design Specification for .dwg files PDF is explicitly allowed (see CLEANROOM.md).
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported.

My contribution is based on §2.6 of the ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1) and on the corpus bytes. No third-party code or comments were read.

Developer Certificate of Origin

By submitting this PR, I certify that the contribution complies with the Developer Certificate of Origin 1.1.

…dth (#83)

raw.len() and size_bytes disagree on R2010+, because a record's MS does
not count its own leading MC handle-stream-size field (#77). The type
now documents the framing (MS | MC | streams | CRC) and gains byte_len()
for the record's length and mc_width() for the difference, so a caller
need not know the trap. size_bytes is unchanged. Over the 52-file public
corpus mc_width is 0 on every R14 to R2007 record and 1 or 2 on every
R2010+ record.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T14:11:08.763603Z 29a290d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 14:11
@DrunkOnJava
DrunkOnJava merged commit 910bde7 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/83-rawobject-framing branch October 26, 2026 14:17
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.

RawObject: raw.len() != size_bytes is a latent API trap — rename or add len() before 0.2.0

1 participant