Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: can add UnmarshalWithUseNumber function #7067

Closed
gopherbot opened this issue Jan 6, 2014 · 5 comments
Closed

encoding/json: can add UnmarshalWithUseNumber function #7067

gopherbot opened this issue Jan 6, 2014 · 5 comments

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 6, 2014

by runner.mei:

func UnmarshalWithUseNumber(data []byte, v interface{}) error {
            // Check for well-formedness.
            // Avoids filling out half a data structure
            // before discovering a JSON syntax error.
            var d decodeState
========================= add next line ===============
                d.useNumber = true
            err := checkValid(data, &d.scan)
            if err != nil {
                return err
            }
        
            d.init(data)
            return d.unmarshal(v)
        }
@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Jan 6, 2014

Comment 1:

Rather than provide a patch, please describe (or given a link to a play.golang.org
program) that is broken.
@gopherbot

This comment has been minimized.

Copy link
Author

@gopherbot gopherbot commented Jan 7, 2014

Comment 2 by runner.mei:

can add UnmarshalWithUseNumber function, like this:
http://play.golang.org/p/GvJ71Ybgwv
@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Jan 7, 2014

Comment 3:

We can't provide a function for every combination of options.  I think using Decoder
here is fine.

Status changed to WorkingAsIntended.

@gopherbot

This comment has been minimized.

Copy link
Author

@gopherbot gopherbot commented Jan 10, 2014

Comment 4 by runner.mei:

If you use the decoder, then data will be copied to Decoder.buf field, will increase an
unnecessary copy.
  dec := json.NewDecoder(strings.NewReader(data))
  dec.UseNumber()
  dec.Decode(&m) // data will copy to dec.buf, it is unnecessary.
 
data length is 2m in my program.
@gopherbot

This comment has been minimized.

Copy link
Author

@gopherbot gopherbot commented Apr 2, 2014

Comment 5 by runner.mei:

also add json.NewDecoderWithBytes function.
  data, _ := ioutil.ReadAll(reader)
  dec := json.NewDecoderWithBytes(data)
  dec.UseNumber()
  dec.Decode(&m)
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.