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

NAME

6       Bytes - Byte sequence operations.
7

Module

9       Module   Bytes
10

Documentation

12       Module Bytes
13        : sig end
14
15
16       Byte sequence operations.
17
18       A   byte   sequence  is  a  mutable  data  structure  that  contains  a
19       fixed-length sequence of bytes. Each byte can be  indexed  in  constant
20       time for reading or writing.
21
22       Given a byte sequence s of length l , we can access each of the l bytes
23       of s via its index in the sequence. Indexes start at 0 ,  and  we  will
24       call an index valid in s if it falls within the range [0...l-1] (inclu‐
25       sive). A position is the point between two bytes or at the beginning or
26       end  of the sequence.  We call a position valid in s if it falls within
27       the range [0...l] (inclusive). Note that the byte at index n is between
28       positions n and n+1 .
29
30       Two  parameters  start and len are said to designate a valid range of s
31       if len >= 0 and start and start+len are valid positions in s .
32
33       Byte sequences can be modified in place, for instance via the  set  and
34       blit  functions  described  below.   See also strings (module String ),
35       which are almost the same data structure, but  cannot  be  modified  in
36       place.
37
38       Bytes are represented by the OCaml type char .
39
40       The labeled version of this module can be used as described in the Std‐
41       Labels module.
42
43
44       Since 4.02.0
45
46
47
48
49
50
51       val length : bytes -> int
52
53       Return the length (number of bytes) of the argument.
54
55
56
57       val get : bytes -> int -> char
58
59
60       get s n returns the byte at index n in argument s .
61
62
63       Raises Invalid_argument if n is not a valid index in s .
64
65
66
67       val set : bytes -> int -> char -> unit
68
69
70       set s n c modifies s in place, replacing the byte at index n with c .
71
72
73       Raises Invalid_argument if n is not a valid index in s .
74
75
76
77       val create : int -> bytes
78
79
80       create n returns a new byte sequence of length  n  .  The  sequence  is
81       uninitialized and contains arbitrary bytes.
82
83
84       Raises Invalid_argument if n < 0 or n > Sys.max_string_length .
85
86
87
88       val make : int -> char -> bytes
89
90
91       make n c returns a new byte sequence of length n , filled with the byte
92       c .
93
94
95       Raises Invalid_argument if n < 0 or n > Sys.max_string_length .
96
97
98
99       val init : int -> (int -> char) -> bytes
100
101
102       init n f returns a fresh byte sequence of length n , with  character  i
103       initialized to the result of f i (in increasing index order).
104
105
106       Raises Invalid_argument if n < 0 or n > Sys.max_string_length .
107
108
109
110       val empty : bytes
111
112       A byte sequence of size 0.
113
114
115
116       val copy : bytes -> bytes
117
118       Return  a  new  byte sequence that contains the same bytes as the argu‐
119       ment.
120
121
122
123       val of_string : string -> bytes
124
125       Return a new byte sequence that contains the same bytes  as  the  given
126       string.
127
128
129
130       val to_string : bytes -> string
131
132       Return  a new string that contains the same bytes as the given byte se‐
133       quence.
134
135
136
137       val sub : bytes -> int -> int -> bytes
138
139
140       sub s pos len returns a new byte sequence of length  len  ,  containing
141       the subsequence of s that starts at position pos and has length len .
142
143
144       Raises  Invalid_argument  if pos and len do not designate a valid range
145       of s .
146
147
148
149       val sub_string : bytes -> int -> int -> string
150
151       Same as Bytes.sub but return a string instead of a byte sequence.
152
153
154
155       val extend : bytes -> int -> int -> bytes
156
157
158       extend s left right returns a new byte sequence that contains the bytes
159       of  s , with left uninitialized bytes prepended and right uninitialized
160       bytes appended to it. If left or right is negative, then bytes are  re‐
161       moved (instead of appended) from the corresponding side of s .
162
163
164       Since 4.05.0 in BytesLabels
165
166
167       Raises Invalid_argument if the result length is negative or longer than
168       Sys.max_string_length bytes.
169
170
171
172       val fill : bytes -> int -> int -> char -> unit
173
174
175       fill s pos len c modifies s in place, replacing len characters with c ,
176       starting at pos .
177
178
179       Raises  Invalid_argument  if pos and len do not designate a valid range
180       of s .
181
182
183
184       val blit : bytes -> int -> bytes -> int -> int -> unit
185
186
187       blit src src_pos dst dst_pos len copies len bytes from sequence  src  ,
188       starting at index src_pos , to sequence dst , starting at index dst_pos
189       . It works correctly even if src and dst are the  same  byte  sequence,
190       and the source and destination intervals overlap.
191
192
193       Raises  Invalid_argument  if  src_pos  and len do not designate a valid
194       range of src , or if dst_pos and len do not designate a valid range  of
195       dst .
196
197
198
199       val blit_string : string -> int -> bytes -> int -> int -> unit
200
201
202       blit  src  src_pos  dst  dst_pos len copies len bytes from string src ,
203       starting at index src_pos , to byte sequence dst ,  starting  at  index
204       dst_pos .
205
206
207       Since 4.05.0 in BytesLabels
208
209
210       Raises  Invalid_argument  if  src_pos  and len do not designate a valid
211       range of src , or if dst_pos and len do not designate a valid range  of
212       dst .
213
214
215
216       val concat : bytes -> bytes list -> bytes
217
218
219       concat  sep  sl  concatenates the list of byte sequences sl , inserting
220       the separator byte sequence sep between each, and returns the result as
221       a new byte sequence.
222
223
224       Raises    Invalid_argument    if    the    result    is   longer   than
225       Sys.max_string_length bytes.
226
227
228
229       val cat : bytes -> bytes -> bytes
230
231
232       cat s1 s2 concatenates s1 and s2 and returns the result as a  new  byte
233       sequence.
234
235
236       Since 4.05.0 in BytesLabels
237
238
239       Raises    Invalid_argument    if    the    result    is   longer   than
240       Sys.max_string_length bytes.
241
242
243
244       val iter : (char -> unit) -> bytes -> unit
245
246
247       iter f s applies function f in turn to all the bytes  of  s  .   It  is
248       equivalent to f (get s 0); f (get s 1); ...; f (get s
249           (length s - 1)); () .
250
251
252
253       val iteri : (int -> char -> unit) -> bytes -> unit
254
255       Same  as  Bytes.iter  , but the function is applied to the index of the
256       byte as first argument and the byte itself as second argument.
257
258
259
260       val map : (char -> char) -> bytes -> bytes
261
262
263       map f s applies function f in turn to all the bytes of s (in increasing
264       index  order)  and stores the resulting bytes in a new sequence that is
265       returned as the result.
266
267
268
269       val mapi : (int -> char -> char) -> bytes -> bytes
270
271
272       mapi f s calls f with each character of s and its index (in  increasing
273       index  order)  and stores the resulting bytes in a new sequence that is
274       returned as the result.
275
276
277
278       val fold_left : ('a -> char -> 'a) -> 'a -> bytes -> 'a
279
280
281       fold_left f x s computes f (... (f (f x (get s 0)) (get s 1)) ...) (get
282       s (n-1)) , where n is the length of s .
283
284
285       Since 4.13.0
286
287
288
289       val fold_right : (char -> 'a -> 'a) -> bytes -> 'a -> 'a
290
291
292       fold_right  f  s  x  computes  f (get s 0) (f (get s 1) ( ... (f (get s
293       (n-1)) x) ...))  , where n is the length of s .
294
295
296       Since 4.13.0
297
298
299
300       val for_all : (char -> bool) -> bytes -> bool
301
302
303       for_all p s checks if all characters in s satisfy the predicate p .
304
305
306       Since 4.13.0
307
308
309
310       val exists : (char -> bool) -> bytes -> bool
311
312
313       exists p s checks if at least one character of s satisfies  the  predi‐
314       cate p .
315
316
317       Since 4.13.0
318
319
320
321       val trim : bytes -> bytes
322
323       Return a copy of the argument, without leading and trailing whitespace.
324       The bytes regarded as whitespace are the ASCII characters ' ' ,  '\012'
325       , '\n' , '\r' , and '\t' .
326
327
328
329       val escaped : bytes -> bytes
330
331       Return  a  copy of the argument, with special characters represented by
332       escape sequences, following the  lexical  conventions  of  OCaml.   All
333       characters  outside the ASCII printable range (32..126) are escaped, as
334       well as backslash and double-quote.
335
336
337       Raises   Invalid_argument   if    the    result    is    longer    than
338       Sys.max_string_length bytes.
339
340
341
342       val index : bytes -> char -> int
343
344
345       index s c returns the index of the first occurrence of byte c in s .
346
347
348       Raises Not_found if c does not occur in s .
349
350
351
352       val index_opt : bytes -> char -> int option
353
354
355       index_opt  s c returns the index of the first occurrence of byte c in s
356       or None if c does not occur in s .
357
358
359       Since 4.05
360
361
362
363       val rindex : bytes -> char -> int
364
365
366       rindex s c returns the index of the last occurrence of byte c in s .
367
368
369       Raises Not_found if c does not occur in s .
370
371
372
373       val rindex_opt : bytes -> char -> int option
374
375
376       rindex_opt s c returns the index of the last occurrence of byte c in  s
377       or None if c does not occur in s .
378
379
380       Since 4.05
381
382
383
384       val index_from : bytes -> int -> char -> int
385
386
387       index_from s i c returns the index of the first occurrence of byte c in
388       s after position i .  index s c is equivalent to index_from s 0 c .
389
390
391       Raises Invalid_argument if i is not a valid position in s .
392
393
394       Raises Not_found if c does not occur in s after position i .
395
396
397
398       val index_from_opt : bytes -> int -> char -> int option
399
400
401       index_from_opt s i c returns the index of the first occurrence of  byte
402       c in s after position i or None if c does not occur in s after position
403       i .  index_opt s c is equivalent to index_from_opt s 0 c .
404
405
406       Since 4.05
407
408
409       Raises Invalid_argument if i is not a valid position in s .
410
411
412
413       val rindex_from : bytes -> int -> char -> int
414
415
416       rindex_from s i c returns the index of the last occurrence of byte c in
417       s  before  position  i+1  .   rindex s c is equivalent to rindex_from s
418       (length s - 1) c .
419
420
421       Raises Invalid_argument if i+1 is not a valid position in s .
422
423
424       Raises Not_found if c does not occur in s before position i+1 .
425
426
427
428       val rindex_from_opt : bytes -> int -> char -> int option
429
430
431       rindex_from_opt s i c returns the index of the last occurrence of  byte
432       c  in s before position i+1 or None if c does not occur in s before po‐
433       sition i+1 .  rindex_opt s c is equivalent to rindex_from s (length s -
434       1) c .
435
436
437       Since 4.05
438
439
440       Raises Invalid_argument if i+1 is not a valid position in s .
441
442
443
444       val contains : bytes -> char -> bool
445
446
447       contains s c tests if byte c appears in s .
448
449
450
451       val contains_from : bytes -> int -> char -> bool
452
453
454       contains_from  s  start  c  tests if byte c appears in s after position
455       start .  contains s c is equivalent to contains_from
456           s 0 c .
457
458
459       Raises Invalid_argument if start is not a valid position in s .
460
461
462
463       val rcontains_from : bytes -> int -> char -> bool
464
465
466       rcontains_from s stop c tests if byte c appears in  s  before  position
467       stop+1 .
468
469
470       Raises  Invalid_argument  if stop < 0 or stop+1 is not a valid position
471       in s .
472
473
474
475       val uppercase : bytes -> bytes
476
477       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
478       cated.
479
480
481       Return a copy of the argument, with all lowercase letters translated to
482       uppercase, including accented letters of the ISO Latin-1 (8859-1) char‐
483       acter set.
484
485
486
487       val lowercase : bytes -> bytes
488
489       Deprecated.   Functions  operating  on Latin-1 character set are depre‐
490       cated.
491
492
493       Return a copy of the argument, with all uppercase letters translated to
494       lowercase, including accented letters of the ISO Latin-1 (8859-1) char‐
495       acter set.
496
497
498
499       val capitalize : bytes -> bytes
500
501       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
502       cated.
503
504
505       Return  a  copy of the argument, with the first character set to upper‐
506       case, using the ISO Latin-1 (8859-1) character set.
507
508
509
510       val uncapitalize : bytes -> bytes
511
512       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
513       cated.
514
515
516       Return  a  copy of the argument, with the first character set to lower‐
517       case, using the ISO Latin-1 (8859-1) character set.
518
519
520
521       val uppercase_ascii : bytes -> bytes
522
523       Return a copy of the argument, with all lowercase letters translated to
524       uppercase, using the US-ASCII character set.
525
526
527       Since 4.03.0 (4.05.0 in BytesLabels)
528
529
530
531       val lowercase_ascii : bytes -> bytes
532
533       Return a copy of the argument, with all uppercase letters translated to
534       lowercase, using the US-ASCII character set.
535
536
537       Since 4.03.0 (4.05.0 in BytesLabels)
538
539
540
541       val capitalize_ascii : bytes -> bytes
542
543       Return a copy of the argument, with the first character set  to  upper‐
544       case, using the US-ASCII character set.
545
546
547       Since 4.03.0 (4.05.0 in BytesLabels)
548
549
550
551       val uncapitalize_ascii : bytes -> bytes
552
553       Return  a  copy of the argument, with the first character set to lower‐
554       case, using the US-ASCII character set.
555
556
557       Since 4.03.0 (4.05.0 in BytesLabels)
558
559
560       type t = bytes
561
562
563       An alias for the type of byte sequences.
564
565
566
567       val compare : t -> t -> int
568
569       The comparison function for byte sequences, with the same specification
570       as  compare .  Along with the type t , this function compare allows the
571       module Bytes to be passed as argument  to  the  functors  Set.Make  and
572       Map.Make .
573
574
575
576       val equal : t -> t -> bool
577
578       The equality function for byte sequences.
579
580
581       Since 4.03.0 (4.05.0 in BytesLabels)
582
583
584
585       val starts_with : prefix:bytes -> bytes -> bool
586
587
588       starts_with ~ prefix s is true if and only if s starts with prefix .
589
590
591       Since 4.13.0
592
593
594
595       val ends_with : suffix:bytes -> bytes -> bool
596
597
598       ends_with suffix s is true if and only if s ends with suffix .
599
600
601       Since 4.13.0
602
603
604
605
606   Unsafe conversions (for advanced users)
607       This  section  describes unsafe, low-level conversion functions between
608       bytes and string . They do not copy the internal data; used improperly,
609       they  can  break  the immutability invariant on strings provided by the
610       -safe-string option. They are available for expert library authors, but
611       for most purposes you should use the always-correct Bytes.to_string and
612       Bytes.of_string instead.
613
614       val unsafe_to_string : bytes -> string
615
616       Unsafely convert a byte sequence into a string.
617
618       To reason about the use of unsafe_to_string , it is convenient to  con‐
619       sider  an "ownership" discipline. A piece of code that manipulates some
620       data "owns" it; there are several disjoint ownership modes, including:
621
622       -Unique ownership: the data may be accessed and mutated
623
624       -Shared ownership: the data has several owners, that  may  only  access
625       it, not mutate it.
626
627       Unique  ownership  is linear: passing the data to another piece of code
628       means giving up ownership (we cannot write the data  again).  A  unique
629       owner  may decide to make the data shared (giving up mutation rights on
630       it), but shared data may not become uniquely-owned again.
631
632
633       unsafe_to_string s can only be used when the caller owns the  byte  se‐
634       quence  s  --  either  uniquely or as shared immutable data. The caller
635       gives up ownership of s , and gains ownership of the returned string.
636
637       There are two valid use-cases that respect this ownership discipline:
638
639       1. Creating a string by initializing and mutating a byte sequence  that
640       is never changed after initialization is performed.
641
642
643       let string_init len f : string =
644         let s = Bytes.create len in
645         for i = 0 to len - 1 do Bytes.set s i (f i) done;
646         Bytes.unsafe_to_string s
647
648
649       This  function  is  safe  because the byte sequence s will never be ac‐
650       cessed or mutated after unsafe_to_string  is  called.  The  string_init
651       code gives up ownership of s , and returns the ownership of the result‐
652       ing string to its caller.
653
654       Note that it would be unsafe if s was passed as an additional parameter
655       to the function f as it could escape this way and be mutated in the fu‐
656       ture -- string_init would give up ownership of s to pass it to f ,  and
657       could not call unsafe_to_string safely.
658
659       We have provided the String.init , String.map and String.mapi functions
660       to cover most cases of building new strings. You  should  prefer  those
661       over to_string or unsafe_to_string whenever applicable.
662
663       2.  Temporarily  giving ownership of a byte sequence to a function that
664       expects a uniquely owned string and returns ownership back, so that  we
665       can mutate the sequence again after the call ended.
666
667
668       let bytes_length (s : bytes) =
669         String.length (Bytes.unsafe_to_string s)
670
671
672       In  this use-case, we do not promise that s will never be mutated after
673       the call to bytes_length s .  The  String.length  function  temporarily
674       borrows  unique ownership of the byte sequence (and sees it as a string
675       ), but returns this ownership back to the caller, which may assume that
676       s is still a valid byte sequence after the call. Note that this is only
677       correct because we know that String.length does not capture  its  argu‐
678       ment  -- it could escape by a side-channel such as a memoization combi‐
679       nator.
680
681       The caller may not mutate s while the string is borrowed (it has tempo‐
682       rarily  given up ownership). This affects concurrent programs, but also
683       higher-order functions: if  String.length  returned  a  closure  to  be
684       called  later,  s should not be mutated until this closure is fully ap‐
685       plied and returns ownership.
686
687
688
689       val unsafe_of_string : string -> bytes
690
691       Unsafely convert a shared string to a byte sequence that should not  be
692       mutated.
693
694       The  same  ownership discipline that makes unsafe_to_string correct ap‐
695       plies to unsafe_of_string : you may use it if you were the owner of the
696       string value, and you will own the return bytes in the same mode.
697
698       In  practice,  unique ownership of string values is extremely difficult
699       to reason about correctly. You should always assume strings are shared,
700       never uniquely owned.
701
702       For  example, string literals are implicitly shared by the compiler, so
703       you never uniquely own them.
704
705
706       let incorrect = Bytes.unsafe_of_string "hello"
707       let s = Bytes.of_string "hello"
708
709
710       The first declaration is incorrect, because the string literal  "hello"
711       could  be  shared  by the compiler with other parts of the program, and
712       mutating incorrect is a bug. You must always use  the  second  version,
713       which performs a copy and is thus correct.
714
715       Assuming  unique ownership of strings that are not string literals, but
716       are (partly) built from string literals, is also incorrect.  For  exam‐
717       ple,  mutating  unsafe_of_string  ("foo"  ^  s) could mutate the shared
718       string "foo" -- assuming a rope-like representation  of  strings.  More
719       generally, functions operating on strings will assume shared ownership,
720       they do not preserve unique ownership. It is thus incorrect  to  assume
721       unique ownership of the result of unsafe_of_string .
722
723       The  only case we have reasonable confidence is safe is if the produced
724       bytes is shared -- used as an immutable byte sequence. This is possibly
725       useful  for incremental migration of low-level programs that manipulate
726       immutable sequences of bytes (for example Marshal.from_bytes ) and pre‐
727       viously used the string type for this purpose.
728
729
730
731       val split_on_char : char -> bytes -> bytes list
732
733
734       split_on_char  sep  s  returns  the list of all (possibly empty) subse‐
735       quences of s that are delimited by the sep character.
736
737       The function's output is specified by the following invariants:
738
739
740       -The list is not empty.
741
742       -Concatenating its elements using sep as a separator returns a byte se‐
743       quence equal to the input ( Bytes.concat (Bytes.make 1 sep)
744             (Bytes.split_on_char sep s) = s ).
745
746       -No byte sequence in the result contains the sep character.
747
748
749
750       Since 4.13.0
751
752
753
754
755   Iterators
756       val to_seq : t -> char Seq.t
757
758       Iterate  on the string, in increasing index order. Modifications of the
759       string during iteration will be reflected in the sequence.
760
761
762       Since 4.07
763
764
765
766       val to_seqi : t -> (int * char) Seq.t
767
768       Iterate on the string, in  increasing  order,  yielding  indices  along
769       chars
770
771
772       Since 4.07
773
774
775
776       val of_seq : char Seq.t -> t
777
778       Create a string from the generator
779
780
781       Since 4.07
782
783
784
785
786   UTF codecs and validations
787   UTF-8
788       val get_utf_8_uchar : t -> int -> Uchar.utf_decode
789
790
791       get_utf_8_uchar b i decodes an UTF-8 character at index i in b .
792
793
794
795       val set_utf_8_uchar : t -> int -> Uchar.t -> int
796
797
798       set_utf_8_uchar  b  i u UTF-8 encodes u at index i in b and returns the
799       number of bytes n that were written starting at i . If n is 0 there was
800       not enough space to encode u at i and b was left untouched. Otherwise a
801       new character can be encoded at i + n .
802
803
804
805       val is_valid_utf_8 : t -> bool
806
807
808       is_valid_utf_8 b is true if and only if b contains valid UTF-8 data.
809
810
811
812
813   UTF-16BE
814       val get_utf_16be_uchar : t -> int -> Uchar.utf_decode
815
816
817       get_utf_16be_uchar b i decodes an UTF-16BE character at index i in b .
818
819
820
821       val set_utf_16be_uchar : t -> int -> Uchar.t -> int
822
823
824       set_utf_16be_uchar b i u UTF-16BE encodes u at index i in b and returns
825       the number of bytes n that were written starting at i . If n is 0 there
826       was not enough space to encode u at i and b was left untouched.  Other‐
827       wise a new character can be encoded at i + n .
828
829
830
831       val is_valid_utf_16be : t -> bool
832
833
834       is_valid_utf_16be  b  is  true if and only if b contains valid UTF-16BE
835       data.
836
837
838
839
840   UTF-16LE
841       val get_utf_16le_uchar : t -> int -> Uchar.utf_decode
842
843
844       get_utf_16le_uchar b i decodes an UTF-16LE character at index i in b .
845
846
847
848       val set_utf_16le_uchar : t -> int -> Uchar.t -> int
849
850
851       set_utf_16le_uchar b i u UTF-16LE encodes u at index i in b and returns
852       the number of bytes n that were written starting at i . If n is 0 there
853       was not enough space to encode u at i and b was left untouched.  Other‐
854       wise a new character can be encoded at i + n .
855
856
857
858       val is_valid_utf_16le : t -> bool
859
860
861       is_valid_utf_16le  b  is  true if and only if b contains valid UTF-16LE
862       data.
863
864
865
866
867   Binary encoding/decoding of integers
868       The functions in this section binary encode and decode integers to  and
869       from byte sequences.
870
871       All  following  functions raise Invalid_argument if the space needed at
872       index i to decode or encode the integer is not available.
873
874       Little-endian (resp. big-endian) encoding means that least (resp. most)
875       significant  bytes  are stored first.  Big-endian is also known as net‐
876       work byte order.  Native-endian encoding  is  either  little-endian  or
877       big-endian depending on Sys.big_endian .
878
879       32-bit  and  64-bit  integers  are  represented  by the int32 and int64
880       types, which can be interpreted either as signed or unsigned numbers.
881
882       8-bit and 16-bit integers are represented by the int  type,  which  has
883       more  bits  than  the binary encoding.  These extra bits are handled as
884       follows:
885
886       -Functions that decode signed (resp. unsigned) 8-bit or 16-bit integers
887       represented by int values sign-extend (resp. zero-extend) their result.
888
889       -Functions that encode 8-bit or 16-bit integers represented by int val‐
890       ues truncate their input to their least significant bytes.
891
892
893       val get_uint8 : bytes -> int -> int
894
895
896       get_uint8 b i is b 's unsigned 8-bit integer starting at byte index i .
897
898
899       Since 4.08
900
901
902
903       val get_int8 : bytes -> int -> int
904
905
906       get_int8 b i is b 's signed 8-bit integer starting at byte index i .
907
908
909       Since 4.08
910
911
912
913       val get_uint16_ne : bytes -> int -> int
914
915
916       get_uint16_ne b i is b 's native-endian unsigned 16-bit integer  start‐
917       ing at byte index i .
918
919
920       Since 4.08
921
922
923
924       val get_uint16_be : bytes -> int -> int
925
926
927       get_uint16_be  b  i is b 's big-endian unsigned 16-bit integer starting
928       at byte index i .
929
930
931       Since 4.08
932
933
934
935       val get_uint16_le : bytes -> int -> int
936
937
938       get_uint16_le b i is b 's little-endian unsigned 16-bit integer  start‐
939       ing at byte index i .
940
941
942       Since 4.08
943
944
945
946       val get_int16_ne : bytes -> int -> int
947
948
949       get_int16_ne  b  i is b 's native-endian signed 16-bit integer starting
950       at byte index i .
951
952
953       Since 4.08
954
955
956
957       val get_int16_be : bytes -> int -> int
958
959
960       get_int16_be b i is b 's big-endian signed 16-bit integer  starting  at
961       byte index i .
962
963
964       Since 4.08
965
966
967
968       val get_int16_le : bytes -> int -> int
969
970
971       get_int16_le  b  i is b 's little-endian signed 16-bit integer starting
972       at byte index i .
973
974
975       Since 4.08
976
977
978
979       val get_int32_ne : bytes -> int -> int32
980
981
982       get_int32_ne b i is b 's native-endian 32-bit integer starting at  byte
983       index i .
984
985
986       Since 4.08
987
988
989
990       val get_int32_be : bytes -> int -> int32
991
992
993       get_int32_be b i is b 's big-endian 32-bit integer starting at byte in‐
994       dex i .
995
996
997       Since 4.08
998
999
1000
1001       val get_int32_le : bytes -> int -> int32
1002
1003
1004       get_int32_le b i is b 's little-endian 32-bit integer starting at  byte
1005       index i .
1006
1007
1008       Since 4.08
1009
1010
1011
1012       val get_int64_ne : bytes -> int -> int64
1013
1014
1015       get_int64_ne  b i is b 's native-endian 64-bit integer starting at byte
1016       index i .
1017
1018
1019       Since 4.08
1020
1021
1022
1023       val get_int64_be : bytes -> int -> int64
1024
1025
1026       get_int64_be b i is b 's big-endian 64-bit integer starting at byte in‐
1027       dex i .
1028
1029
1030       Since 4.08
1031
1032
1033
1034       val get_int64_le : bytes -> int -> int64
1035
1036
1037       get_int64_le  b i is b 's little-endian 64-bit integer starting at byte
1038       index i .
1039
1040
1041       Since 4.08
1042
1043
1044
1045       val set_uint8 : bytes -> int -> int -> unit
1046
1047
1048       set_uint8 b i v sets b 's unsigned 8-bit integer starting at byte index
1049       i to v .
1050
1051
1052       Since 4.08
1053
1054
1055
1056       val set_int8 : bytes -> int -> int -> unit
1057
1058
1059       set_int8  b i v sets b 's signed 8-bit integer starting at byte index i
1060       to v .
1061
1062
1063       Since 4.08
1064
1065
1066
1067       val set_uint16_ne : bytes -> int -> int -> unit
1068
1069
1070       set_uint16_ne b i v sets b 's  native-endian  unsigned  16-bit  integer
1071       starting at byte index i to v .
1072
1073
1074       Since 4.08
1075
1076
1077
1078       val set_uint16_be : bytes -> int -> int -> unit
1079
1080
1081       set_uint16_be b i v sets b 's big-endian unsigned 16-bit integer start‐
1082       ing at byte index i to v .
1083
1084
1085       Since 4.08
1086
1087
1088
1089       val set_uint16_le : bytes -> int -> int -> unit
1090
1091
1092       set_uint16_le b i v sets b 's  little-endian  unsigned  16-bit  integer
1093       starting at byte index i to v .
1094
1095
1096       Since 4.08
1097
1098
1099
1100       val set_int16_ne : bytes -> int -> int -> unit
1101
1102
1103       set_int16_ne b i v sets b 's native-endian signed 16-bit integer start‐
1104       ing at byte index i to v .
1105
1106
1107       Since 4.08
1108
1109
1110
1111       val set_int16_be : bytes -> int -> int -> unit
1112
1113
1114       set_int16_be b i v sets b 's big-endian signed 16-bit integer  starting
1115       at byte index i to v .
1116
1117
1118       Since 4.08
1119
1120
1121
1122       val set_int16_le : bytes -> int -> int -> unit
1123
1124
1125       set_int16_le b i v sets b 's little-endian signed 16-bit integer start‐
1126       ing at byte index i to v .
1127
1128
1129       Since 4.08
1130
1131
1132
1133       val set_int32_ne : bytes -> int -> int32 -> unit
1134
1135
1136       set_int32_ne b i v sets b 's native-endian 32-bit integer  starting  at
1137       byte index i to v .
1138
1139
1140       Since 4.08
1141
1142
1143
1144       val set_int32_be : bytes -> int -> int32 -> unit
1145
1146
1147       set_int32_be b i v sets b 's big-endian 32-bit integer starting at byte
1148       index i to v .
1149
1150
1151       Since 4.08
1152
1153
1154
1155       val set_int32_le : bytes -> int -> int32 -> unit
1156
1157
1158       set_int32_le b i v sets b 's little-endian 32-bit integer  starting  at
1159       byte index i to v .
1160
1161
1162       Since 4.08
1163
1164
1165
1166       val set_int64_ne : bytes -> int -> int64 -> unit
1167
1168
1169       set_int64_ne  b  i v sets b 's native-endian 64-bit integer starting at
1170       byte index i to v .
1171
1172
1173       Since 4.08
1174
1175
1176
1177       val set_int64_be : bytes -> int -> int64 -> unit
1178
1179
1180       set_int64_be b i v sets b 's big-endian 64-bit integer starting at byte
1181       index i to v .
1182
1183
1184       Since 4.08
1185
1186
1187
1188       val set_int64_le : bytes -> int -> int64 -> unit
1189
1190
1191       set_int64_le  b  i v sets b 's little-endian 64-bit integer starting at
1192       byte index i to v .
1193
1194
1195       Since 4.08
1196
1197
1198
1199
1200
1201OCamldoc                          2022-07-22                          Bytes(3)
Impressum