Shell: export Bytes.{get,set}_intXX to the proto

This commit is contained in:
Grégoire Henry 2016-11-17 02:06:50 +01:00
parent a55f31bc9b
commit 938ff6404b
3 changed files with 134 additions and 11 deletions

View File

@ -134,8 +134,16 @@ module Make(Param : sig val name: string end)() = struct
module Compare = Compare module Compare = Compare
module Array = Array module Array = Array
module List = List module List = List
module Bytes = Bytes module Bytes = struct
module String = String include Bytes
include EndianBytes.BigEndian
module LE = EndianBytes.LittleEndian
end
module String = struct
include String
include EndianString.BigEndian
module LE = EndianString.LittleEndian
end
module Set = Set module Set = Set
module Map = Map module Map = Map
module Int32 = Int32 module Int32 = Int32

View File

@ -420,14 +420,79 @@ let s = Bytes.of_string "hello"
[string] type for this purpose. [string] type for this purpose.
*) *)
(**/**) (** Functions reading and writing bytes *)
(* The following is for system use only. Do not call directly. *) val get_char: t -> int -> char
(** [get_char buff i] reads 1 byte at offset i as a char *)
external unsafe_get : bytes -> int -> char = "%string_unsafe_get" val get_uint8: t -> int -> int
external unsafe_set : bytes -> int -> char -> unit = "%string_unsafe_set" (** [get_uint8 buff i] reads 1 byte at offset i as an unsigned int of 8
external unsafe_blit : bits. i.e. It returns a value between 0 and 2^8-1 *)
bytes -> int -> bytes -> int -> int -> unit
= "caml_blit_string" [@@noalloc] val get_int8: t -> int -> int
external unsafe_fill : (** [get_int8 buff i] reads 1 byte at offset i as a signed int of 8
bytes -> int -> int -> char -> unit = "caml_fill_string" [@@noalloc] bits. i.e. It returns a value between -2^7 and 2^7-1 *)
val set_char: t -> int -> char -> unit
(** [set_char buff i v] writes [v] to [buff] at offset [i] *)
val set_int8: t -> int -> int -> unit
(** [set_int8 buff i v] writes the least significant 8 bits of [v]
to [buff] at offset [i] *)
(** Functions reading according to Big Endian byte order *)
val get_uint16: t -> int -> int
(** [get_uint16 buff i] reads 2 bytes at offset i as an unsigned int
of 16 bits. i.e. It returns a value between 0 and 2^16-1 *)
val get_int16: t -> int -> int
(** [get_int16 buff i] reads 2 byte at offset i as a signed int of
16 bits. i.e. It returns a value between -2^15 and 2^15-1 *)
val get_int32: t -> int -> int32
(** [get_int32 buff i] reads 4 bytes at offset i as an int32. *)
val get_int64: t -> int -> int64
(** [get_int64 buff i] reads 8 bytes at offset i as an int64. *)
val set_int16: t -> int -> int -> unit
(** [set_int16 buff i v] writes the least significant 16 bits of [v]
to [buff] at offset [i] *)
val set_int32: t -> int -> int32 -> unit
(** [set_int32 buff i v] writes [v] to [buff] at offset [i] *)
val set_int64: t -> int -> int64 -> unit
(** [set_int64 buff i v] writes [v] to [buff] at offset [i] *)
module LE: sig
(** Functions reading according to Little Endian byte order *)
val get_uint16: t -> int -> int
(** [get_uint16 buff i] reads 2 bytes at offset i as an unsigned int
of 16 bits. i.e. It returns a value between 0 and 2^16-1 *)
val get_int16: t -> int -> int
(** [get_int16 buff i] reads 2 byte at offset i as a signed int of
16 bits. i.e. It returns a value between -2^15 and 2^15-1 *)
val get_int32: t -> int -> int32
(** [get_int32 buff i] reads 4 bytes at offset i as an int32. *)
val get_int64: t -> int -> int64
(** [get_int64 buff i] reads 8 bytes at offset i as an int64. *)
val set_int16: t -> int -> int -> unit
(** [set_int16 buff i v] writes the least significant 16 bits of [v]
to [buff] at offset [i] *)
val set_int32: t -> int -> int32 -> unit
(** [set_int32 buff i v] writes [v] to [buff] at offset [i] *)
val set_int64: t -> int -> int64 -> unit
(** [set_int64 buff i v] writes [v] to [buff] at offset [i] *)
end

View File

@ -238,3 +238,53 @@ val compare: t -> t -> int
{!Pervasives.compare}. Along with the type [t], this function [compare] {!Pervasives.compare}. Along with the type [t], this function [compare]
allows the module [String] to be passed as argument to the functors allows the module [String] to be passed as argument to the functors
{!Set.Make} and {!Map.Make}. *) {!Set.Make} and {!Map.Make}. *)
(** Functions reading bytes *)
val get_char: t -> int -> char
(** [get_char buff i] reads 1 byte at offset i as a char *)
val get_uint8: t -> int -> int
(** [get_uint8 buff i] reads 1 byte at offset i as an unsigned int of 8
bits. i.e. It returns a value between 0 and 2^8-1 *)
val get_int8: t -> int -> int
(** [get_int8 buff i] reads 1 byte at offset i as a signed int of 8
bits. i.e. It returns a value between -2^7 and 2^7-1 *)
(** Functions reading according to Big Endian byte order *)
val get_uint16: t -> int -> int
(** [get_uint16 buff i] reads 2 bytes at offset i as an unsigned int
of 16 bits. i.e. It returns a value between 0 and 2^16-1 *)
val get_int16: t -> int -> int
(** [get_int16 buff i] reads 2 byte at offset i as a signed int of
16 bits. i.e. It returns a value between -2^15 and 2^15-1 *)
val get_int32: t -> int -> int32
(** [get_int32 buff i] reads 4 bytes at offset i as an int32. *)
val get_int64: t -> int -> int64
(** [get_int64 buff i] reads 8 bytes at offset i as an int64. *)
module LE: sig
(** Functions reading according to Little Endian byte order *)
val get_uint16: t -> int -> int
(** [get_uint16 buff i] reads 2 bytes at offset i as an unsigned int
of 16 bits. i.e. It returns a value between 0 and 2^16-1 *)
val get_int16: t -> int -> int
(** [get_int16 buff i] reads 2 byte at offset i as a signed int of
16 bits. i.e. It returns a value between -2^15 and 2^15-1 *)
val get_int32: t -> int -> int32
(** [get_int32 buff i] reads 4 bytes at offset i as an int32. *)
val get_int64: t -> int -> int64
(** [get_int64 buff i] reads 8 bytes at offset i as an int64. *)
end