4 * Array format access functions.
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
19 #include <babeltrace/ctf/types.h>
21 int ctf_array_read(struct stream_pos
*ppos
, struct definition
*definition
)
23 struct definition_array
*array_definition
=
24 container_of(definition
, struct definition_array
, p
);
25 struct declaration_array
*array_declaration
=
26 array_definition
->declaration
;
27 struct declaration
*elem
= array_declaration
->elem
;
28 struct ctf_stream_pos
*pos
=
29 container_of(ppos
, struct ctf_stream_pos
, parent
);
31 if (elem
->id
== CTF_TYPE_INTEGER
) {
32 struct declaration_integer
*integer_declaration
=
33 container_of(elem
, struct declaration_integer
, p
);
35 if (integer_declaration
->encoding
== CTF_STRING_UTF8
36 || integer_declaration
->encoding
== CTF_STRING_ASCII
) {
38 if (integer_declaration
->len
== CHAR_BIT
39 && integer_declaration
->p
.alignment
== CHAR_BIT
) {
41 ctf_align_pos(pos
, integer_declaration
->p
.alignment
);
42 if (!ctf_pos_access_ok(pos
, array_declaration
->len
* CHAR_BIT
))
45 g_string_assign(array_definition
->string
, "");
46 g_string_insert_len(array_definition
->string
,
47 0, (char *) ctf_get_pos_addr(pos
),
48 array_declaration
->len
);
49 ctf_move_pos(pos
, array_declaration
->len
* CHAR_BIT
);
54 return array_rw(ppos
, definition
);
57 int ctf_array_write(struct stream_pos
*ppos
, struct definition
*definition
)
59 struct definition_array
*array_definition
=
60 container_of(definition
, struct definition_array
, p
);
61 struct declaration_array
*array_declaration
=
62 array_definition
->declaration
;
63 struct declaration
*elem
= array_declaration
->elem
;
64 struct ctf_stream_pos
*pos
=
65 container_of(ppos
, struct ctf_stream_pos
, parent
);
67 if (elem
->id
== CTF_TYPE_INTEGER
) {
68 struct declaration_integer
*integer_declaration
=
69 container_of(elem
, struct declaration_integer
, p
);
71 if (integer_declaration
->encoding
== CTF_STRING_UTF8
72 || integer_declaration
->encoding
== CTF_STRING_ASCII
) {
74 if (integer_declaration
->len
== CHAR_BIT
75 && integer_declaration
->p
.alignment
== CHAR_BIT
) {
77 ctf_align_pos(pos
, integer_declaration
->p
.alignment
);
78 if (!ctf_pos_access_ok(pos
, array_declaration
->len
* CHAR_BIT
))
81 memcpy((char *) ctf_get_pos_addr(pos
),
82 array_definition
->string
->str
,
83 array_declaration
->len
);
84 ctf_move_pos(pos
, array_declaration
->len
* CHAR_BIT
);
89 return array_rw(ppos
, definition
);
This page took 0.038203 seconds and 5 git commands to generate.