On Wed, Dec 30, 2020 at 4:07 AM Amnon wrote:
>
> How do you know, if you don't check? FTR, it's not just about sending
> garbage, it's also about requests accidentally being truncated or just
> generally garbled.
>
> json.NewDecoder(r.Body).Decode() will return an error if the request
> is
On Tue, Dec 29, 2020 at 9:50 PM Axel Wagner
wrote:
>
> There is an important semantic difference between the two, which means you
> almost never want to use a `Decoder`: `Unmarshal` is for parsing a single
> json document, whereas a `Decoder` is for parsing a stream of concatenated
>
On Tue, Dec 29, 2020 at 6:07 PM Amnon wrote:
> *How do you know, if you don't check? FTR, it's not just about sending
> garbage, it's also about requests accidentally being truncated or just
> generally garbled.*
>
> json.NewDecoder(r.Body).Decode() will return an error if the
> request is
*How do you know, if you don't check? FTR, it's not just about sending
garbage, it's also about requests accidentally being truncated or just
generally garbled.*
json.NewDecoder(r.Body).Decode() will return an error if the
request is garbled or truncated.
The other nice thing about this code
On Tue, Dec 29, 2020 at 5:17 PM Amnon wrote:
> I always use `json.NewDecoder(r.Body).Decode()`
>
You shouldn't.
The code is more succinct than reading the entire body into a buffer, and
> then unmarshalling it. And there is only one error to check.
>
There is only one error to check, because
I always use `json.NewDecoder(r.Body).Decode()`
The code is more succinct than reading the entire body into a buffer, and
then unmarshalling it.
And there is only one error to check.
If I was super concerned about people sending trailing gibberish to my
server, I could call `dec.Buffered()` to
There is an important semantic difference between the two, which means you
almost never want to use a `Decoder`: `Unmarshal` is for parsing a single
json document, whereas a `Decoder` is for parsing a stream of concatenated
documents, like so: https://play.golang.org/p/4uiNyJlNIKh. In particular,
On Tue, Dec 29, 2020 at 11:35 AM burak serdar wrote:
>
> On Mon, Dec 28, 2020 at 5:22 PM Amit Saha wrote:
> >
> > Hi all, let's say I am a single large JSON object that I want to
> > process in my HTTP server backend.
> >
> > I am trying to get my head around if there is any performance
> >
On Mon, Dec 28, 2020 at 5:22 PM Amit Saha wrote:
>
> Hi all, let's say I am a single large JSON object that I want to
> process in my HTTP server backend.
>
> I am trying to get my head around if there is any performance
> advantage - memory or CPU to use the json.NewDecoder()/Decode()
>
Hi all, let's say I am a single large JSON object that I want to
process in my HTTP server backend.
I am trying to get my head around if there is any performance
advantage - memory or CPU to use the json.NewDecoder()/Decode()
mechanism versus the Unmarshal() function?
Thanks,
Amit
--
You
10 matches
Mail list logo