pub struct Producer { /* private fields */ }Expand description
High-level NDN producer — serves Data in response to Interests.
Implementations§
Source§impl Producer
impl Producer
Sourcepub async fn connect(
socket: impl AsRef<Path>,
prefix: impl Into<Name>,
) -> Result<Self, AppError>
pub async fn connect( socket: impl AsRef<Path>, prefix: impl Into<Name>, ) -> Result<Self, AppError>
Connect to an external router and register a prefix.
Sourcepub fn from_handle(handle: InProcHandle, prefix: Name) -> Self
pub fn from_handle(handle: InProcHandle, prefix: Name) -> Self
Create from an in-process InProcHandle (embedded engine).
Sourcepub async fn serve<F, Fut>(&self, handler: F) -> Result<(), AppError>
pub async fn serve<F, Fut>(&self, handler: F) -> Result<(), AppError>
Run the producer loop with an async handler.
The handler receives each (Interest, Responder) pair and must call
one of Responder::respond, Responder::respond_bytes, or
Responder::nack to reply. Dropping the Responder without replying
silently discards the Interest.
§Example
use ndn_packet::encode::DataBuilder;
producer.serve(|interest, responder| async move {
let data = DataBuilder::new((*interest.name).clone(), b"42").build();
responder.respond_bytes(data).await.ok();
}).awaitSourcepub async fn publish_large(
&self,
prefix: &Name,
content: Bytes,
chunk_size: usize,
) -> Result<(), AppError>
pub async fn publish_large( &self, prefix: &Name, content: Bytes, chunk_size: usize, ) -> Result<(), AppError>
Publish a large payload as a segmented NDN object.
Splits content into chunks of at most chunk_size bytes (default:
NDN_DEFAULT_SEGMENT_SIZE = 8 KiB), then serves each chunk as a
separate Data packet at /<prefix>/<n> where n is the ASCII-decimal
segment index. The last segment carries the FinalBlockId field so
consumers can determine when reassembly is complete.
Use Consumer::fetch_segmented on
the receiving side to fetch and reassemble the payload.
§Note
This method serves one round of Interests — enough for one consumer to
fetch all segments sequentially. For persistent serving (multiple
consumers), embed the ChunkedProducer in a custom serve loop.