1StdLabels.Bytes(3)               OCaml library              StdLabels.Bytes(3)
2
3
4

NAME

6       StdLabels.Bytes - no description
7

Module

9       Module   StdLabels.Bytes
10

Documentation

12       Module Bytes
13        : (module BytesLabels)
14
15
16
17
18
19
20
21
22       val length : bytes -> int
23
24       Return the length (number of bytes) of the argument.
25
26
27
28       val get : bytes -> int -> char
29
30
31       get s n returns the byte at index n in argument s .
32
33       Raise Invalid_argument if n is not a valid index in s .
34
35
36
37       val set : bytes -> int -> char -> unit
38
39
40       set s n c modifies s in place, replacing the byte at index n with c .
41
42       Raise Invalid_argument if n is not a valid index in s .
43
44
45
46       val create : int -> bytes
47
48
49       create  n  returns  a  new  byte sequence of length n . The sequence is
50       uninitialized and contains arbitrary bytes.
51
52       Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
53
54
55
56       val make : int -> char -> bytes
57
58
59       make n c returns a new byte sequence of length n , filled with the byte
60       c .
61
62       Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
63
64
65
66       val init : int -> f:(int -> char) -> bytes
67
68
69       init  n  f returns a fresh byte sequence of length n , with character i
70       initialized to the result of f i .
71
72       Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
73
74
75
76       val empty : bytes
77
78       A byte sequence of size 0.
79
80
81
82       val copy : bytes -> bytes
83
84       Return a new byte sequence that contains the same bytes  as  the  argu‐
85       ment.
86
87
88
89       val of_string : string -> bytes
90
91       Return  a  new  byte sequence that contains the same bytes as the given
92       string.
93
94
95
96       val to_string : bytes -> string
97
98       Return a new string that contains the same  bytes  as  the  given  byte
99       sequence.
100
101
102
103       val sub : bytes -> pos:int -> len:int -> bytes
104
105
106       sub  s start len returns a new byte sequence of length len , containing
107       the subsequence of s that starts at position start and has length len .
108
109       Raise Invalid_argument if start and len do not designate a valid  range
110       of s .
111
112
113
114       val sub_string : bytes -> pos:int -> len:int -> string
115
116       Same as sub but return a string instead of a byte sequence.
117
118
119
120       val extend : bytes -> left:int -> right:int -> bytes
121
122
123       extend s left right returns a new byte sequence that contains the bytes
124       of s , with left uninitialized bytes prepended and right  uninitialized
125       bytes  appended  to  it.  If  left or right is negative, then bytes are
126       removed (instead of appended) from the corresponding side of s .
127
128       Raise Invalid_argument if the result length is negative or longer  than
129       Sys.max_string_length bytes.
130
131
132       Since 4.05.0
133
134
135
136       val fill : bytes -> pos:int -> len:int -> char -> unit
137
138
139       fill s start len c modifies s in place, replacing len characters with c
140       , starting at start .
141
142       Raise Invalid_argument if start and len do not designate a valid  range
143       of s .
144
145
146
147       val  blit  :  src:bytes  ->  src_pos:int -> dst:bytes -> dst_pos:int ->
148       len:int -> unit
149
150
151       blit src srcoff dst dstoff len copies len bytes  from  sequence  src  ,
152       starting at index srcoff , to sequence dst , starting at index dstoff .
153       It works correctly even if src and dst are the same byte sequence,  and
154       the source and destination intervals overlap.
155
156       Raise Invalid_argument if srcoff and len do not designate a valid range
157       of src , or if dstoff and len do not designate a valid range of dst .
158
159
160
161       val blit_string : src:string -> src_pos:int -> dst:bytes -> dst_pos:int
162       -> len:int -> unit
163
164
165       blit  src  srcoff  dst  dstoff  len  copies len bytes from string src ,
166       starting at index srcoff , to byte sequence dst  ,  starting  at  index
167       dstoff .
168
169       Raise Invalid_argument if srcoff and len do not designate a valid range
170       of src , or if dstoff and len do not designate a valid range of dst .
171
172
173       Since 4.05.0
174
175
176
177       val concat : sep:bytes -> bytes list -> bytes
178
179
180       concat sep sl concatenates the list of byte sequences  sl  ,  inserting
181       the separator byte sequence sep between each, and returns the result as
182       a new byte sequence.
183
184
185
186       val cat : bytes -> bytes -> bytes
187
188
189       cat s1 s2 concatenates s1 and s2 and returns the  result  as  new  byte
190       sequence.
191
192       Raise    Invalid_argument    if    the    result    is    longer   than
193       Sys.max_string_length bytes.
194
195
196       Since 4.05.0
197
198
199
200       val iter : f:(char -> unit) -> bytes -> unit
201
202
203       iter f s applies function f in turn to all the bytes  of  s  .   It  is
204       equivalent to f (get s 0); f (get s 1); ...; f (get s
205           (length s - 1)); () .
206
207
208
209       val iteri : f:(int -> char -> unit) -> bytes -> unit
210
211       Same  as  Bytes.iter  , but the function is applied to the index of the
212       byte as first argument and the byte itself as second argument.
213
214
215
216       val map : f:(char -> char) -> bytes -> bytes
217
218
219       map f s applies function f in turn to all the bytes of s and stores the
220       resulting bytes in a new sequence that is returned as the result.
221
222
223
224       val mapi : f:(int -> char -> char) -> bytes -> bytes
225
226
227       mapi  f s calls f with each character of s and its index (in increasing
228       index order) and stores the resulting bytes in a new sequence  that  is
229       returned as the result.
230
231
232
233       val trim : bytes -> bytes
234
235       Return a copy of the argument, without leading and trailing whitespace.
236       The bytes regarded as whitespace are the ASCII characters ' ' ,  '\012'
237       , '\n' , '\r' , and '\t' .
238
239
240
241       val escaped : bytes -> bytes
242
243       Return  a  copy of the argument, with special characters represented by
244       escape sequences, following the lexical conventions of OCaml.
245
246
247
248       val index : bytes -> char -> int
249
250
251       index s c returns the index of the first occurrence of byte c in s .
252
253       Raise Not_found if c does not occur in s .
254
255
256
257       val index_opt : bytes -> char -> int option
258
259
260       index_opt s c returns the index of the first occurrence of byte c in  s
261       or None if c does not occur in s .
262
263
264       Since 4.05
265
266
267
268       val rindex : bytes -> char -> int
269
270
271       rindex s c returns the index of the last occurrence of byte c in s .
272
273       Raise Not_found if c does not occur in s .
274
275
276
277       val rindex_opt : bytes -> char -> int option
278
279
280       rindex_opt  s c returns the index of the last occurrence of byte c in s
281       or None if c does not occur in s .
282
283
284       Since 4.05
285
286
287
288       val index_from : bytes -> int -> char -> int
289
290
291       index_from s i c returns the index of the first occurrence of byte c in
292       s after position i .  Bytes.index s c is equivalent to Bytes.index_from
293       s 0 c .
294
295       Raise Invalid_argument if i is not a  valid  position  in  s  .   Raise
296       Not_found if c does not occur in s after position i .
297
298
299
300       val index_from_opt : bytes -> int -> char -> int option
301
302
303       index_from  _opts i c returns the index of the first occurrence of byte
304       c in s after position i or None if c does not occur in s after position
305       i .  Bytes.index_opt s c is equivalent to Bytes.index_from_opt s 0 c .
306
307       Raise Invalid_argument if i is not a valid position in s .
308
309
310       Since 4.05
311
312
313
314       val rindex_from : bytes -> int -> char -> int
315
316
317       rindex_from s i c returns the index of the last occurrence of byte c in
318       s before position i+1 .  rindex s c  is  equivalent  to  rindex_from  s
319       (Bytes.length s - 1) c .
320
321       Raise  Invalid_argument  if  i+1  is not a valid position in s .  Raise
322       Not_found if c does not occur in s before position i+1 .
323
324
325
326       val rindex_from_opt : bytes -> int -> char -> int option
327
328
329       rindex_from_opt s i c returns the index of the last occurrence of  byte
330       c  in  s  before  position  i+1 or None if c does not occur in s before
331       position  i+1  .   rindex_opt  s  c  is  equivalent  to  rindex_from  s
332       (Bytes.length s - 1) c .
333
334       Raise Invalid_argument if i+1 is not a valid position in s .
335
336
337       Since 4.05
338
339
340
341       val contains : bytes -> char -> bool
342
343
344       contains s c tests if byte c appears in s .
345
346
347
348       val contains_from : bytes -> int -> char -> bool
349
350
351       contains_from  s  start  c  tests if byte c appears in s after position
352       start .  contains s c is equivalent to contains_from
353           s 0 c .
354
355       Raise Invalid_argument if start is not a valid position in s .
356
357
358
359       val rcontains_from : bytes -> int -> char -> bool
360
361
362       rcontains_from s stop c tests if byte c appears in  s  before  position
363       stop+1 .
364
365       Raise Invalid_argument if stop < 0 or stop+1 is not a valid position in
366       s .
367
368
369
370       val uppercase : bytes -> bytes
371
372       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
373       cated.
374
375
376       Return a copy of the argument, with all lowercase letters translated to
377       uppercase, including accented letters of the ISO Latin-1 (8859-1) char‐
378       acter set.
379
380
381
382       val lowercase : bytes -> bytes
383
384       Deprecated.   Functions  operating  on Latin-1 character set are depre‐
385       cated.
386
387
388       Return a copy of the argument, with all uppercase letters translated to
389       lowercase, including accented letters of the ISO Latin-1 (8859-1) char‐
390       acter set.
391
392
393
394       val capitalize : bytes -> bytes
395
396       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
397       cated.
398
399
400       Return  a  copy of the argument, with the first character set to upper‐
401       case, using the ISO Latin-1 (8859-1) character set..
402
403
404
405       val uncapitalize : bytes -> bytes
406
407       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
408       cated.
409
410
411       Return  a  copy of the argument, with the first character set to lower‐
412       case, using the ISO Latin-1 (8859-1) character set..
413
414
415
416       val uppercase_ascii : bytes -> bytes
417
418       Return a copy of the argument, with all lowercase letters translated to
419       uppercase, using the US-ASCII character set.
420
421
422       Since 4.05.0
423
424
425
426       val lowercase_ascii : bytes -> bytes
427
428       Return a copy of the argument, with all uppercase letters translated to
429       lowercase, using the US-ASCII character set.
430
431
432       Since 4.05.0
433
434
435
436       val capitalize_ascii : bytes -> bytes
437
438       Return a copy of the argument, with the first character set  to  upper‐
439       case, using the US-ASCII character set.
440
441
442       Since 4.05.0
443
444
445
446       val uncapitalize_ascii : bytes -> bytes
447
448       Return  a  copy of the argument, with the first character set to lower‐
449       case, using the US-ASCII character set.
450
451
452       Since 4.05.0
453
454
455       type t = bytes
456
457
458       An alias for the type of byte sequences.
459
460
461
462       val compare : t -> t -> int
463
464       The comparison function for byte sequences, with the same specification
465       as  compare .  Along with the type t , this function compare allows the
466       module Bytes to be passed as argument  to  the  functors  Set.Make  and
467       Map.Make .
468
469
470
471       val equal : t -> t -> bool
472
473       The equality function for byte sequences.
474
475
476       Since 4.05.0
477
478
479
480
481   Iterators
482       val to_seq : t -> char Seq.t
483
484       Iterate  on the string, in increasing index order. Modifications of the
485       string during iteration will be reflected in the iterator.
486
487
488       Since 4.07
489
490
491
492       val to_seqi : t -> (int * char) Seq.t
493
494       Iterate on the string, in  increasing  order,  yielding  indices  along
495       chars
496
497
498       Since 4.07
499
500
501
502       val of_seq : char Seq.t -> t
503
504       Create a string from the generator
505
506
507       Since 4.07
508
509
510
511
512   Binary encoding/decoding of integers
513       The  functions in this section binary encode and decode integers to and
514       from byte sequences.
515
516       All following functions raise Invalid_argument if the space  needed  at
517       index i to decode or encode the integer is not available.
518
519       Little-endian (resp. big-endian) encoding means that least (resp. most)
520       significant bytes are stored first.  Big-endian is also known  as  net‐
521       work  byte  order.   Native-endian  encoding is either little-endian or
522       big-endian depending on Sys.big_endian .
523
524       32-bit and 64-bit integers are  represented  by  the  int32  and  int64
525       types, which can be interpreted either as signed or unsigned numbers.
526
527       8-bit  and  16-bit  integers are represented by the int type, which has
528       more bits than the binary encoding.  These extra bits  are  handled  as
529       follows:
530
531       -Functions that decode signed (resp. unsigned) 8-bit or 16-bit integers
532       represented by int values sign-extend (resp. zero-extend) their result.
533
534       -Functions that encode 8-bit or 16-bit integers represented by int val‐
535       ues truncate their input to their least significant bytes.
536
537
538       val get_uint8 : bytes -> int -> int
539
540
541       get_uint8 b i is b 's unsigned 8-bit integer starting at byte index i .
542
543
544       Since 4.08
545
546
547
548       val get_int8 : bytes -> int -> int
549
550
551       get_int8 b i is b 's signed 8-bit integer starting at byte index i .
552
553
554       Since 4.08
555
556
557
558       val get_uint16_ne : bytes -> int -> int
559
560
561       get_uint16_ne  b i is b 's native-endian unsigned 16-bit integer start‐
562       ing at byte index i .
563
564
565       Since 4.08
566
567
568
569       val get_uint16_be : bytes -> int -> int
570
571
572       get_uint16_be b i is b 's big-endian unsigned 16-bit  integer  starting
573       at byte index i .
574
575
576       Since 4.08
577
578
579
580       val get_uint16_le : bytes -> int -> int
581
582
583       get_uint16_le  b i is b 's little-endian unsigned 16-bit integer start‐
584       ing at byte index i .
585
586
587       Since 4.08
588
589
590
591       val get_int16_ne : bytes -> int -> int
592
593
594       get_int16_ne b i is b 's native-endian signed 16-bit  integer  starting
595       at byte index i .
596
597
598       Since 4.08
599
600
601
602       val get_int16_be : bytes -> int -> int
603
604
605       get_int16_be  b  i is b 's big-endian signed 16-bit integer starting at
606       byte index i .
607
608
609       Since 4.08
610
611
612
613       val get_int16_le : bytes -> int -> int
614
615
616       get_int16_le b i is b 's little-endian signed 16-bit  integer  starting
617       at byte index i .
618
619
620       Since 4.08
621
622
623
624       val get_int32_ne : bytes -> int -> int32
625
626
627       get_int32_ne  b i is b 's native-endian 32-bit integer starting at byte
628       index i .
629
630
631       Since 4.08
632
633
634
635       val get_int32_be : bytes -> int -> int32
636
637
638       get_int32_be b i is b 's big-endian 32-bit  integer  starting  at  byte
639       index i .
640
641
642       Since 4.08
643
644
645
646       val get_int32_le : bytes -> int -> int32
647
648
649       get_int32_le  b i is b 's little-endian 32-bit integer starting at byte
650       index i .
651
652
653       Since 4.08
654
655
656
657       val get_int64_ne : bytes -> int -> int64
658
659
660       get_int64_ne b i is b 's native-endian 64-bit integer starting at  byte
661       index i .
662
663
664       Since 4.08
665
666
667
668       val get_int64_be : bytes -> int -> int64
669
670
671       get_int64_be  b  i  is  b 's big-endian 64-bit integer starting at byte
672       index i .
673
674
675       Since 4.08
676
677
678
679       val get_int64_le : bytes -> int -> int64
680
681
682       get_int64_le b i is b 's little-endian 64-bit integer starting at  byte
683       index i .
684
685
686       Since 4.08
687
688
689
690       val set_uint8 : bytes -> int -> int -> unit
691
692
693       set_uint8 b i v sets b 's unsigned 8-bit integer starting at byte index
694       i to v .
695
696
697       Since 4.08
698
699
700
701       val set_int8 : bytes -> int -> int -> unit
702
703
704       set_int8 b i v sets b 's signed 8-bit integer starting at byte index  i
705       to v .
706
707
708       Since 4.08
709
710
711
712       val set_uint16_ne : bytes -> int -> int -> unit
713
714
715       set_uint16_ne  b  i  v  sets b 's native-endian unsigned 16-bit integer
716       starting at byte index i to v .
717
718
719       Since 4.08
720
721
722
723       val set_uint16_be : bytes -> int -> int -> unit
724
725
726       set_uint16_be b i v sets b 's big-endian unsigned 16-bit integer start‐
727       ing at byte index i to v .
728
729
730       Since 4.08
731
732
733
734       val set_uint16_le : bytes -> int -> int -> unit
735
736
737       set_uint16_le  b  i  v  sets b 's little-endian unsigned 16-bit integer
738       starting at byte index i to v .
739
740
741       Since 4.08
742
743
744
745       val set_int16_ne : bytes -> int -> int -> unit
746
747
748       set_int16_ne b i v sets b 's native-endian signed 16-bit integer start‐
749       ing at byte index i to v .
750
751
752       Since 4.08
753
754
755
756       val set_int16_be : bytes -> int -> int -> unit
757
758
759       set_int16_be  b i v sets b 's big-endian signed 16-bit integer starting
760       at byte index i to v .
761
762
763       Since 4.08
764
765
766
767       val set_int16_le : bytes -> int -> int -> unit
768
769
770       set_int16_le b i v sets b 's little-endian signed 16-bit integer start‐
771       ing at byte index i to v .
772
773
774       Since 4.08
775
776
777
778       val set_int32_ne : bytes -> int -> int32 -> unit
779
780
781       set_int32_ne  b  i v sets b 's native-endian 32-bit integer starting at
782       byte index i to v .
783
784
785       Since 4.08
786
787
788
789       val set_int32_be : bytes -> int -> int32 -> unit
790
791
792       set_int32_be b i v sets b 's big-endian 32-bit integer starting at byte
793       index i to v .
794
795
796       Since 4.08
797
798
799
800       val set_int32_le : bytes -> int -> int32 -> unit
801
802
803       set_int32_le  b  i v sets b 's little-endian 32-bit integer starting at
804       byte index i to v .
805
806
807       Since 4.08
808
809
810
811       val set_int64_ne : bytes -> int -> int64 -> unit
812
813
814       set_int64_ne b i v sets b 's native-endian 64-bit integer  starting  at
815       byte index i to v .
816
817
818       Since 4.08
819
820
821
822       val set_int64_be : bytes -> int -> int64 -> unit
823
824
825       set_int64_be b i v sets b 's big-endian 64-bit integer starting at byte
826       index i to v .
827
828
829       Since 4.08
830
831
832
833       val set_int64_le : bytes -> int -> int64 -> unit
834
835
836       set_int64_le b i v sets b 's little-endian 64-bit integer  starting  at
837       byte index i to v .
838
839
840       Since 4.08
841
842
843
844
845
846OCamldoc                          2020-02-27                StdLabels.Bytes(3)
Impressum