func ReadChunk(bread *bytes.Reader, offset int64) (SiemensChunk, int64) {
	out := SiemensChunk{}

	// Most words are 4 bytes
	word := make([]byte, 4)

	// Read the element name. 64 bytes, ignore after the first 0x00
	eword := make([]byte, 64)
	bread.ReadAt(eword, offset)
	offset += int64(len(eword))

	// Eliminate data from the name that comes after the first 0x00

	// fmt.Println(string(eword))
	wp := bytes.Split(eword, []byte{0x00})
	// fmt.Println(string(wp[0]))

	out.Name = string(wp[0])

	// Next, read the info about this name:

	// VM
	bread.ReadAt(word, offset)
	offset += 4
	out.VM = binary.LittleEndian.Uint32(word)

	// VR
	bread.ReadAt(word, offset)
	offset += 4
	out.VR = string(bytes.Split(word, []byte{0x00})[0])

	// syngo dt
	bread.ReadAt(word, offset)
	offset += 4
	out.SyngoDT = binary.LittleEndian.Uint32(word)

	// subelement count
	bread.ReadAt(word, offset)
	offset += 4
	out.Subelements = binary.LittleEndian.Uint32(word)

	// Next is another delim. No need to read since we don't use it, but do need
	// to increment the offset.

	// bread.ReadAt(word, offset)
	// if bytes.Equal(word, SiemensDelimiter) || bytes.Equal(word, SiemensDelimiter2) {
	// }
	offset += 4

	// Iterate over the subelements
	for i := 0; i < int(out.Subelements); i++ {
		// Always 16 bytes. The first 4, second 4, and fourth 4 are equal to one
		// another, and signify the number of bytes that correspond to the data
		// in this subelement. The third 4 bytes are always a delimiter(!). So,
		// read the first 4 bytes, treat them as a 32-bit little-endian integer,
		// and increment the offset by 16.
		bread.ReadAt(word, offset)
		offset += 16

		// This subelement has dataLen bytes to be read
		dataLen := binary.LittleEndian.Uint32(word)

		dword := make([]byte, dataLen)
		bread.ReadAt(dword, offset)
		offset += int64(len(dword))

		// The data fields are always padded out to the nearest 4-byte boundary.
		// So, e.g., if we have 9 bytes of data, we will read out 3 more bytes
		// so we are padded out to 12 bytes. (Don't actually need to read out
		// the bytes - just need to advance the offset)
		if modulus := dataLen % 4; modulus != 0 {
			fixOffset := 4 - modulus
			// bread.ReadAt(make([]byte, fixOffset), offset)
			offset += int64(fixOffset)
		}

		if dataLen > 0 {
			out.SubElementData = append(out.SubElementData, string(bytes.Split(dword, []byte{0x00})[0]))
			// noNullDword := bytes.Split(dword, []byte{0x00})
			// out.SubElementData = append(out.SubElementData, string(noNullDword[0]))
		}
	}

	return out, offset
}
// ReadChunk reads a named element and any subelements from the Siemens header.
ReadChunk reads a named element and any subelements from the Siemens header.
// ReadChunk reads a named element and any subelements from the Siemens header .
func ReadChunk(bread *bytes.Reader, offset int64) (SiemensChunk, int64) {
	out := SiemensChunk{}
	word := make([]byte, 4)
	eword := make([]byte, 64)
	bread.ReadAt(eword, offset)
	offset += int64(len(eword))
	wp := bytes.Split(eword, []byte{0x00})
	out.Name = string(wp[0])
	bread.ReadAt(word, offset)
	offset += 4
	out.VM = binary.LittleEndian.Uint32(word)
	bread.ReadAt(word, offset)
	offset += 4
	out.VR = string(bytes.Split(word, []byte{0x00})[0])
	bread.ReadAt(word, offset)
	offset += 4
	out.SyngoDT = binary.LittleEndian.Uint32(word)
	bread.ReadAt(word, offset)
	offset += 4
	out.Subelements = binary.LittleEndian.Uint32(word)
	offset += 4
	for i := 0; i < int(out.Subelements); i++ {
		bread.ReadAt(word, offset)
		offset += 16
		dataLen := binary.LittleEndian.Uint32(word)
		dword := make([]byte, dataLen)
		bread.ReadAt(dword, offset)
		offset += int64(len(dword))
		if modulus := dataLen % 4; modulus != 0 {
			fixOffset := 4 - modulus
			offset += int64(fixOffset)
		}
		if dataLen > 0 {
			out.SubElementData = append(out.SubElementData, string(bytes.Split(dword, []byte{0x00})[0]))
		}
	}
	return out, offset
}
func ReadChunk ( bread * bytes . Reader , offset int64 ) ( SiemensChunk , int64 ) { out := SiemensChunk { } word := make ( [ ] byte , 4 ) eword := make ( [ ] byte , 64 ) bread . ReadAt ( eword , offset ) offset += int64 ( len ( eword ) ) wp := bytes . Split ( eword , [ ] byte { 0x00 } ) out . Name = string ( wp [ 0 ] ) bread . ReadAt ( word , offset ) offset += 4 out . VM = binary . LittleEndian . Uint32 ( word ) bread . ReadAt ( word , offset ) offset += 4 out . VR = string ( bytes . Split ( word , [ ] byte { 0x00 } ) [ 0 ] ) bread . ReadAt ( word , offset ) offset += 4 out . SyngoDT = binary . LittleEndian . Uint32 ( word ) bread . ReadAt ( word , offset ) offset += 4 out . Subelements = binary . LittleEndian . Uint32 ( word ) offset += 4 for i := 0 ; i < int ( out . Subelements ) ; i ++ { bread . ReadAt ( word , offset ) offset += 16 dataLen := binary . LittleEndian . Uint32 ( word ) dword := make ( [ ] byte , dataLen ) bread . ReadAt ( dword , offset ) offset += int64 ( len ( dword ) ) if modulus := dataLen % 4 ; modulus != 0 { fixOffset := 4 - modulus offset += int64 ( fixOffset ) } if dataLen > 0 { out . SubElementData = append ( out . SubElementData , string ( bytes . Split ( dword , [ ] byte { 0x00 } ) [ 0 ] ) ) } } return out , offset }
ReadChunk reads a named element and any subelements from the Siemens header.
ReadChunk reads a named element and any subelements from the Siemens header .
// Most words are 4 bytes // Read the element name. 64 bytes, ignore after the first 0x00 // Eliminate data from the name that comes after the first 0x00 // fmt.Println(string(eword)) // fmt.Println(string(wp[0])) // Next, read the info about this name: // VM // VR // syngo dt // subelement count // Next is another delim. No need to read since we don't use it, but do need // to increment the offset. // bread.ReadAt(word, offset) // if bytes.Equal(word, SiemensDelimiter) || bytes.Equal(word, SiemensDelimiter2) { // } // Iterate over the subelements // Always 16 bytes. The first 4, second 4, and fourth 4 are equal to one // another, and signify the number of bytes that correspond to the data // in this subelement. The third 4 bytes are always a delimiter(!). So, // read the first 4 bytes, treat them as a 32-bit little-endian integer, // and increment the offset by 16. // This subelement has dataLen bytes to be read // The data fields are always padded out to the nearest 4-byte boundary. // So, e.g., if we have 9 bytes of data, we will read out 3 more bytes // so we are padded out to 12 bytes. (Don't actually need to read out // the bytes - just need to advance the offset) // bread.ReadAt(make([]byte, fixOffset), offset) // noNullDword := bytes.Split(dword, []byte{0x00}) // out.SubElementData = append(out.SubElementData, string(noNullDword[0]))