diff --git a/src/node/updater/environment.ml b/src/node/updater/environment.ml index 015008fb9..9e1246d4a 100644 --- a/src/node/updater/environment.ml +++ b/src/node/updater/environment.ml @@ -134,8 +134,16 @@ module Make(Param : sig val name: string end)() = struct module Compare = Compare module Array = Array module List = List - module Bytes = Bytes - module String = String + module Bytes = struct + 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 Map = Map module Int32 = Int32 diff --git a/src/proto/environment/bytes.mli b/src/proto/environment/bytes.mli index 3b03382ce..746bf1c3c 100644 --- a/src/proto/environment/bytes.mli +++ b/src/proto/environment/bytes.mli @@ -420,14 +420,79 @@ let s = Bytes.of_string "hello" [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" -external unsafe_set : bytes -> int -> char -> unit = "%string_unsafe_set" -external unsafe_blit : - bytes -> int -> bytes -> int -> int -> unit - = "caml_blit_string" [@@noalloc] -external unsafe_fill : - bytes -> int -> int -> char -> unit = "caml_fill_string" [@@noalloc] +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 *) + +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 diff --git a/src/proto/environment/string.mli b/src/proto/environment/string.mli index 6b9c7f577..50693ff14 100644 --- a/src/proto/environment/string.mli +++ b/src/proto/environment/string.mli @@ -238,3 +238,53 @@ val compare: t -> t -> int {!Pervasives.compare}. Along with the type [t], this function [compare] allows the module [String] to be passed as argument to the functors {!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