1
/* This represents the root of the serialization data; everything hangs
2
* off this. In read mode, we don't do much besides populate and then
3
* read this. In write mode, however, the tables and data chunks will be
4
* filled out and grown as needed. */
6
/* The version of the serialization format. */
9
/* The number of dependencies, as well as a pointer to the
10
* dependencies table. */
11
Parrot_Int4 num_dependencies;
12
char *dependencies_table;
14
/* The SC we're serializing/deserializing. */
17
/* List of the serialization context objects that we depend on. */
20
/* The number of STables, as well as pointers to the STables
21
* table and data chunk. */
22
Parrot_Int4 num_stables;
26
/* The number of objects, as well as pointers to the objects
27
* table and data chunk. */
28
Parrot_Int4 num_objects;
32
/* The number of closures, as we as a pointer to the closures
34
Parrot_Int4 num_closures;
37
/* The number of contexts (e.g. lexpads), as well as pointers
38
* to the contexts table and data chunk. */
39
Parrot_Int4 num_contexts;
43
/* The number of repossessions and pointer to repossessions table. */
44
Parrot_Int4 num_repos;
47
/* Array of STRINGs. */
51
/* Represents the serialization reader and the various functions available
53
typedef struct SixModel_STable STable;
54
typedef struct SerializationReader {
55
/* Serialization root data. */
56
SerializationRoot root;
58
/* The stables, objects code refs and contexts lists we're deserializing
65
/* Current offsets for the data chunks (also correspond to the amount of
66
* data written in to them). */
67
Parrot_Int4 stables_data_offset;
68
Parrot_Int4 objects_data_offset;
69
Parrot_Int4 contexts_data_offset;
71
/* Limits up to where we can read stables, objects and contexts data. */
72
char *stables_data_end;
73
char *objects_data_end;
74
char *contexts_data_end;
76
/* Where to find details related to the current buffer we're reading from:
77
* the buffer pointer itself, the current offset and the amount that is
78
* allocated. These are all pointers back into this data structure. */
79
char **cur_read_buffer;
80
Parrot_Int4 *cur_read_offset;
83
/* Various reading functions. */
84
INTVAL (*read_int) (PARROT_INTERP, struct SerializationReader *reader);
85
FLOATVAL (*read_num) (PARROT_INTERP, struct SerializationReader *reader);
86
STRING * (*read_str) (PARROT_INTERP, struct SerializationReader *reader);
87
PMC * (*read_ref) (PARROT_INTERP, struct SerializationReader *reader);
88
STable * (*read_stable_ref) (PARROT_INTERP, struct SerializationReader *reader);
90
/* The object we're currently deserializing. */
93
/* The data, which we'll want to free after deserialization. */
95
} SerializationReader;
97
/* Represents the serialization writer and the various functions available
99
typedef struct SerializationWriter {
100
/* Serialization root data. */
101
SerializationRoot root;
103
/* The stables, objects, code refs and contexts lists we're working
104
* through/adding to. */
110
/* Current position in the stables, objects and contexts lists. */
111
INTVAL stables_list_pos;
112
INTVAL objects_list_pos;
113
INTVAL contexts_list_pos;
115
/* Hash of strings we've already seen while serializing to the index they
116
* are placed at in the string heap. */
119
/* Amount of memory allocated for various things. */
120
Parrot_Int4 dependencies_table_alloc;
121
Parrot_Int4 stables_table_alloc;
122
Parrot_Int4 stables_data_alloc;
123
Parrot_Int4 objects_table_alloc;
124
Parrot_Int4 objects_data_alloc;
125
Parrot_Int4 closures_table_alloc;
126
Parrot_Int4 contexts_table_alloc;
127
Parrot_Int4 contexts_data_alloc;
128
Parrot_Int4 repos_table_alloc;
130
/* Current offsets for the data chunks (also correspond to the amount of
131
* data written in to them). */
132
Parrot_Int4 stables_data_offset;
133
Parrot_Int4 objects_data_offset;
134
Parrot_Int4 contexts_data_offset;
136
/* Where to find details related to the current buffer we're writing in
137
* to: the buffer pointer itself, the current offset and the amount that
138
* is allocated. These are all pointers back into this data structure. */
139
char **cur_write_buffer;
140
Parrot_Int4 *cur_write_offset;
141
Parrot_Int4 *cur_write_limit;
143
/* Various writing functions. */
144
void (*write_int) (PARROT_INTERP, struct SerializationWriter *writer, INTVAL value);
145
void (*write_num) (PARROT_INTERP, struct SerializationWriter *writer, FLOATVAL value);
146
void (*write_str) (PARROT_INTERP, struct SerializationWriter *writer, STRING *value);
147
void (*write_ref) (PARROT_INTERP, struct SerializationWriter *writer, PMC *value);
148
void (*write_stable_ref) (PARROT_INTERP, struct SerializationWriter *writer, STable *st);
149
} SerializationWriter;
151
/* Core serialize and deserialize functions. */
152
STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap);
153
void Serialization_deserialize(PARROT_INTERP, PMC *sc, PMC *string_heap, PMC *codes_static, STRING *data);