Skip to content

mem: add Buffer.Slice()#8977

Open
ash2k wants to merge 2 commits intogrpc:masterfrom
ash2k:ash2k/slice
Open

mem: add Buffer.Slice()#8977
ash2k wants to merge 2 commits intogrpc:masterfrom
ash2k:ash2k/slice

Conversation

@ash2k
Copy link
Contributor

@ash2k ash2k commented Mar 17, 2026

I have a CodecV2 that gives me a mem.BufferSlice (i.e. exposes what it gets from gRPC directly). I need to get another mem.BufferSlice from it that is a subslice. In some scenarios I need to slice the first and/or the last buffer to get only the subset of data. Hence, having a Slice() method on the Buffer type would be really useful.

Another use case: I want to use BufferSlice.Reader and implement a Peek()(or similar) to get a BufferSlice of the next N bytes. I don't want a []byte or [][]byte, I'd like to return this BufferSlice from a codecv2 and let gRPC free the buffers when it no longer needs them (i.e. I don't want to wrap those individual []byte into BufferSlices).

RELEASE NOTES:

  • Add mem.Buffer.Slice() - new method to slice the buffer like a slice.

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.10%. Comparing base (e5563c6) to head (a405abf).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8977      +/-   ##
==========================================
+ Coverage   82.93%   83.10%   +0.16%     
==========================================
  Files         411      411              
  Lines       32704    32719      +15     
==========================================
+ Hits        27124    27192      +68     
+ Misses       4179     4146      -33     
+ Partials     1401     1381      -20     
Files with missing lines Coverage Δ
mem/buffer_slice.go 96.45% <100.00%> (ø)
mem/buffers.go 89.81% <100.00%> (+1.64%) ⬆️

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Works just like Go's slice slicing.
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