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

Export EncodeBytesLen() in the encoder #119

Closed
xichen2020 opened this issue Dec 30, 2016 · 3 comments
Closed

Export EncodeBytesLen() in the encoder #119

xichen2020 opened this issue Dec 30, 2016 · 3 comments

Comments

@xichen2020
Copy link
Contributor

Is it possible to export EncodeBytesLen() in the encoder APIs? My use case is that I need to encode a large number of items, each of which contains an ID, which in turn contains a prefix, a body, and a suffix, all of which are byte slices, e.g.,

type ID struct {
  Prefix []byte
  Body []byte
  Suffix []byte
}

What I'd like to achieve is to encode the ID object as if it were a single []byte so that I can avoid unnecessary byte copies during decoding. With the existing API, I'd have to concatenate the prefix/body/suffix and create a new byte slice to use the EncodeBytes method. However if we export EncodeBytesLen(), I can call EncodeBytesLen() to encode the number of bytes first, then write the raw bytes.

If that sounds reasonable, I'd be happy to put up a PR.

@vmihailenco
Copy link
Owner

Bytes is a slice (array) so you use EncodeArrayLen.

@vmihailenco
Copy link
Owner

Hm, no - I am wrong. Please send a PR.

@xichen2020
Copy link
Contributor Author

Here it is: #120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants