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

feat: copy mode for decoder and Copy method for encoder #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Bai-Yingjie
Copy link

主要考虑是并发场景下使用encoder和decoder.

  • 目前decoder使用的[]byte数据均指向原input buffer, 如果这个buffer是个固定的收报buffer, 那么这个buffer改变, decoder引用的数据就会改变, decode的结果就会改变. copy mode就是把需要的[]byte部分从原buffer拷贝一份.

  • encoder的Copy方法是拷贝当前encoder, 但使用新的buffer. 这样一个encoder就可以在并发场景下copy后使用.

encoder.Copy() method returns a copy of the encoder to use separate
buf thus can be concurrent safe.

In the case when decoding a user supplied buf, making a copy of the
[]byte part in the buf allows user to modify the buf after decoding
is done, this is the copy mode.
@Bai-Yingjie
Copy link
Author

@niubaoshu

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

Successfully merging this pull request may close these issues.

1 participant