PageRenderTime 27ms CodeModel.GetById 12ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/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
13module decoders.binary.par2;
14
15import core.stream;
16
17import decoders.binary.codec;
18
19private {
20
21	// States
22	enum {
23		PAR2_STATE_INIT,
24	}
25	
26	align(4) struct Par2PacketHeader {
27		ubyte[8] magic;			// Magic Sequence
28		ulong length;			// Length of packet
29		ulong[2] hash;			// 16 byte MD5 hash
30		ulong[2] recoverySetID;	// 16 byte set ID
31		ubyte[16] type;			// can be "anything"
32
33		// Body follows, aligned by 4 bytes
34	}
35
36	align(4) struct MainPacket {
37		ulong sliceSize;		// must be a multiple of 4
38		uint numFiles;			// number of files in recovery set
39
40		// Followed by dynamic list of file IDs (16 byte MD5 hashes)
41		// and following that a dynamic list of file IDs (again hashes)
42		// for the non-recovery set.
43	}
44
45	align(4) struct FileDescriptorPacket {
46		ulong[2] id;		// 16 byte MD5 hash
47		ulong[2] hash;		// 16 byte MD5 hash
48		ulong[2] subHash;	// 16 byte MD5 hash of first 16kB of file
49		ulong length;		// length of file
50
51		// Name (in ASCII) follows
52	}
53	
54	align(4) struct SliceChecksumPacket {
55		ulong[2] fileID;	// 16 byte MD5 hash
56		
57		// An array of hashes and crc32 pairs follow for the slices of the
58		// file. The HASH/CRC pairs are in the same order as their
59		// respective slices in the file.
60	}
61	
62	align(4) struct RecoverySlicePacket {
63		uint exponent;		// exponent used to generate recovery data
64		
65		// Follows is a byte array aligned to 4 that contains the
66		// recovery data
67	}
68}
69
70// Section: Codecs/Binary
71
72// Description: This represents the Par2 Codec.
73class Par2Decoder : BinaryDecoder {
74
75	StreamData decode(Stream stream, Stream toStream) {
76
77		for (;;) {
78			switch (decoderState) {
79				default: return StreamData.Invalid;
80			}
81		}
82
83		return StreamData.Invalid;
84	}
85}