4 * Sequence 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_sequence_read(struct stream_pos
*ppos
, struct definition
*definition
)
23 struct definition_sequence
*sequence_definition
=
24 container_of(definition
, struct definition_sequence
, p
);
25 struct declaration_sequence
*sequence_declaration
=
26 sequence_definition
->declaration
;
27 struct declaration
*elem
= sequence_declaration
->elem
;
28 struct ctf_stream_pos
*pos
= ctf_pos(ppos
);
30 if (elem
->id
== CTF_TYPE_INTEGER
) {
31 struct declaration_integer
*integer_declaration
=
32 container_of(elem
, struct declaration_integer
, p
);
34 if (integer_declaration
->encoding
== CTF_STRING_UTF8
35 || integer_declaration
->encoding
== CTF_STRING_ASCII
) {
37 if (integer_declaration
->len
== CHAR_BIT
38 && integer_declaration
->p
.alignment
== CHAR_BIT
) {
39 uint64_t len
= sequence_len(sequence_definition
);
41 ctf_align_pos(pos
, integer_declaration
->p
.alignment
);
42 if (!ctf_pos_access_ok(pos
, len
* CHAR_BIT
))
45 g_string_assign(sequence_definition
->string
, "");
46 g_string_insert_len(sequence_definition
->string
,
47 0, (char *) ctf_get_pos_addr(pos
), len
);
48 ctf_move_pos(pos
, len
* CHAR_BIT
);
53 return sequence_rw(ppos
, definition
);
56 int ctf_sequence_write(struct stream_pos
*ppos
, struct definition
*definition
)
58 struct definition_sequence
*sequence_definition
=
59 container_of(definition
, struct definition_sequence
, p
);
60 struct declaration_sequence
*sequence_declaration
=
61 sequence_definition
->declaration
;
62 struct declaration
*elem
= sequence_declaration
->elem
;
63 struct ctf_stream_pos
*pos
= ctf_pos(ppos
);
65 if (elem
->id
== CTF_TYPE_INTEGER
) {
66 struct declaration_integer
*integer_declaration
=
67 container_of(elem
, struct declaration_integer
, p
);
69 if (integer_declaration
->encoding
== CTF_STRING_UTF8
70 || integer_declaration
->encoding
== CTF_STRING_ASCII
) {
72 if (integer_declaration
->len
== CHAR_BIT
73 && integer_declaration
->p
.alignment
== CHAR_BIT
) {
74 uint64_t len
= sequence_len(sequence_definition
);
76 ctf_align_pos(pos
, integer_declaration
->p
.alignment
);
77 if (!ctf_pos_access_ok(pos
, len
* CHAR_BIT
))
80 memcpy((char *) ctf_get_pos_addr(pos
),
81 sequence_definition
->string
->str
, len
);
82 ctf_move_pos(pos
, len
* CHAR_BIT
);
87 return sequence_rw(ppos
, definition
);
This page took 0.032992 seconds and 4 git commands to generate.