Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sample go to hit the driver-if for a Link Assoc
- // TG sends Thrift messages over zmq sockets ...
- package main
- import (
- "context"
- "fmt"
- "os"
- ctrl "controller"
- drv "drivermessage"
- thrift "git.apache.org/thrift.git/lib/go/thrift"
- zmq "github.com/pebbe/zmq4"
- )
- func deserializeDriverThrift([]byte data) (drv.ttypes.DriverDevAllocRes, error) {
- dr_response = drv.ttypes.DriverDevAllocRes()
- return dr_response, nil
- }
- func serializeDriverThrift(driverMesasge drv.ttypes.DriverMessage) ([]byte, error) {
- var messageBytes []byte
- buffer := thrift.NewMemoryBufferLen(1024)
- proto := thrift.NewCompactProtocol(buffer)
- serializer := &thrift.TSerializer{
- Transport: buffer,
- Protocol: proto,
- }
- defer serializer.Transport.Close()
- err := serializer.Read(&messageBytes, driverMesasge)
- return messageBytes, err
- }
- func main() {
- connect_str := "tcp://localhost:18990"
- requester, _ := zmq.NewSocket(zmq.REQ)
- defer requester.Close()
- requester.Connect(connect_str)
- fmt.Println("Connected to ", connect_str)
- dr_msg := drv.ttypes.DriverMessage()
- dr_msg.radioMac = "69:69:69:69:69:69"
- dr_msg.value = drv.ttypes.DriverDevAllocReq(dr_msg.radioMac)
- dr_mgs_bytes, err = serializeDriverThrift(dr_msg)
- if err != nil:
- fmt.Println("Error with serialzing dr_msg")
- os.Exit(1)
- msg = ctrl.ttypes.Message(ctrl.ttypes.MessageType.DR_DEV_ALLOC_REQ,
- dr_mgs_bytes)
- fmt.Println("Sending ", msg)
- requester.Send(msg, 0)
- // Wait for reply - need to
- reply, _ := requester.Recv(0)
- fmt.Println("Received ", reply)
- // TODO: deserialize with Thrift
- deserializeDriverThrift(reply)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement