Skip to content

Commit

Permalink
Merge pull request #1380 from MoarVM/serialize-cstr
Browse files Browse the repository at this point in the history
Implement serialize/deserialize of CStr REPR
  • Loading branch information
jnthn committed Nov 20, 2020
2 parents b13f6a2 + 3c5deb2 commit 76ea458
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/6model/reprs/CStr.c
Expand Up @@ -71,6 +71,17 @@ static void deserialize_stable_size(MVMThreadContext *tc, MVMSTable *st, MVMSeri
st->size = sizeof(MVMCStr);
}

static void deserialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMSerializationReader *reader) {
MVMString *orig = MVM_serialization_read_str(tc, reader);
MVMCStrBody *body = (MVMCStrBody *)data;
MVM_ASSIGN_REF(tc, &(root->header), body->orig, orig);
body->cstr = MVM_string_utf8_encode_C_string(tc, orig);
}

static void serialize(MVMThreadContext *tc, MVMSTable *st, void *data, MVMSerializationWriter *writer) {
MVM_serialization_write_str(tc, writer, ((MVMCStrBody *)data)->orig);
}

/* Initializes the representation. */
const MVMREPROps * MVMCStr_initialize(MVMThreadContext *tc) {
return &CStr_this_repr;
Expand Down Expand Up @@ -98,8 +109,8 @@ static const MVMREPROps CStr_this_repr = {
MVM_REPR_DEFAULT_ELEMS,
get_storage_spec,
NULL, /* change_type */
NULL, /* serialize */
NULL, /* deserialize */
serialize,
deserialize,
NULL, /* serialize_repr_data */
NULL, /* deserialize_repr_data */
deserialize_stable_size,
Expand Down

0 comments on commit 76ea458

Please sign in to comment.