offset is a Rust pointer operation that returns a pointer displaced by a specified number of elements from a base pointer. It is useful when a foreign API needs the end of an allocated buffer. section 4.6
Use offset when you need to:
- Move from a base pointer by N elements in a contiguous block. section 4.7
- Compute the end of a copied response buffer by adding its byte length to the buffer pointer. section 4.6
- Distinguish forward pointer calculation with offset from measuring the difference between two pointers with offset_from. section 4.6
Finding a response buffer's end
After copying response bytes into response_buffer, assign buf.pos to the buffer start and buf.last to response_buffer.offset(response_bytes.len() as isize), cast to a byte pointer. The resulting range can be placed in an NGINX output chain. section 4.6
buf.pos = response_buffer as *mut u8;
buf.last = response_buffer.offset(
response_bytes.len() as isize) as *mut u8;
let mut out_chain = ngx_chain_t {
buf,
next: std::ptr::null_mut(),
};
Inspect the pointer calculation beside the buffer fields and output-chain initialization. section 4.6
