File tree Expand file tree Collapse file tree 2 files changed +40
-6
lines changed Expand file tree Collapse file tree 2 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,36 @@ later.)
20
20
= comment The following should be a table but formatting in tables is
21
21
not yet rendered properly.
22
22
23
- = item X < B < pack > |pack> [TBD]
23
+ = head2 X < B < pack > |pack>
24
+
25
+ Pack is a feature that allows binary serialization of general data structures,
26
+ and is inherited from
27
+ L < Perl's pack|http://perldoc.perl.org/functions/pack.html > .
28
+ The C < pack > order creates a
29
+ C < Buf > by packing data structures in a certain way given by a I < packing string >
30
+ with the options shown
31
+ L < in the description of C < unpack > \/type/Blob#method_unpack > .
32
+
33
+ For instance, we can pack numbers interpreting them as hexadecimal (C < H > ) with
34
+ the pattern repeating until there are no more elements (C < * > ):
35
+
36
+ = for code
37
+ use experimental :pack;
38
+ say pack("H*", "414243").contents;# OUTPUT: «(65 66 67)»
39
+
40
+ There is a corresponding C < unpack > routine that does exactly the opposite.
41
+
42
+ = for code
43
+ use experimental :pack;
44
+ my $buf=Buf.new(65,66,67);
45
+ say $buf.unpack("H*"); # OUTPUT: «414243»
46
+
47
+
48
+ Not all of the symbols above are guaranteed to be implemented, and the roadmap
49
+ does not include a fixed date for getting out of that stage.
50
+
51
+ Please see also documentation for L < C < pack > \/type/Blob#sub_pack> and
52
+ L < C < unpack > \/type/Blob#method_unpack> in the C < Blob > page.
24
53
25
54
= head2 X < B < macros > |macros>
26
55
Original file line number Diff line number Diff line change @@ -137,14 +137,17 @@ values are given to fill the entire C<Blob>.
137
137
138
138
= head2 method unpack
139
139
140
- This method is considered B < experimental > , in order to use it you will need to do:
140
+ This method is considered B < experimental > , in order to use it you will need to
141
+ do:
141
142
142
143
use experimental :pack;
143
144
144
-
145
145
Defined as:
146
146
147
- method unpack(Blob:D: $template --> List:D)
147
+ method unpack(Blob:D: Str:D $template)
148
+ method unpack(Blob:D: @template)
149
+ multi sub unpack(Blob:D \blob, Str:D $template)
150
+ multi sub unpack(Blob:D \blob, @template)
148
151
149
152
Extracts features from the blob according to the template string, and
150
153
returns them as a list.
@@ -187,13 +190,15 @@ Example:
187
190
188
191
= head2 sub pack
189
192
190
- This subroutine is considered B < experimental > , in order to use it you will need to do:
193
+ This subroutine is considered B < experimental > , in order to use it you will need
194
+ to do:
191
195
192
196
= for code
193
197
use experimental :pack;
194
198
195
199
= for code
196
- sub pack(Str $template, *@items --> Buf)
200
+ sub pack(Str $template, *@items)
201
+ sub pack(@template, *@items)
197
202
198
203
Packs the given items according to the template and returns a buffer
199
204
containing the packed bytes.
You can’t perform that action at this time.
0 commit comments