示例#1
0
文件: test.c 项目: 01BTC10/amp
int
main(){
  char *args[] = { "some", "stuff", "here" };

  // encode
  char *buf = amp_encode(args, 3);

  // header
  amp_t msg = {0};
  amp_decode(&msg, buf);
  assert(1 == msg.version);
  assert(3 == msg.argc);

  // args
  for (int i = 0; i < msg.argc; ++i) {
    char *arg = amp_decode_arg(&msg);
    switch (i) {
      case 0:
        assert(0 == strcmp("some", arg));
        break;
      case 1:
        assert(0 == strcmp("stuff", arg));
        break;
      case 2:
        assert(0 == strcmp("here", arg));
        break;
    }
  }

  printf("ok\n");

  return 0;
}
示例#2
0
文件: list.c 项目: rhs/amp
size_t amp_encode_list(amp_list_t *l, char *out)
{
  char *old = out;
  char *start;
  // XXX
  amp_write_start(&out, out + 1024, &start);
  for (int i = 0; i < l->size; i++)
  {
    out += amp_encode(l->values[i], out);
  }
  amp_write_list(&out, out + 1024, start, l->size);
  return out - old;
}