-
-
Save FROGGS/c82f5d98d957d5240d15 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
use lib '.'; | |
use Ser; | |
'TEST_FILE'.IO.spurt: serialize({ foo => 42 }); | |
say deserialize('TEST_FILE'.IO.slurp); |
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
module Ser; | |
sub serialize($obj is copy) is export { | |
my Mu $sh1 := nqp::list_s(); | |
my Mu $sc := nqp::createsc(nqp::unbox_s('FLUBBER')); | |
nqp::scsetobj($sc, 0, $obj); | |
nqp::setobjsc($obj, $sc); | |
my $serialized = nqp::serialize($sc, $sh1); | |
nqp::p6box_s(nqp::join("\n", $sh1)) ~ "\n" ~ $serialized | |
} | |
sub deserialize($b64) is export { | |
my Mu $sh2 := nqp::list_s(); | |
my @lines = $b64.split("\n"); | |
my str $serialized = nqp::unbox_s(@lines.pop); | |
nqp::push_s($sh2, nqp::null_s()); | |
nqp::push_s($sh2, nqp::unbox_s($_)) for @lines; | |
my Mu $dsc2 := nqp::createsc(nqp::unbox_s('FLUBBER')); | |
nqp::deserialize($serialized, $dsc2, $sh2, nqp::list(), nqp::null()); | |
nqp::scgetobj($dsc2, 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment