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: add Decorder.Buffer(buf []byte) function? #30864

mei-rune opened this issue Mar 15, 2019 · 1 comment

encoding/json: add Decorder.Buffer(buf []byte) function? #30864

mei-rune opened this issue Mar 15, 2019 · 1 comment


Copy link

to fix #7709 and #7067, #9706

add Decorder.Buffer([]byte) function, it like bufio.Buffer(buf []byte, max int)

  1. set buf size and reduce memory alloc
  2. zero copy is possible and as follow:
type InplaceReader int
func (p *InplaceReader) Read([]byte) (int, error) {
	if *p == 0 {
		return 0, io.EOF
	ret := int(*p)
	*p = 0
	return ret, io.EOF


        n, remoteAddr, err := socket.ReadFromUDP(bs)
        if err != nil {
           return err
	r := InplaceReader(len(bs))
	decoder := json.NewDecoder(&r)
        decoder.UseNumber()   // json.Unmarshal() is unsupport UseNumber
Copy link

It looks like all of those issues were closed as Working As Intended. It is preferable to keep all of the context for an issue and a proposed fix within the context of a single issue, rather than creating a new one.

@golang golang locked and limited conversation to collaborators Mar 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

3 participants