-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodec.go
More file actions
42 lines (38 loc) · 1.96 KB
/
Copy pathcodec.go
File metadata and controls
42 lines (38 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package godicom
// codecContext is the encoding state a value codec needs to turn bytes into
// values or back: how the bytes are laid out, and how text in them is spelled.
//
// These travelled the write chain as three separate parameters. That cost two
// things worth fixing. The two bools are adjacent and interchangeable, so
// transposing them at a call site compiles and silently writes a file in the
// wrong encoding. And every new piece of codec state -- a validation policy, a
// character-set fallback -- had to be threaded through every signature between
// writeDataset and the leaf that needed it.
//
// Not everything the read path carries around belongs here. State that has to
// outlive the parse lives on readContext instead, which is what a Dataset retains:
// the data dictionary in effect is there rather than here because a deferred load
// re-resolves an element's VR long after the codecContext it was first read under
// is gone.
//
// EncodingInfo is embedded rather than restated field by field: it is already
// the type for the implicit-VR/endianness pair, and it is what a Dataset stores
// its own encoding in.
type codecContext struct {
EncodingInfo
// Charsets is the SpecificCharacterSet in effect at this point. A sequence
// item inherits its parent's, and a (0008,0005) element changes it for
// everything after it in the same dataset, so this is per-nesting-level
// state -- unlike readContext, which spans a whole parse.
Charsets []string
}
// fileMetaCodec is the encoding PS3.10 fixes for File Meta Information:
// Explicit VR Little Endian, with no SpecificCharacterSet, since group 0x0002
// holds no VR whose meaning a character set could change.
var fileMetaCodec = codecContext{EncodingInfo: EncodingInfo{IsLittleEndian: true}}
// withCharsets returns cc with a different SpecificCharacterSet in effect, for
// crossing a (0008,0005) element.
func (cc codecContext) withCharsets(charsets []string) codecContext {
cc.Charsets = charsets
return cc
}