ReadFromUDP can return a packet of any size, from 1 to 2000 bytes, you
need to reslice your buffer using the number of bytes actually read.
json.Unmarshal(buf[:n], &msg)
Also, there is no guarantee that ReadFromUDP will return a complete json blob.
On Fri, Sep 21, 2012 at 5:42 PM, Huanchen Zhang <
iamzh...@gmail.com> wrote:
> Hi,
>
> When I try to umarshal a byte array received via udp, and I get the the
> following error %!(EXTRA string=invalid character '\x00' after top-level
> value).
>
> Following are my codes:
>
> buf := make([]byte, 2000)
> n, _, err:= cli.udpConn.ReadFromUDP(buf)
> var msg Message
> json.Unmarshal(buf, &msg)
>
> Anyone has any idea ?
>
> Thank you !
> Huanchen
>
> --
>
>