[% setvar title Use pack/unpack for marshalling %]
Note: these documents may be out of date. Do not use as reference! |
To see what is currently happening visit http://www.perl6.org/
Use pack/unpack for marshalling
Maintainer: Ilya Zakharevich <ilya@math.ohio-state.edu> Date: 16 September 2000 Mailing List: perl6-language-data@perl.org Number: 249 Version: 1 Status: Developing
This RFC extends pack/unpack builtins to store/extract the TEMPLATE to/from the packed data. This allows storage of arbitrary Perl data.
t
on unpack(): remove the last extracted value and use it as if it replaces
this t
. For example, the following two calls are equivalent:
unpack 'A5 t A5', 'aCx6,AcX6...0123456' unpack 'aCx6, A5', 'AcX6...0123456'
on pack(): store the next argument so that it is extractable with 't'
,
this t
acts as a modifier for the previous type. For example,
pack 'A3 t', [5,6,[7,8],0]
may be stored in many ways, one of them (most readable?)
'A7t' . ' A21 t ' . ' g[ A A g[ A A ] A ] ' . '56780'
When this is unpacked with 'A3 t'
, the first 3 chars are used as a new
template, then the next 7 chars are used as a new template, then the next
21 chars are used as a new template, which finally extracts the structure.
This example shows that an arbitrary large structure can be extracted using
the template 'A3 t'
.
T
behaves the same as the A4 t
. (Syntactic sugar, optional). As shown
above, arbitrary data is restorable by a simple 'T'. For example,
pack 'T', [5,6,[7,8],0]
may be stored in many ways, one of them (most readable?)
'A21t' . ' g[ A A g[ A A ] A ] ' . '56780'
None.
Straightforward.
RFC142: Enhanced Pack/Unpack
RFC 246: pack/unpack uncontrovercial enhancements
RFC 248: enhanced groups in pack/unpack