4 * Sequence format access functions.
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
21 #include <babeltrace/ctf/types.h>
23 int ctf_sequence_read(struct stream_pos
*ppos
, struct definition
*definition
)
25 struct definition_sequence
*sequence_definition
=
26 container_of(definition
, struct definition_sequence
, p
);
27 struct declaration_sequence
*sequence_declaration
=
28 sequence_definition
->declaration
;
29 struct declaration
*elem
= sequence_declaration
->elem
;
30 struct ctf_stream_pos
*pos
= ctf_pos(ppos
);
32 if (elem
->id
== CTF_TYPE_INTEGER
) {
33 struct declaration_integer
*integer_declaration
=
34 container_of(elem
, struct declaration_integer
, p
);
36 if (integer_declaration
->encoding
== CTF_STRING_UTF8
37 || integer_declaration
->encoding
== CTF_STRING_ASCII
) {
39 if (integer_declaration
->len
== CHAR_BIT
40 && integer_declaration
->p
.alignment
== CHAR_BIT
) {
41 uint64_t len
= sequence_len(sequence_definition
);
43 ctf_align_pos(pos
, integer_declaration
->p
.alignment
);
44 if (!ctf_pos_access_ok(pos
, len
* CHAR_BIT
))
47 g_string_assign(sequence_definition
->string
, "");
48 g_string_insert_len(sequence_definition
->string
,
49 0, (char *) ctf_get_pos_addr(pos
), len
);
50 ctf_move_pos(pos
, len
* CHAR_BIT
);
55 return sequence_rw(ppos
, definition
);
58 int ctf_sequence_write(struct stream_pos
*ppos
, struct definition
*definition
)
60 struct definition_sequence
*sequence_definition
=
61 container_of(definition
, struct definition_sequence
, p
);
62 struct declaration_sequence
*sequence_declaration
=
63 sequence_definition
->declaration
;
64 struct declaration
*elem
= sequence_declaration
->elem
;
65 struct ctf_stream_pos
*pos
= ctf_pos(ppos
);
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
) {
76 uint64_t len
= sequence_len(sequence_definition
);
78 ctf_align_pos(pos
, integer_declaration
->p
.alignment
);
79 if (!ctf_pos_access_ok(pos
, len
* CHAR_BIT
))
82 memcpy((char *) ctf_get_pos_addr(pos
),
83 sequence_definition
->string
->str
, len
);
84 ctf_move_pos(pos
, len
* CHAR_BIT
);
89 return sequence_rw(ppos
, definition
);
This page took 0.031483 seconds and 4 git commands to generate.