/// <summary> /// Expect the upcoming 4 bytes are int32, read it and return it; /// </summary> public static uint ExpectUInt32(this Stream target) { var buff = new byte[4]; if (target.Read(buff) == 4) { return(LittleEndianByteOrderHelper.GetUInt32(buff)); } else { throw new EndOfStreamException(); } }
uint ReadUInt32FromTrailingContent(IBlock block) { var buffer = new byte[4]; var contentLength = block.GetHeader(kBlockContentLength); if ((contentLength % 4) != 0) { throw new DataMisalignedException("Block content length not %4: " + contentLength); } if (contentLength == 0) { throw new InvalidDataException("Trying to dequeue UInt32 from an empty block"); } block.Read(dst: buffer, dstOffset: 0, srcOffset: (int)contentLength - 4, count: 4); return(LittleEndianByteOrderHelper.GetUInt32(buffer)); }