/// <summary>Outputs a debug version of a compressed segment</summary> public static StringBuilder DumpCompressed(Slice compressed, StringBuilder output = null) { if (output == null) output = new StringBuilder(); if (compressed.Count == 0) { output.Append("Empty bitmap [0 bytes]"); return output; } var reader = new SliceReader(compressed); output.Append(String.Format("Compressed [{0} bytes]:", compressed.Count)); uint header = reader.ReadFixed32(); int highestBit = (int)header; output.Append(String.Format(" {0} words", (compressed.Count >> 2) - 1)); uint p = 0; int i = 0; while(reader.Remaining >= 4) { uint word = reader.ReadFixed32(); if ((word & TYPE_MASK) == BIT_TYPE_LITERAL) { output.AppendFormat(", ({0}:{1}) 0x{2:X8}", i, p, word); p += 31; } else { uint len = (word & LENGTH_MASK) + 1; output.AppendFormat(", ({0}:{1}) {2} x {3}", i, p, ((word & FILL_MASK) >> FILL_SHIFT) == 0 ? "zero" : "one", len); p += len * 31; } i++; } output.Append(", MSB ").Append(highestBit); if (reader.Remaining > 0) { output.AppendLine(String.Format(", ERROR: {0} trailing byte(s)", reader.Remaining)); } return output; }
private static void CheckVersion(Slice value, bool writeAccess) { // the version is stored as 3 x 32-bit unsigned ints, so (1, 0, 0) will be "<01><00><00><00> <00><00><00><00> <00><00><00><00>" var reader = new SliceReader(value); var major = reader.ReadFixed32(); var minor = reader.ReadFixed32(); var upgrade = reader.ReadFixed32(); if (major > LayerVersion.Major) throw new InvalidOperationException(String.Format("Cannot load directory with version {0}.{1}.{2} using directory layer {3}", major, minor, upgrade, LayerVersion)); if (writeAccess && minor > LayerVersion.Minor) throw new InvalidOperationException(String.Format("Directory with version {0}.{1}.{2} is read-only when opened using directory layer {3}", major, minor, upgrade, LayerVersion)); }