Commit beb2017dc82d3aac80d858d81f0997a5b77e6b82
1 parent
e7ed789d
dyntype seems to work for int now, incl. json
Showing
3 changed files
with
44 additions
and
7 deletions
... | ... | @@ -30,8 +30,8 @@ __jsonConst(struct BIGPOINT_DYNTYPE * _this, struct json_object * json) |
30 | 30 | switch (json_object_get_type(json)) { |
31 | 31 | case json_type_int: |
32 | 32 | _this->type = BIGPOINT_DYNTYPE_INT; |
33 | - _this->size = sizeof(long); | |
34 | - (_this->data)._int = (long)json_object_get_int(json); | |
33 | + _this->size = sizeof(int); | |
34 | + (_this->data)._int = (int)json_object_get_int(json); | |
35 | 35 | break; |
36 | 36 | |
37 | 37 | default: |
... | ... | @@ -56,10 +56,15 @@ __toJson(struct BIGPOINT_DYNTYPE * _this) |
56 | 56 | { |
57 | 57 | struct json_object * json = NULL; |
58 | 58 | |
59 | - /** | |
60 | - * @TODO: make a smart implementation here base on the type of the | |
61 | - * actual object. | |
62 | - */ | |
59 | + switch(_this->type) { | |
60 | + case BIGPOINT_DYNTYPE_INT: | |
61 | + json = json_object_new_int((_this->data)._int); | |
62 | + break; | |
63 | + | |
64 | + default: | |
65 | + json = NULL; | |
66 | + } | |
67 | + | |
63 | 68 | return json; |
64 | 69 | } |
65 | 70 | ... | ... |
test4.c
0 → 100644
1 | +#include <stdio.h> | |
2 | +#include <string.h> | |
3 | +#include <json/json.h> | |
4 | + | |
5 | +#include "bigpoint_cclass.h" | |
6 | +#include "bigpoint_dyntype.h" | |
7 | + | |
8 | + | |
9 | +int | |
10 | +main(int argc, char * argv[]) | |
11 | +{ | |
12 | + struct json_object * json = json_object_new_int(123); | |
13 | + | |
14 | + struct BIGPOINT_DYNTYPE * dyn = newFromJson(BIGPOINT_DYNTYPE, json); | |
15 | + | |
16 | + printf("%d\n", (dyn->data)._int); | |
17 | + | |
18 | + delete(dyn); | |
19 | + json_object_put(json); | |
20 | + | |
21 | + dyn = new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_INT, sizeof(int), 321); | |
22 | + json = toJson(dyn); | |
23 | + | |
24 | + printf("%s\n", json_object_to_json_string(json)); | |
25 | + | |
26 | + delete(dyn); | |
27 | + json_object_put(json); | |
28 | + | |
29 | + return 0; | |
30 | +} | |
31 | + | |
32 | +// vim: set et ts=4 sw=4: | ... | ... |
Please
register
or
login
to post a comment