/decoders/binary/par2.d

http://github.com/wilkie/djehuty · D · 85 lines · 41 code · 20 blank · 24 comment · 2 complexity · 2b2815a6394b2f4ce9d7cd3c2cd69647 MD5 · raw file

  1. /*
  2. * par2.d
  3. *
  4. * This module implements the par2 standard, which describes parity volume
  5. * sets.
  6. *
  7. * Author: Dave Wilkinson
  8. * Originated: June 9th, 2009
  9. * References: http://www.par2.net/par2spec.php
  10. *
  11. */
  12. module decoders.binary.par2;
  13. import core.stream;
  14. import decoders.binary.codec;
  15. private {
  16. // States
  17. enum {
  18. PAR2_STATE_INIT,
  19. }
  20. align(4) struct Par2PacketHeader {
  21. ubyte[8] magic; // Magic Sequence
  22. ulong length; // Length of packet
  23. ulong[2] hash; // 16 byte MD5 hash
  24. ulong[2] recoverySetID; // 16 byte set ID
  25. ubyte[16] type; // can be "anything"
  26. // Body follows, aligned by 4 bytes
  27. }
  28. align(4) struct MainPacket {
  29. ulong sliceSize; // must be a multiple of 4
  30. uint numFiles; // number of files in recovery set
  31. // Followed by dynamic list of file IDs (16 byte MD5 hashes)
  32. // and following that a dynamic list of file IDs (again hashes)
  33. // for the non-recovery set.
  34. }
  35. align(4) struct FileDescriptorPacket {
  36. ulong[2] id; // 16 byte MD5 hash
  37. ulong[2] hash; // 16 byte MD5 hash
  38. ulong[2] subHash; // 16 byte MD5 hash of first 16kB of file
  39. ulong length; // length of file
  40. // Name (in ASCII) follows
  41. }
  42. align(4) struct SliceChecksumPacket {
  43. ulong[2] fileID; // 16 byte MD5 hash
  44. // An array of hashes and crc32 pairs follow for the slices of the
  45. // file. The HASH/CRC pairs are in the same order as their
  46. // respective slices in the file.
  47. }
  48. align(4) struct RecoverySlicePacket {
  49. uint exponent; // exponent used to generate recovery data
  50. // Follows is a byte array aligned to 4 that contains the
  51. // recovery data
  52. }
  53. }
  54. // Section: Codecs/Binary
  55. // Description: This represents the Par2 Codec.
  56. class Par2Decoder : BinaryDecoder {
  57. StreamData decode(Stream stream, Stream toStream) {
  58. for (;;) {
  59. switch (decoderState) {
  60. default: return StreamData.Invalid;
  61. }
  62. }
  63. return StreamData.Invalid;
  64. }
  65. }