private static PreambleStatus Read(DICOMBinaryReader dr) { bool mismatchPreamble123 = false; if (dr.StreamLength > 132) { byte[] nullPreamble = dr.Take(128); if (nullPreamble.Any(b => b != 0x00)) { mismatchPreamble123 = true; } //READ D I C M byte[] dcm = dr.Take(4); if (dcm[0] != 'D' || dcm[1] != 'I' || dcm[2] != 'C' || dcm[3] != 'M') { return(PreambleStatus.WrongPreambleDicm); } if (mismatchPreamble123) { return(PreambleStatus.MismatchPreamble128); } return(PreambleStatus.Ok); } return(PreambleStatus.None); }
private static PresentationContext ReadPresentationCtxContents(byte[] contents, bool requestType = false) { var pc = new PresentationContext(); pc.TransferSyntaxes = new List <string>(); using (var dr = new DICOMBinaryReader(contents)) { pc.Id = dr.Take(1)[0]; dr.Skip(1); //Reserved Null Byte pc.Reason = (PresentationContextReason)Enum.ToObject(typeof(PresentationContextReason), dr.Take(1)[0]); dr.Skip(1); //Reserved Null Byte if (requestType) { pc.AbstractSyntax = ReadAbstractSyntax(dr).Trim(); } while (dr.StreamPosition < dr.StreamLength) { var initPos = dr.StreamPosition; pc.TransferSyntaxes.Add(ReadTransferSyntax(dr)); if (dr.StreamPosition == initPos) { break; } } } return(pc); }
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 PDVItemFragment ReadPDVFragment(DICOMBinaryReader dr, int length) { var pif = new PDVItemFragment(); var messageHeader = dr.Take(1)[0]; pif.IsCommandObject = messageHeader.GetBit(0); pif.IsLastItem = messageHeader.GetBit(1); pif.Data = dr.ReadBytes(length - 1); return(pif); }