Decoder_new, /* tp_new */
};
+void
+_hexwrite(unsigned char*s, size_t l) {
+ for (size_t i = 0; i < l; i++)
+ printf("%.2x", s[i]);
+}
+
PyObject*
test_from_agl() {
- unsigned char b1c[8], b2c[8];
- unsigned char b1[8], b2[8], b3[8], b4[8], b5[8];
- memset(b1, 1, 8);
- memset(b2, 2, 8);
- memset(b3, 3, 8);
- const unsigned char *blocks[3] = {b1, b2, b3};
- unsigned char *outblocks[2] = {b4, b5};
+ unsigned char b0c[8], b1c[8];
+ unsigned char b0[8], b1[8], b2[8], b3[8], b4[8];
+ memset(b0, 1, 8);
+ memset(b1, 2, 8);
+ memset(b2, 3, 8);
+ const unsigned char *blocks[3] = {b0, b1, b2};
+ unsigned char *outblocks[2] = {b3, b4};
unsigned block_nums[] = {3, 4};
+ /*printf("_from_c before encoding:\n");
+ printf("b0: "); _hexwrite(b0, 8); printf(", ");
+ printf("b1: "); _hexwrite(b1, 8); printf(", ");
+ printf("b2: "); _hexwrite(b2, 8); printf(", ");
+ printf("\n");*/
+
fec_t *const fec = fec_new(3, 5);
fec_encode(fec, blocks, outblocks, block_nums, 2, 8);
- write(1, b1, 8);
- write(1, b2, 8);
- write(1, b3, 8);
- write(1, b4, 8);
- write(1, b5, 8);
+ /*printf("after encoding:\n");
+ printf("b3: "); _hexwrite(b3, 8); printf(", ");
+ printf("b4: "); _hexwrite(b4, 8); printf(", ");
+ printf("\n");*/
- memcpy(b1c, b1, 8); memcpy(b2c, b2, 8);
+ memcpy(b0c, b0, 8); memcpy(b1c, b1, 8);
- const unsigned char *inpkts[] = {b3, b4, b5};
- unsigned char *outpkts[] = {b1, b2};
- unsigned indexes[] = {2, 3, 4};
+ const unsigned char *inpkts[] = {b3, b4, b2};
+ unsigned char *outpkts[] = {b0, b1};
+ unsigned indexes[] = {3, 4, 2};
fec_decode(fec, inpkts, outpkts, indexes, 8);
- write(1, b1, 8);
- write(1, b2, 8);
+ /*printf("after decoding:\n");
+ printf("b0: "); _hexwrite(b0, 8); printf(", ");
+ printf("b1: "); _hexwrite(b1, 8);
+ printf("\n");*/
- if ((memcmp(b1, b1c,8) == 0) && (memcmp(b2, b2c,8) == 0))
+ if ((memcmp(b0, b0c,8) == 0) && (memcmp(b1, b1c,8) == 0))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
* @param fecs buffers into which the secondary blocks will be written
* @param block_nums the numbers of the desired check blocks (the id >= k) which fec_encode() will produce and store into the buffers of the fecs parameter
* @param num_block_nums the length of the block_nums array
+ * @param sz size of a packet in bytes
*/
void fec_encode(const fec_t* code, const gf*restrict const*restrict const src, gf*restrict const*restrict const fecs, const unsigned*restrict const block_nums, size_t num_block_nums, size_t sz);
/**
- * @param inpkts an array of packets (size k)
+ * @param inpkts an array of packets (size k); If the block whose number is i is present, then it is required to be in the i'th element.
* @param outpkts an array of buffers into which the reconstructed output packets will be written (only packets which are not present in the inpkts input will be reconstructed and written to outpkts)
* @param index an array of the blocknums of the packets in inpkts
* @param sz size of a packet in bytes
def test_from_agl_py(self):
e = zfec.Encoder(3, 5)
- b1 = '\x01'*8 ; b2 = '\x02'*8 ; b3 = '\x03'*8
- b4, b5 = e.encode([b1, b2, b3], (3, 4))
+ b0 = '\x01'*8 ; b1 = '\x02'*8 ; b2 = '\x03'*8
+ # print "_from_py before encoding:"
+ # print "b0: %s, b1: %s, b2: %s" % tuple(base64.b16encode(x) for x in [b0, b1, b2])
+
+ b3, b4 = e.encode([b0, b1, b2], (3, 4))
+ # print "after encoding:"
+ # print "b3: %s, b4: %s" % tuple(base64.b16encode(x) for x in [b3, b4])
+
d = zfec.Decoder(3, 5)
- resblocks = d.decode((b3, b4, b5), (2, 3, 4))
+ r0, r1, r2 = d.decode((b2, b3, b4), (1, 2, 3))
- print "b1: %r, b2: %r, b3: %r, b4: %r, b5: %r, resblocks: %r" % (b1, b2, b3, b4, b5, resblocks)
+ # print "after decoding:"
+ # print "b0: %s, b1: %s" % tuple(base64.b16encode(x) for x in [b0, b1])
def test_small(self):
for i in range(16):