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

How about exposing byteSize function #2314

Closed
k8scat opened this issue Aug 11, 2022 · 0 comments
Closed

How about exposing byteSize function #2314

k8scat opened this issue Aug 11, 2022 · 0 comments

Comments

@k8scat
Copy link
Contributor

k8scat commented Aug 11, 2022

I want to use byteSize to compute the size of a message and decide whether to send it,because I meet an error while sending a big message

func (m *ProducerMessage) byteSize(version int) int {
	var size int
	if version >= 2 {
		size = maximumRecordOverhead
		for _, h := range m.Headers {
			size += len(h.Key) + len(h.Value) + 2*binary.MaxVarintLen32
		}
	} else {
		size = producerMessageOverhead
	}
	if m.Key != nil {
		size += m.Key.Length()
	}
	if m.Value != nil {
		size += m.Value.Length()
	}
	return size
}
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

1 participant