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

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

Comments

Projects
None yet
2 participants
@runner-mei
Copy link

commented Mar 15, 2019

to fix #7709 and #7067, #9706

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

  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
	decoder.Buffer(bs)
        decoder.Decode(&x)
@katiehockman

This comment has been minimized.

Copy link
Contributor

commented Mar 19, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.