I want to send an image through rpc using the golang packet valyala goRPC and I'm having some problems to receive the image type in the server.
This is my client code, who takes an .jpg image, decodes it and send it through rpc:
c := &gorpc.Client{
// TCP address of the server.
Addr: "127.0.0.1:12345",
}
c.Start()
reader, err := os.Open("barranco.jpg")
if err != nil{
log.Fatal(err)
}
defer reader.Close()
img, _, err := image.Decode(reader)
if err != nil {
log.Fatal(err)
}
fmt.Print("Pulsa intro para enviar.\n")
bufio.NewReader(os.Stdin).ReadBytes('\n')
gorpc.RegisterType(img)
resp, err := c.Call(img)
So in this code, I take an image called barranco.jpg, I decode it but before sending it to the server I register the type on the client. My problem is, how can I register that type in the server? I always get the same fail in the server because I can't register that image type /:
Thanks in advance.
Type image.Image
is an interface so you can't register it, it's too abstract. Underlaying implementations for jpeg however are either image.Gray
or image.YCbCr
, both concrete structs, you may type assert img.(Gray)
to decide which. Try to register both image.Gray
and image.YCbCr
, assert which you have have and then send as concrete type.