Code Monkey home page Code Monkey logo

Comments (2)

hcarty avatar hcarty commented on September 5, 2024

Do you have an example of what you would want the interface to look like? I could see something along the lines of the following being simple but useful wrappers:

val make_send : ('a -> string list) -> _ Lwt_zmq.Socket.t -> ('a -> unit Lwt.t)
val make_recv : (string list -> 'a) -> _ Lwt_zmq.Socket.t -> (unit -> 'a Lwt.t)

val make_send_s : ('a -> string list Lwt.t) -> _ Lwt_zmq.Socket.t -> ('a -> unit Lwt.t)
val make_recv_s : (string list -> 'a Lwt.t) -> _ Lwt_zmq.Socket.t -> (unit -> 'a Lwt.t)

make_send to_message socket would return a function which sends values over socket, serialized by to_message.

make_recv of_message socket would return a function which received values over socket, deserialized by of_message.

The _s versions would take a cooperative function for the (de)serialization process.

from lwt-zmq.

mryau avatar mryau commented on September 5, 2024

Hello,

currently I need only properly typed messages on zmq bus so I prefer following modification of your code with functor:

module type IDType = sig
  type t
  val to_string : t -> string
  val of_string : string -> t
end

module FLSocket(DType : IDType) = struct

  type 'a t = {
    socket : 'a ZMQ.Socket.t;
    fd : Lwt_unix.file_descr;
  }

...
  let recv s =
    wrap (fun s -> let r = ZMQ.Socket.recv ~block:false s in DType.of_string r) s

  let send ?more s m =
    wrap (fun s -> ZMQ.Socket.send ?more ~block:false s (DType.to_string m)) s
...
end

type vlan = int list [@@deriving protobuf { protoc }]
type io =
        | Port of int [@key 1]
        | Agg of int [@key 2]
        | Vlan of vlan [@key 3]
        [@@deriving protobuf { protoc }]

type router = io list [@@deriving protobuf { protoc }]

module LSocket =
  FLSocket(struct
    type t = router
    let to_string = Protobuf.Encoder.encode_exn router_to_protobuf
    let of_string = Protobuf.Decoder.decode_exn router_from_protobuf
  end)

I don't know should I send such modification as pull request to your repository?

from lwt-zmq.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.