Statistics
| Branch: | Revision:

grapes / som / Tests / chunk_encoding_test.c @ 8ab58ec7

History | View | Annotate | Download (1.43 KB)

1
/*
2
 *  Copyright (c) 2009 Luca Abeni
3
 *
4
 *  This is free software; see gpl-3.0.txt
5
 */
6

    
7
#include <stdint.h>
8
#include <stdio.h>
9
#include <string.h>
10
#include "chunk.h"
11
#include "trade_msg_la.h"
12

    
13
static void chunk_print(FILE *f, const struct chunk *c)
14
{
15
  const uint8_t *p;
16

    
17
  fprintf(f, "Chunk %d:\n", c->id);
18
  fprintf(f, "\tTS: %llu\n", c->timestamp);
19
  fprintf(f, "\tPayload size: %d\n", c->size);
20
  fprintf(f, "\tAttributes size: %d\n", c->attributes_size);
21
  p = c->data;
22
  fprintf(f, "\tPayload:\n");
23
  fprintf(f, "\t\t%c %c %c %c ...:\n", p[0], p[1], p[2], p[3]);
24
  if (c->attributes_size > 0) {
25
    p = c->attributes;
26
    fprintf(f, "\tAttributes:\n");
27
    fprintf(f, "\t\t%c %c %c %c ...:\n", p[0], p[1], p[2], p[3]);
28
  }
29
}
30

    
31
int main(int argc, char *argv[])
32
{
33
  struct chunk src_c;
34
  struct chunk dst_c;
35
  uint8_t buff[100];
36
  int res;
37

    
38
  src_c.id = 666;
39
  src_c.timestamp = 1000000000ULL;
40
  src_c.size = strlen("ciao") + 1;
41
  src_c.data = (uint8_t *)"ciao";
42
  src_c.attributes_size = 0;
43

    
44
  chunk_print(stdout, &src_c);
45

    
46
  res = encodeChunk(&src_c, buff, 15);
47
  fprintf(stdout, "Encoding in 15 bytes: %d\n", res);
48
  res = encodeChunk(&src_c, buff, 23);
49
  fprintf(stdout, "Encoding in 23 bytes: %d\n", res);
50
  res = encodeChunk(&src_c, buff, sizeof(buff));
51
  fprintf(stdout, "Encoding in %d bytes: %d\n", sizeof(buff), res);
52

    
53
  res = decodeChunk(&dst_c, buff, res);
54
  fprintf(stdout, "Decoding it: %d\n", res);
55
  chunk_print(stdout, &dst_c);
56

    
57
  return 0;
58
}