public static ByteBuf getByteBufFromReadableBuffer ( ReadableBuffer buffer ) { if ( ! sZeroCopyReceiveSupported ) { return null ; } try { if ( buffer instanceof CompositeReadableBuffer ) { Queue < ReadableBuffer > buffers = ( Queue < ReadableBuffer > ) sCompositeBuffers . get ( buffer ) ; if ( buffers . size ( ) == 1 ) { return getByteBufFromReadableBuffer ( buffers . peek ( ) ) ; } else { CompositeByteBuf buf = PooledByteBufAllocator . DEFAULT . compositeBuffer ( ) ; for ( ReadableBuffer readableBuffer : buffers ) { ByteBuf subBuffer = getByteBufFromReadableBuffer ( readableBuffer ) ; if ( subBuffer == null ) { return null ; } buf . addComponent ( true , subBuffer ) ; } return buf ; } } else if ( buffer . getClass ( ) . equals ( sReadableByteBuf . getDeclaringClass ( ) ) ) { return ( ByteBuf ) sReadableByteBuf . get ( buffer ) ; } } catch ( Exception e ) { LOG . warn ( "Failed to get data buffer from stream: {}." , e . getMessage ( ) ) ; return null ; } return null ; }
Gets a Netty buffer directly from a gRPC ReadableBuffer .