This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
generated from Nymphium/ocaml-nix-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
338 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,45 @@ | ||
open Import | ||
include T.Byte_buffer | ||
include F.Byte_buffer | ||
|
||
open struct | ||
module M = struct | ||
module T = T.Byte_buffer | ||
module F = F.Byte_buffer | ||
end | ||
module Reader = struct | ||
include T.Byte_buffer.Reader | ||
include F.Byte_buffer.Reader | ||
|
||
type raw = t | ||
|
||
let raw = t | ||
end | ||
|
||
type raw = t | ||
|
||
let raw = t | ||
|
||
let allocate () = | ||
let finalise t = F.Byte_buffer.destroy @@ Ctypes.addr t in | ||
let t = Ctypes.make ~finalise T.Byte_buffer.t in | ||
t @. T.Byte_buffer.reserved <-@ __reserved__; | ||
let finalise t = destroy @@ Ctypes.addr t in | ||
let t = Ctypes.make ~finalise raw in | ||
t @. reserved <-@ __reserved__; | ||
Ctypes.addr t | ||
;; | ||
|
||
let length b = Unsigned.Size_t.to_int @@ F.Byte_buffer.length b | ||
let destroy = F.Byte_buffer.destroy | ||
let length = Unsigned.Size_t.to_int <@ length | ||
|
||
let from_string ?(copy = false) s = | ||
let slice_of_string = | ||
if copy then F.Slice.from_copied_string else F.Slice.from_static_string | ||
in | ||
let slice = slice_of_string s in | ||
let buf = F.Byte_buffer.create_raw (Ctypes.addr slice) (Unsigned.Size_t.of_int 1) in | ||
let () = F.Slice.unref slice in | ||
let from_string ?copy s = | ||
let slice = Slice.from_string ?copy s in | ||
let buf = create_raw (Ctypes.addr slice) (Unsigned.Size_t.of_int 1) in | ||
let () = Slice.unref slice in | ||
buf | ||
;; | ||
|
||
let to_string_opt b = | ||
if Ctypes.is_null b | ||
then None | ||
else ( | ||
let reader = malloc T.Byte_buffer.Reader.t in | ||
let is_buf_reader_initialized = 0 < F.Byte_buffer.Reader.init reader b in | ||
let reader = malloc Reader.t in | ||
let is_buf_reader_initialized = 0 < Reader.init reader b in | ||
if not is_buf_reader_initialized | ||
then failwith "Error initializing byte_buffer_reader" | ||
else ( | ||
let b = F.Byte_buffer.Reader.readall reader in | ||
let b = Reader.readall reader in | ||
Some (Slice.to_string b))) | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.