4 #include <dballe/fwd.h> 22 virtual std::string
pathname()
const = 0;
25 virtual Encoding
encoding()
const = 0;
30 virtual void close() = 0;
51 virtual bool foreach(std::function<
bool(
const BinaryMessage&)> dest) = 0;
54 virtual void write(
const std::string& msg) = 0;
66 static std::unique_ptr<File>
create(
const std::string&
pathname,
const char* mode);
80 static std::unique_ptr<File>
create(Encoding type,
const std::string& pathname,
const char* mode);
97 static std::unique_ptr<File>
create(FILE* file,
bool close_on_exit,
const std::string& name=
"(fp)");
115 static std::unique_ptr<File>
create(Encoding type, FILE* file,
bool close_on_exit,
const std::string& name=
"(fp)");
145 off_t offset = (off_t)-1;
148 int index = MISSING_INT;
151 : encoding(encoding) {}
158 operator bool()
const;
163 std::ostream& operator<<(std::ostream&,
const dballe::Encoding&);
virtual BinaryMessage read()=0
Read a message from the file.
virtual void close()=0
Close the underlying file.
virtual Encoding encoding() const =0
Get the file encoding.
virtual void write(const std::string &msg)=0
Append the binary message to the file.
static Encoding parse_encoding(const char *s)
Return the Encoding corresponding to the given name.
static std::unique_ptr< File > create(const std::string &pathname, const char *mode)
Open a file from the filesystem, autodetecting the encoding type.
std::string data
Binary message data.
Definition: file.h:135
Binary message.
Definition: file.h:129
static const char * encoding_name(Encoding enc)
Return a string with the name of this encoding.
Encoding encoding
Format of the binary data.
Definition: file.h:132
std::string pathname
Pathname of the file from where the BinaryMessage has been read.
Definition: file.h:142
virtual std::string pathname() const =0
Get the file pathname.
File object for doing I/O on binary message streams.
Definition: file.h:17