I'm comming today because I'm stuck and it doesn't seems logic for me.
I have my server (Go) and my smartphone app (Xamarin C#).
For the Xamarin side, I'm using this package -> Sockets Plugin for Xamarin and Windows (PCL)
For the Go side, I'm using encoding/json
Everything in the Xamarin part is working fine. But in the Go side, it doesn't.. I'm using the following code to handle the messages from each net.Conn.
type DialMessageContainer struct {
Type string `json:"Type"`
Content json.RawMessage `json:"Content"`
}
func (dialTCP *DialTCP) serve_conn(conn net.Conn) {
fmt.Println("Handle new connection.")
dec := json.NewDecoder(conn)
var message m.DialMessageContainer
//Use one of the following
printContent(conn)
// --
err := dec.Decode(&message)
fmt.Println(message, err)
//End
conn.Close()
}
func printContent(conn net.Conn) {
var buf bytes.Buffer
io.Copy(&buf, conn)
fmt.Println(buf.String())
}
So, the type is here to let it know which type of json it is. From this type string, it then unmarshal a json from the json.RawmMessage Content to the good object. I know it works, however when I try to recreate my object from the following json, I get this error:
(printContent no commented, then Decode has nothing to read, it's for the debug trace test)
....
Handle new connection.
{
"Type": "Authentication",
"Content": {
"UUID": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Im1heGltZS1ndWl0dGV0QG91dGxvb2suY29tIiwiZXhwIjoxNDYyNjM4MTkzfQ.DEGJcDYl9Iq4nayo37Rq9ZsK8mrU-V8gU5I8JLO8oLg"
}
}
{ []} EOF
So, when I hide the printContent(conn), the dec.Decode gives this:
....
Handle new connection.
{ []} invalid character '\x00' looking for beginning of object key string
The thing that I ask to myself is : "Does \x00 means the NULL CHAR of the ascii table?". If this error comes because of this char, so where does it is? Moreover, if it's this char, maybe it is just present to mark the end point of the string (use of '\0' in C to mark the end of a char*/char[]).
But, maybe I'm totaly wrong.. Honestly I'm stuck and I don't understand.. Aynway, JSONLint says it's a valid JSON so it can only be something about the reading I think
If anyone can help, thank !