public static Message <Request> ReadAssociationRequest(NetworkBinaryReader dr) { var rq = new Request(); rq.PresentationContexts = new List <PresentationContext>(); dr.Skip(1); //PDU ID and Reserved Null Byte int length = LengthReader.ReadBigEndian(dr.Take(4)); using (DICOMBinaryReader sub = dr.GetSubStream(length)) { rq.ProtocolVersion = LengthReader.ReadBigEndian(sub, 2); sub.Skip(2); //Reserved Null Bytes rq.CalledEntityTitle = sub.ReadString(16).Trim(); rq.CallingEntityTitle = sub.ReadString(16).Trim(); sub.Skip(32); //Reserved Null Bytes rq.ApplicationContext = ItemReader.ReadApplicationContext(sub); while (sub.Peek(1)[0] == (byte)ItemType.PRESENTATION_CONTEXT_REQUEST) { PresentationContext context = ItemReader.ReadPresentationCtxRequest(sub); rq.PresentationContexts.Add(context); } rq.UserInfo = ItemReader.ReadUserInfo(sub); } return(new Message <Request> { Payload = rq, Type = MessageType.PDU }); }
public static Message <PDataTF> ReadPDFData(NetworkBinaryReader dr, bool firstByteRead = false, int i = 0) { PDataTF pdata = null; pdata = new PDataTF(); if (!firstByteRead) { dr.Skip(1); } dr.Skip(1); // PDU ID and Reserved Null Byte var lengthBytes = dr.Take(4); int length = LengthReader.ReadBigEndian(lengthBytes); using (DICOMBinaryReader dbr = dr.GetSubStream(length)) { while (dbr.StreamPosition < dbr.StreamLength) { PDVItem item = ItemReader.ReadPDVItem(dbr); pdata.Items.Add(item); } } return(new Message <PDataTF> { Payload = pdata, Type = MessageType.PDATA_TF }); }
public void WriteBigEndianLength3() { var len = 10; byte[] bytes; using (var ms = new MemoryStream()) { var dw = new DICOMBinaryWriter(ms); VR vr = VR.CodeString; DICOMIOSettings settings = new DICOMIOSettings() { TransferSyntax = TransferSyntax.EXPLICIT_VR_BIG_ENDIAN, DoWriteIndefiniteSequences = false }; var data = new byte[10]; LengthWriter.Write(dw, vr, settings, data != null ? data.Length : 0); bytes = ms.ToArray(); } var read = LengthReader.ReadLittleEndian(bytes); Assert.AreNotEqual(len, read); read = LengthReader.ReadBigEndian(bytes); Assert.AreEqual(len, read); }
public static Message <Accept> ReadAssociationAccept(NetworkBinaryReader dr) { var acc = new Accept(); acc.PresentationContexts = new List <PresentationContext>(); dr.Skip(1); //PDU ID and Reserved Null Byte int length = LengthReader.ReadBigEndian(dr.Take(4)); using (DICOMBinaryReader sub = dr.GetSubStream(length)) { acc.ProtocolVersion = LengthReader.ReadBigEndian(sub, 2); sub.Skip(2); //Reserved Null Bytes acc.CalledEntityTitle = sub.ReadString(16).Trim(); acc.CallingEntityTitle = sub.ReadString(16).Trim(); sub.Skip(32); //Reserved Null Bytes acc.ApplicationContext = ItemReader.ReadApplicationContext(sub); while (sub.Peek(1).First() == (byte)ItemType.PRESENTATION_CONTEXT_ACCEPT) { PresentationContext context = ItemReader.ReadPresentationCtxAccept(sub); if (context != null) { acc.PresentationContexts.Add(context); } } acc.UserInfo = ItemReader.ReadUserInfo(sub); } return(new Message <Accept> { Payload = acc, Type = MessageType.PDU }); }
public static int?ReadMaxLength(DICOMBinaryReader dr) { AssertItemType(dr, "Maximum Length", ItemType.MAXIMUM_LENGTH); dr.Skip(2); // PDU ID and Reserved Null Byte var length = LengthReader.ReadBigEndian(dr, 2); return(LengthReader.ReadBigEndian(dr, 4)); }
private static string ReadUIDItem(DICOMBinaryReader dr, string itemName, ItemType iType) { AssertItemType(dr, itemName, iType); dr.Skip(2); // PDU ID and Reserved Null Byte var length = LengthReader.ReadBigEndian(dr, 2); return(dr.ReadString(length).Trim()); }
public static PresentationContext ReadPresentationCtxAccept(DICOMBinaryReader dr) { AssertItemType(dr, "Presentation Context Accept", ItemType.PRESENTATION_CONTEXT_ACCEPT); dr.Skip(2); // PDU id Reserved Null Byte var length = LengthReader.ReadBigEndian(dr, 2); return(ReadPresentationCtxContents(dr.Take(length))); }
public static PresentationContext ReadPresentationCtxRequest(DICOMBinaryReader dr) { AssertItemType(dr, "Presentation Context Request", ItemType.PRESENTATION_CONTEXT_REQUEST); dr.Skip(2); // PDU id Reserved Null Byte int length = LengthReader.ReadBigEndian(dr, 2); return(ReadPresentationCtxContents(dr.Take(length), true)); }
public static PDVItem ReadPDVItem(DICOMBinaryReader dr) { var pi = new PDVItem(); var length = LengthReader.ReadBigEndian(dr, 4); pi.PresentationContextID = dr.Take(1)[0]; pi.Fragment = ReadPDVFragment(dr, length - 1); return(pi); }
public static AsyncOperations ReadAsyncOperations(DICOMBinaryReader dr) { AssertItemType(dr, "Async Operations", ItemType.ASYNCHRONOUS_OPERATIONS_WINDOW); var ao = new AsyncOperations(); dr.Skip(2); // // PDU ID and Reserved Null Byte var length = LengthReader.ReadBigEndian(dr, 2); ao.MaxInvokeOperations = LengthReader.ReadBigEndian(dr, 2); ao.MaxPerformOperations = LengthReader.ReadBigEndian(dr, 2); return(ao); }
public static UserInfo ReadUserInfo(DICOMBinaryReader dr) { AssertItemType(dr, "User Info", ItemType.USER_INFO); var ui = new UserInfo(); dr.Skip(2); // PDU ID and Reserved Null Byte var length = LengthReader.ReadBigEndian(dr, 2); if (length > 0) { ui.MaxPDULength = (int)ReadMaxLength(dr); if (dr.StreamPosition >= dr.StreamLength) { return(ui); } ui.ImplementationUID = ReadImplementationClassUID(dr); if (dr.StreamPosition >= dr.StreamLength) { return(ui); } if (dr.Peek(1)[0] == (byte)ItemType.ASYNCHRONOUS_OPERATIONS_WINDOW) { ui.AsynchronousOperations = ReadAsyncOperations(dr); } if (dr.StreamPosition >= dr.StreamLength) { return(ui); } if (dr.Peek(1)[0] == (byte)ItemType.IMPLEMENTATION_VERSION_NAME) { ui.ImplementationVersion = ReadImplementationVersion(dr); } if (dr.StreamPosition >= dr.StreamLength) { return(ui); } if (dr.Peek(1)[0] == (byte)ItemType.SCPSCU_ROLE_SELECTION) { ui.ImplementationVersion = ReadSCPSCURoleSelection(dr); } } return(ui); }
public void WriteBigEndianLength2() { var len = 2500; byte[] bytes; using (var ms = new MemoryStream()) { var dw = new DICOMBinaryWriter(ms); LengthWriter.WriteBigEndian(dw, len, 2); bytes = ms.ToArray(); } var read = LengthReader.ReadLittleEndian(bytes); Assert.AreNotEqual(len, read); read = LengthReader.ReadBigEndian(bytes); Assert.AreEqual(len, read); }
public static UserInfo ReadUserInfo(DICOMBinaryReader dr) { AssertItemType(dr, "User Info", ItemType.USER_INFO); var ui = new UserInfo(); dr.Skip(2); // PDU ID and Reserved Null Byte var length = LengthReader.ReadBigEndian(dr, 2); if (length > 0) { ui.MaxPDULength = (int)ReadMaxLength(dr); ui.ImplementationUID = ReadImplementationClassUID(dr); if (dr.Peek(1)[0] == (byte)ItemType.ASYNCHRONOUS_OPERATIONS_WINDOW) { ui.AsynchronousOperations = ReadAsyncOperations(dr); } ui.ImplementationVersion = ReadImplementationVersion(dr); } return(ui); }