/// <summary> /// Decodes the escher stream from a byte array and dumps the results to /// a print stream. /// </summary> /// <param name="data">The data array containing the escher records.</param> /// <param name="offset">The starting offset within the data array.</param> /// <param name="size">The number of bytes to Read.</param> public void Dump(byte[] data, int offset, int size) { EscherRecordFactory recordFactory = new DefaultEscherRecordFactory(); int pos = offset; while (pos < offset + size) { EscherRecord r = recordFactory.CreateRecord(data, pos); int bytesRead = r.FillFields(data, pos, recordFactory); Console.WriteLine(r.ToString()); pos += bytesRead; } }
/// <summary> /// The contract of this method is to deSerialize an escher record including /// it's children. /// </summary> /// <param name="data">The byte array containing the Serialized escher /// records.</param> /// <param name="offset">The offset into the byte array.</param> /// <param name="recordFactory">A factory for creating new escher records</param> /// <returns>The number of bytes written.</returns> public override int FillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesRemaining = ReadHeader(data, offset); int bytesWritten = 8; offset += 8; while (bytesRemaining > 0 && offset < data.Length) { EscherRecord child = recordFactory.CreateRecord(data, offset); int childBytesWritten = child.FillFields(data, offset, recordFactory); bytesWritten += childBytesWritten; offset += childBytesWritten; bytesRemaining -= childBytesWritten; AddChildRecord(child); if (offset >= data.Length && bytesRemaining > 0) { Console.WriteLine("WARNING: " + bytesRemaining + " bytes remaining but no space left"); } } return(bytesWritten); }
/// <summary> /// This method deSerializes the record from a byte array. /// </summary> /// <param name="data"> The byte array containing the escher record information</param> /// <param name="offset">The starting offset into data </param> /// <param name="recordFactory">May be null since this is not a container record.</param> /// <returns>The number of bytes Read from the byte array.</returns> public override int FillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesRemaining = ReadHeader(data, offset); /* * Modified by Zhang Zhang * Have a check between avaliable bytes and bytesRemaining, * take the avaliable length if the bytesRemaining out of range. * July 09, 2010 */ int avaliable = data.Length - (offset + 8); if (bytesRemaining > avaliable) { bytesRemaining = avaliable; } if (IsContainerRecord) { int bytesWritten = 0; thedata = new byte[0]; offset += 8; bytesWritten += 8; while (bytesRemaining > 0) { EscherRecord child = recordFactory.CreateRecord(data, offset); int childBytesWritten = child.FillFields(data, offset, recordFactory); bytesWritten += childBytesWritten; offset += childBytesWritten; bytesRemaining -= childBytesWritten; ChildRecords.Add(child); } return(bytesWritten); } else { thedata = new byte[bytesRemaining]; Array.Copy(data, offset + 8, thedata, 0, bytesRemaining); return(bytesRemaining + 8); } }