class example_record
does Compact
is finalized
{
has Str $.name
is rw
should serialize (:length_prefix(2), :encoding(UTF16),
padding => {:char("\0", :strip} );
has int16 $.val is rw;
has Str $!presentation_cache; # private, not included in compact struct I/O
method presentation () returns Str
{
unless defined $!presentation_cache {
... # compute it
}
return $!presentation_cache;
}
}
####
my Buf $temp = $record;
$stream.print ($temp);
$stream.print (Buf $record);
####
$stream.write ($record); # just what I need
my int16 $x = 42;
$stream.write ($x); # emits 2 bytes, exactly as stored in the primitive
$stream.print ($x); # emits characters "4" and "2" in the proper encoding
####
class VLI<2.0.1 cpan:DLUGOSZ>
does Compact
{
# implements packing/unpacking as described in
has Int $.value is rw;
multi pack (*%adverbs) returns Buf
{
... respects standard signed/unsigned option,
supports unique options for encoding variations
}
} # end class VLI
####
class C does Compact is rw
{
has int32 $x;
has VLI $y;
}
my C $c; # for a Compact class, empty prototype is not undef but default values
$c.x= 5; # OK
$c.y.value = 1234567812345678; # yuck
####
class VLI<2.0.1 cpan:DLUGOSZ>
does Compact::helper
{
# implements packing/unpacking as described in
multi pack (Int value, *%adverbs) returns Buf
{
... respects standard signed/unsigned option,
supports unique options for encoding variations
}
} # end class VLI
class C does Compact is rw
{
has int32 $x;
has Int $y is VLI;
}