MessagePack for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
msgpack
v1
fbuffer.hpp
Go to the documentation of this file.
1
//
2
// MessagePack for C++ FILE* buffer adaptor
3
//
4
// Copyright (C) 2013 Vladimir Volodko
5
//
6
// Distributed under the Boost Software License, Version 1.0.
7
// (See accompanying file LICENSE_1_0.txt or copy at
8
// http://www.boost.org/LICENSE_1_0.txt)
9
//
10
#ifndef MSGPACK_V1_FBUFFER_HPP
11
#define MSGPACK_V1_FBUFFER_HPP
12
13
#include "
msgpack/v1/fbuffer_decl.hpp
"
14
#include "
msgpack/assert.hpp
"
15
16
#include <cstdio>
17
#include <stdexcept>
18
19
namespace
msgpack
{
20
22
MSGPACK_API_VERSION_NAMESPACE
(v1) {
24
25
class
fbuffer
{
26
public
:
27
explicit
fbuffer
(FILE*
file
) : m_file(
file
) { }
28
29
public
:
30
void
write
(
const
char
* buf,
unsigned
int
len)
31
{
32
MSGPACK_ASSERT
(buf || len == 0);
33
if
(!buf)
return
;
34
if
(len == 0)
return
;
35
if
(1 != fwrite(buf, len, 1, m_file)) {
36
throw
std::runtime_error(
"fwrite() failed"
);
37
}
38
}
39
40
FILE*
file
()
const
41
{
42
return
m_file;
43
}
44
45
#if defined(MSGPACK_USE_CPP03)
46
private
:
47
fbuffer
(
const
fbuffer
&);
48
fbuffer
&
operator=
(
const
fbuffer
&);
49
#else
// defined(MSGPACK_USE_CPP03)
50
fbuffer
(
const
fbuffer
&) =
delete
;
51
fbuffer
&
operator=
(
const
fbuffer
&) =
delete
;
52
#endif
// defined(MSGPACK_USE_CPP03)
53
54
private
:
55
FILE* m_file;
56
};
57
59
}
// MSGPACK_API_VERSION_NAMESPACE(v1)
61
62
}
// namespace msgpack
63
64
#endif
// MSGPACK_V1_FBUFFER_HPP
assert.hpp
MSGPACK_ASSERT
#define MSGPACK_ASSERT
Definition
assert.hpp:22
msgpack::fbuffer
Definition
fbuffer.hpp:25
msgpack::fbuffer::file
FILE * file() const
Definition
fbuffer.hpp:40
msgpack::fbuffer::operator=
fbuffer & operator=(const fbuffer &)=delete
msgpack::fbuffer::fbuffer
fbuffer(FILE *file)
Definition
fbuffer.hpp:27
msgpack::fbuffer::write
void write(const char *buf, unsigned int len)
Definition
fbuffer.hpp:30
msgpack::fbuffer::fbuffer
fbuffer(const fbuffer &)=delete
msgpack
Definition
adaptor_base.hpp:15
fbuffer_decl.hpp
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition
versioning.hpp:66
Generated by
1.17.0