dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Pcapng::FileSink Class Reference

PCAPNG sink that writes capture bytes to a file. More...

#include <dfx-pcapng/sinks/FileSink.hpp>

Inheritance diagram for dfx::Pcapng::FileSink:
[legend]
Collaboration diagram for dfx::Pcapng::FileSink:
[legend]

Public Member Functions

 FileSink (fs::path const &path, bool truncate=true)
 Create a file sink targeting path.
void init (std::vector< uint8_t > initialHeader) override
 Initialize the sink by writing the initial PCAPNG header.
void write (std::vector< uint8_t > data) override
 Append serialized PCAPNG bytes to the output file.
Public Member Functions inherited from dfx::Pcapng::Sink
 Sink () noexcept=default
 Construct a sink.
 DISABLE_COPY_AND_MOVE (Sink)
 Sinks are not copyable and not movable.
virtual ~Sink ()=default
 Virtual destructor for polymorphic use.
void setPoller (FdWatch::Poller *poller)
 Provide a poller that the sink may use for event-driven I/O.

Additional Inherited Members

Protected Attributes inherited from dfx::Pcapng::Sink
FdWatch::Poller_poller = nullptr
 Borrowed poller pointer for event-driven sink implementations.

Detailed Description

PCAPNG sink that writes capture bytes to a file.

FileSink is a concrete Sink implementation that persists a PCAPNG capture stream to a filesystem path using a binary std::ofstream.

A more optimal solution than std::ofstream may be implemented in a future revision.

Key behaviors:

  • If the target path has a parent directory, it is created with fs::create_directories() before opening the file.
  • The file is opened in binary mode.
  • The stream is configured to throw on failbit and badbit, so write failures surface as exceptions rather than silent partial output.

This sink does not rely on FdWatch::Poller; it performs synchronous writes from the capture worker thread.

Note
Construction fails (throws) if the file cannot be opened.

Constructor & Destructor Documentation

◆ FileSink()

dfx::Pcapng::FileSink::FileSink ( fs::path const & path,
bool truncate = true )

Create a file sink targeting path.

  • Creates parent directories if needed.
  • Opens the file in binary mode.
  • Enables stream exceptions for failbit and badbit.
Parameters
pathOutput file path.
truncateIf true, truncate/overwrite the file. If false, append.
Exceptions
dfx::Utils::ExceptionThrown if parent directory creation fails or if the file cannot be opened.

Member Function Documentation

◆ init()

void dfx::Pcapng::FileSink::init ( std::vector< uint8_t > initialHeader)
overridevirtual

Initialize the sink by writing the initial PCAPNG header.

FileSink implements initialization by immediately writing initialHeader to the output stream.

Parameters
initialHeaderSerialized PCAPNG header bytes to write first.

Implements dfx::Pcapng::Sink.

◆ write()

void dfx::Pcapng::FileSink::write ( std::vector< uint8_t > data)
overridevirtual

Append serialized PCAPNG bytes to the output file.

Writes data to the underlying file stream as raw bytes.

Parameters
dataBytes to write.

Implements dfx::Pcapng::Sink.


The documentation for this class was generated from the following file: