Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: hello_message_pack
include/msgpack/fbuffer.hpp
- Committer:
- hideakitai
- Date:
- 2016-02-22
- Revision:
- 4:bd0c06dd6e92
- Parent:
- 0:3f9dbf1e2cb0
File content as of revision 4:bd0c06dd6e92:
//
// MessagePack for C++ FILE* buffer adaptor
//
// Copyright (C) 2013 Vladimir Volodko
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_FBUFFER_HPP__
#define MSGPACK_FBUFFER_HPP__
#include "msgpack/versioning.hpp"
#include <cstdio>
#include <stdexcept>
namespace msgpack {
/// @cond
MSGPACK_API_VERSION_NAMESPACE(v1) {
/// @endcond
class fbuffer {
public:
explicit fbuffer(FILE* file) : m_file(file) { }
public:
void write(const char* buf, unsigned int len)
{
if (1 != fwrite(buf, len, 1, m_file)) {
throw std::runtime_error("fwrite() failed");
}
}
FILE* file() const
{
return m_file;
}
#if defined(MSGPACK_USE_CPP03)
private:
fbuffer(const fbuffer&);
fbuffer& operator=(const fbuffer&);
#else // defined(MSGPACK_USE_CPP03)
fbuffer(const fbuffer&) = delete;
fbuffer& operator=(const fbuffer&) = delete;
#endif // defined(MSGPACK_USE_CPP03)
private:
FILE* m_file;
};
/// @cond
} // MSGPACK_API_VERSION_NAMESPACE(v1)
/// @endcond
} // namespace msgpack
#endif /* msgpack/fbuffer.hpp */