Repository navigation
feat(core): extensible registries for VRs, SOP classes and character sets; options-object streams - #650
Merged
Conversation
new ReadBufferStream(buffer, { littleEndian, start, stop, noCopy,
clearBuffers }) and new WriteBufferStream({ defaultSize, littleEndian }).
Little endian is the default. The 0.x positional forms still work, keep
every argument (including the 3rd options argument of ReadBufferStream),
and warn once per class. All internal callers use the options form.
Co-authored-by: Luis Miguel Santos <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The VR classification is stored once (constants/vrs.js flags), copied to each VR instance, and singleVRs and BINARY_VRS are computed from it and follow registerVr. Vrs replaces the private VRinstances table; createByTypeString reads it, so a registered VR decodes without the "Invalid vr type" warning. Members are unchanged (UV stays binary and length32; OL/OV have only the byte-stream flag). SopClasses (name -> UID), registerSopClass(name, uid) and sopClassName(uid) replace the hand-kept sopClassNamesByUID table. DicomMetaDictionary.sopClassUIDsByName and sopClassNamesByUID are the registry's plain objects, and _generateUIDMap() still picks up direct edits of sopClassNamesByUID. Co-authored-by: Luis Miguel Santos <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rset
registerCharacterSet(term, { label, createDecoder, encode }) adds or
replaces a SpecificCharacterSet defined term for read and write. The
registry is seeded from encodingMapping (read at lookup time) and keeps
it in step. resolveCharsetDecoder looks terms up in the registry, so all
read paths decode a registered term.
writeDataSet sets the stream encoder when it writes (0008,0005) and
restores the caller's encoder at the end of the dataset or item; Tag.write
gives each child stream its parent's encoder. StreamingPart10Writer keeps
the same scope per item. Single-byte charsets get a reverse-table encoder
(unencodable characters throw, or write "?" with writeOptions.ignoreErrors);
UTF-8 uses TextEncoder; multi-byte and ISO 2022 charsets keep UTF-8 bytes
with a one-time warning.
Co-authored-by: Luis Miguel Santos <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The VR, SOP class and character-set registries and the stream constructor shim add about 9 KB to the dcmjs.js bundle and 8 KB to the dcmjs.es.js consumer bundle (ratios 1.079 and 1.061). Co-authored-by: Luis Miguel Santos <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs/specs/registries.md (user requirements REG-U-n) and registries-implementation.md (REG-I-n), and MIGRATION.md entries for the stream constructors and for the write in the declared character set. Co-authored-by: Luis Miguel Santos <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
- writeUTF8String encodes String(value): a number in a text VR no longer crashes the single-byte encoder (B1). - writeDataSet restores the stream encoder in a finally block (N6). - the charset warn-once key is the normalized term, so registerCharacterSet clears it (N1). - registerSopClass drops the old reverse entry of a renamed UID (N4). - bundle-size ceiling comment matches the ceilings (N8). - MIGRATION.md lists every constructor whose byte order changed and rewords the intro about the writer (S4). - tests: the unencodable character and "?" under ignoreErrors (REG-U-13), StreamingPart10Writer item scoping (REG-I-19), and a number in an LO under ISO_IR 100 (B1). Co-authored-by: Luis Miguel Santos <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…isions - ReadBufferStream treats any explicit non-object 2nd argument (undefined, 0, ...) as the 0.x byte order, and WriteBufferStream any explicit non-object 1st argument, so those calls stay big endian as in 0.x and warn once. DeflatedReadBufferStream passes an options object. - REG-U-12: an empty (0008,0005) or ISO 2022 IR 6 writes with the windows-1252 table, the common handling of an unspecified repertoire. - REG-U-13: ISO_IR 100 keeps the windows-1252 table (symmetric with the read), so 0x80-0x9F characters write without an error. - MIGRATION.md: the note is about the 0.x-compatible DicomDict.write and DicomMessage.write, which now delegate to writePart10. Co-authored-by: Luis Miguel Santos <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🎉 This PR is included in version 1.0.0-beta.16 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR moves three ideas from #455 to 1.0. Luis Miguel Santos is co-author of each commit. The maintainers reshaped the ideas during the review of #455.
Vrs,SopClasses, and the character sets.registerCharacterSetregisters a decode function and an encode function. The writer encodes text in the declaredSpecificCharacterSet.The specification is in
docs/specs/registries.md(user requirements,REG-U-n). The implementation specification is indocs/specs/registries-implementation.md(REG-I-n).Changes
ReadBufferStream(buffer, options)andWriteBufferStream(options). The options arelittleEndian(defaulttrue),start,stop,noCopy,clearBuffers, anddefaultSize.ReadBufferStream. A positional call keeps the 0.x big-endian default. The shim logs one warning for each class.Vrsholds the VR instances, for exampleVrs.DS.registerVr(code, vr, flags?)adds a VR or replaces a VR. Each VR keeps its classification as properties. The old lists (singleVRs,BINARY_VRS) are now views ofVrs, with the same members.SopClassesmaps a name to a UID, for exampleSopClasses.CTImage.registerSopClass(name, uid)adds an entry.sopClassName(uid)gives the reverse lookup.DicomMetaDictionary.sopClassUIDsByNameandsopClassNamesByUIDstay plain objects, so property access still works.registerCharacterSet(term, { label, createDecoder, encode })adds aSpecificCharacterSetdefined term. The read path and the write path use the same registry.encodingMappingstays a plain object.writePart10,Part10Writer, andStreamingPart10Writerall use this behavior.ignoreErrors, the writer writes?.ISO_IR 100use the windows-1252 table, the same table as the read path. The specification gives the reason.docs/MIGRATION.mdlists the byte-order change of the constructors. It also lists the charset change of the 0.x-compatibleDicomDict.write()andDicomMessage.write().dcmjs.js) and from 1.06 to 1.062 (dcmjs.es.js).Tests
The full suite passes: 1269 tests pass and 12 tests are skipped. The new tests are in
test/core/registries.test.js.The API must do this:
ReadBufferStreamcall keepsstartandstop. A positional call keeps big endian. The options form uses little endian.registerVrmakes an unknown VR decode with the registered instance, without the "Invalid vr type" warning.SopClasses,registerSopClass, andDicomMetaDictionary.sopClassUIDsByName.Namegive the same UIDs.The user experience must have this:
ISO_IR 100writeséas the byte0xE9, and the read gives the same text. A number in an LO value also writes.writePart10andStreamingPart10Writer.ignoreErrors, the writer writes?.Known limits
DicomMessage.readFiledoes not give the character set of the dataset to sequence items. fix: decode text in sequence items with the dataset's SpecificCharacterSet #520 and fix: decode text in sequence items with the right SpecificCharacterSet (sync and async readers) #609 fix this problem.Related: #455, #454.
🤖 Generated with Claude Code