Esempio n. 1
0
int 
compress (uint8_t *out, const uint8_t *blocks[], 
  size_t blocks_to_comp, struct comp_options *opts)
{
  switch (opts->comb) {
    case COMB__HASH:
      return compress_hash (out, blocks, blocks_to_comp, opts->comp);
    case COMB__XOR:
      return compress_xor (out, blocks, blocks_to_comp, opts->comp);
    default:
      return ERROR_INVALID_COMPRESSION_METHOD;
  }
}
Esempio n. 2
0
static int 
compress_xor (uint8_t *out, const uint8_t *blocks[], size_t blocks_to_comp,
    enum comp_method comp)
{
  // XOR
  const uint16_t block_size = compress_block_size (comp);
  uint8_t buf[block_size];
  memset (buf, 0, sizeof (buf));
  for (unsigned int i = 1; i < blocks_to_comp; i++) {
    xor_block_self (buf, blocks[i], block_size);
  }

  const uint8_t *to_hash[2] = { blocks[0], buf };
  return compress_hash (out, to_hash, 2, comp);
}
Esempio n. 3
0
 void
 node::store (std::ostream &os, node_ptr const &root, bool text)
 {
   compress_hash ();
   NodeList list;
   list.set_root (root->index () + 1);
   foreach (node *n, nodes)
     {
       Node &sn = *list.add_node ();
       sn.set_index (n->index () + 1);
       store_loc (*sn.mutable_loc (), n->loc);
       if (generic_node *p = n->is<generic_node> ())
         {
           GenericNode &list = *sn.mutable_node ();
           list.set_type (p->type);
           foreach (node_ptr const &c, p->list)
             if (c)
               list.add_child (c->index () + 1);
             else
               list.add_child (0);
         }