def encode_element(elem, is_implicit_vr=True, is_little_endian=True): """Encode a *pydicom* :class:`~pydicom.dataelem.DataElement` `elem`. .. deprecated:: 1.5 Will be removed in version 2.0, use *pydicom* instead. Parameters ---------- elem : pydicom.dataelem.DataElement The element to encode. is_implicit_vr : bool, optional The element encoding scheme the element will be encoded with, ``True`` for implicit VR (default), ``False`` for explicit VR. is_little_endian : bool, optional The byte ordering the element will be encoded in, ``True`` for little endian (default), ``False`` for big endian. Returns ------- bytes The encoded element. """ fp = DicomBytesIO() fp.is_implicit_VR = is_implicit_vr fp.is_little_endian = is_little_endian write_data_element(fp, elem) bytestring = fp.parent.getvalue() fp.close() return bytestring
def encode_element(elem, is_implicit_vr=True, is_little_endian=True): """Encode a pydicom DataElement `elem` to a byte stream. The default is to encode the element as implicit VR little endian. Parameters ---------- elem : pydicom.dataelem.DataElement The element to encode is_implicit_vr : bool, optional The element encoding scheme the element will be encoded with, default is True. is_little_endian : bool, optional The byte ordering the element will be encoded in, default is True. Returns ------- bytes The encoded element. """ fp = DicomBytesIO() fp.is_implicit_VR = is_implicit_vr fp.is_little_endian = is_little_endian write_data_element(fp, elem) bytestring = fp.parent.getvalue() fp.close() return bytestring
def encode_element(el, is_implicit_VR, is_little_endian): f = DicomBytesIO() f.is_implicit_VR = is_implicit_VR f.is_little_endian = is_little_endian write_data_element(f, el) rawstr = f.parent.getvalue() f.close() return rawstr
def test_empty_AT(self): """Write empty AT correctly..........""" # Was issue 74 data_elem = DataElement(0x00280009, "AT", []) expected = hex2bytes(( " 28 00 09 00" # (0028,0009) Frame Increment Pointer " 00 00 00 00" # length 0 )) write_data_element(self.f1, data_elem) got = self.f1.parent.getvalue() msg = ("Did not write zero-length AT value correctly. " "Expected %r, got %r") % (bytes2hex(expected), bytes2hex(got)) msg = "%r %r" % (type(expected), type(got)) msg = "'%r' '%r'" % (expected, got) self.assertEqual(expected, got, msg)
def encode_element(elem, is_implicit_VR=True, is_little_endian=True): """Return the encoded `elem`. Parameters ---------- elem : pydicom.dataelem.DataElement The element to encode is_implicit_VR : bool Encode using implicit VR, default True is_little_endian : bool Encode using little endian, default True Returns ------- str or bytes The encoded element as str (python2) or bytes (python3) """ with DicomBytesIO() as fp: fp.is_implicit_VR = is_implicit_VR fp.is_little_endian = is_little_endian write_data_element(fp, elem) return fp.parent.getvalue()