a way to send notifies

This commit is contained in:
xeon 2024-08-04 19:41:49 +03:00
parent b62a013017
commit b82fd888f3
2 changed files with 11 additions and 3 deletions

View file

@ -26,6 +26,7 @@ let handle pk =
| None -> printf "unhandled cmd: %d\n%!" pk.cmd; None
let rec run ic oc =
let open Packet in
let* pk = read ic in
let head = Hex.show (Hex.of_string pk.head) in
@ -34,7 +35,7 @@ let rec run ic oc =
printf "packet cmd: %d, head: %s, body: %s\n%!" pk.cmd head body;
let* () = match handle pk with
| Some pk -> write oc pk
|Some res -> (Lwt_list.iter_s (fun pk -> write oc pk) res.packets)
| None -> return_unit
in

View file

@ -2,6 +2,7 @@ open Lwt
open Lwt.Syntax
type packet = { cmd: int; head: string; body: string }
type net_result = { packets: packet list }
let read ic =
let open Lwt_io in
@ -32,11 +33,17 @@ let write oc pk =
let* () = flush oc in
return_unit
let pack cmd en data =
let build cmd en data =
let encoder = Pbrt.Encoder.create () in
en data encoder;
let buf = Pbrt.Encoder.to_string encoder in
{ cmd = cmd; head = ""; body = buf; }
let empty cmd = { cmd = cmd; head = ""; body = "" }
let pack cmd en data =
{ packets = [ (build cmd en data) ] }
let merge result pk =
{ packets = pk :: result.packets }
let empty cmd = {packets = [{ cmd = cmd; head = ""; body = "" }]}