Package dev.relism.flash.bytes
Interface ArrayBackedByteView
- All Superinterfaces:
dev.relism.fpr.core.ByteView
- All Known Implementing Classes:
FastPathViews.RequestByteView,FastPathViews.SocketByteView,FastPathViews.StringByteView,PooledSlice
public interface ArrayBackedByteView
extends dev.relism.fpr.core.ByteView
Capability interface for a
ByteView that is a contiguous slice of a single backing
byte[] — as opposed to a SegmentedByteView, which spans several arrays and
cannot expose a single (array, offset) pair.
Every array-backed view in this codebase implements this: RequestByteView,
SocketByteView, StringByteView (all in
dev.relism.flash.routing.routers.fastpathrouter.FastPathViews), and PooledSlice.
MethodPathByteView deliberately does not — it is a composite of a byte[]
(method) and another ByteView (path), so it has no single backing array.
What this enables
Anywhere code holds a plainByteView and wants the fast path when the concrete
instance happens to be array-backed, an instanceof ArrayBackedByteView check unlocks:
- Single-allocation
Stringconstruction —new String(view.array(), view.offset(), view.length(), UTF_8)instead of a byte-at-a-time copy into a scratchbyte[]followed by a second allocation for - A single
System.arraycopyinstead of a manual loop wherever a view's bytes need to be copied.
ByteView (e.g. because it received one across the
SegmentedByteView boundary) keeps the
byte-at-a-time fallback — this interface is an opportunistic fast path, never a requirement.-
Method Summary
Methods inherited from interface dev.relism.fpr.core.ByteView
byteAt, length, longAt, supportsLong
-
Method Details
-
array
byte[] array()The backing array. Bytes[offset(), offset() + length())belong to this view. -
offset
int offset()Offset of this view's first byte withinarray().
-