To start off, it is worth mentioning that within a single F# solution, serializing and deserializing of Bond messages works fine. However, I am having trouble properly handling the sending and/or receiving of the message over ZeroMQ.
There is a runtime error on the subscriber side of the following program. A .bond file is defined and compiled with the bond compiler. Then a dll is created from C# to be called from F# . I then have two F# programs. One that publishes serialized data over a tcp socket and another that is a subscriber. When the message is received on the sub, the line which tries to Unmarshal the raw data is the one that causes the runtime error. Can anyone see the reason for this?
[EDIT] Per Fyodor's comment, I made a change on the publisher side which changes the error on the subscriber side. So the error likely has something to do with how i am packing and unpacking the information.
This is the .bond file
namespace Examples
struct Record
{
0: map<string, double> payload;
}
Here is the publisher:
// publisher
open System
open Bond
open Bond.Protocols
open Bond.IO.Safe
open ZeroMQ
let ctx = new ZContext()
let publisher = new ZSocket(ctx, ZSocketType.PUB)
publisher.Bind("tcp://*:5556")
let src = new Examples.Record()
src.payload.Add("a", 1.)
src.payload.Add("b", 2.)
let output = new OutputBuffer()
let writer = new CompactBinaryWriter<OutputBuffer>(output)
while true do
Marshal.To(writer, src)
//let input = new InputBuffer(output.Data)
//let byteArr = input.ReadBytes(int(input.Length - 1L))
let updateFrame = new ZFrame(System.Text.Encoding.ASCII.GetString output.Data.Array)
publisher.Send(updateFrame)
Here is the subscriber:
// subscriber
open Bond
open Bond.Protocols
open Bond.IO.Safe
open System
open System.Text
open ZeroMQ
let ctx = new ZContext()
let subscriber = new ZSocket(ctx, ZSocketType.SUB)
subscriber.Connect("tcp://127.0.0.1:5556")
subscriber.SubscribeAll()
let output = new OutputBuffer()
while true do
let received = subscriber.ReceiveFrame()
let byteArr = Encoding.ASCII.GetBytes (received.ReadString())
let arrSeg = ArraySegment<byte>(byteArr)
let input = new InputBuffer(arrSeg)
let dst = Unmarshal<Examples.Record>.From(input)
for KeyValue(k, v) in dst.payload do
printfn "%A %A" k v