-
-
Save FROGGS/a4f263bdea31d553be84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/6model/reprs/P6bigint.c b/src/6model/reprs/P6bigint.c | |
index 5775052..d7cc636 100644 | |
--- a/src/6model/reprs/P6bigint.c | |
+++ b/src/6model/reprs/P6bigint.c | |
@@ -99,6 +99,32 @@ static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) { | |
/* Nothing to do for this REPR. */ | |
} | |
+static void deserialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMSerializationReader *reader) { | |
+ int size = reader->read_int(tc, reader); | |
+ | |
+ //~ assert_can_read(tc, reader, 8); | |
+ | |
+ mp_read_signed_bin(&((MVMP6bigintBody *)data)->i, *(reader->cur_read_buffer) + *(reader->cur_read_offset), size); | |
+ | |
+ *(reader->cur_read_offset) += size; | |
+ | |
+} | |
+ | |
+static void serialize(MVMThreadContext *tc, MVMSTable *st, void *data, MVMSerializationWriter *writer) { | |
+ mp_int *i = &((MVMP6bigintBody *)data)->i; | |
+ | |
+ /* This will return the number of bytes (octets) required to store the signed copy of the bigint. */ | |
+ int size = mp_signed_bin_size(i); | |
+ writer->write_int(tc, writer, size); | |
+ | |
+ writer->expand_storage_if_needed(tc, writer, size); | |
+ | |
+ /* This will store the bigint into the buffer in big–endian format. */ | |
+ mp_to_signed_bin(i, *(writer->cur_write_buffer) + *(writer->cur_write_offset)); | |
+ | |
+ *(writer->cur_write_offset) += size; | |
+} | |
+ | |
/* Initializes the representation. */ | |
MVMREPROps * MVMP6bigint_initialize(MVMThreadContext *tc) { | |
this_repr = malloc(sizeof(MVMREPROps)); | |
diff --git a/src/6model/serialization.h b/src/6model/serialization.h | |
index 5afb843..283aa34 100644 | |
--- a/src/6model/serialization.h | |
+++ b/src/6model/serialization.h | |
@@ -146,6 +146,7 @@ struct MVMSerializationWriter { | |
void (*write_str) (MVMThreadContext *tc, MVMSerializationWriter *writer, MVMString *value); | |
void (*write_ref) (MVMThreadContext *tc, MVMSerializationWriter *writer, MVMObject *value); | |
void (*write_stable_ref) (MVMThreadContext *tc, MVMSerializationWriter *writer, MVMSTable *st); | |
+ void (*expand_storage_if_needed) (MVMThreadContext *tc, MVMSerializationWriter *writer, MVMint64 need); | |
}; | |
/* Core serialize and deserialize functions. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment