mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 10:19:51 +00:00
removed symbolic links
This commit is contained in:
parent
ca0b085d15
commit
cd10fbc1fe
31 changed files with 0 additions and 2 deletions
103
cpp/msgpack/sbuffer.hpp
Normal file
103
cpp/msgpack/sbuffer.hpp
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
//
|
||||
// MessagePack for C++ simple buffer implementation
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_SBUFFER_HPP__
|
||||
#define MSGPACK_SBUFFER_HPP__
|
||||
|
||||
#include "msgpack/sbuffer.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
||||
class sbuffer : public msgpack_sbuffer {
|
||||
public:
|
||||
sbuffer(size_t initsz = MSGPACK_SBUFFER_INIT_SIZE)
|
||||
{
|
||||
base::data = (char*)::malloc(initsz);
|
||||
if(!base::data) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
base::size = 0;
|
||||
base::alloc = initsz;
|
||||
}
|
||||
|
||||
~sbuffer()
|
||||
{
|
||||
::free(base::data);
|
||||
}
|
||||
|
||||
public:
|
||||
void write(const char* buf, unsigned int len)
|
||||
{
|
||||
if(base::alloc - base::size < len) {
|
||||
expand_buffer(len);
|
||||
}
|
||||
memcpy(base::data + base::size, buf, len);
|
||||
base::size += len;
|
||||
}
|
||||
|
||||
char* data()
|
||||
{
|
||||
return base::data;
|
||||
}
|
||||
|
||||
const char* data() const
|
||||
{
|
||||
return base::data;
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return base::size;
|
||||
}
|
||||
|
||||
char* release()
|
||||
{
|
||||
return msgpack_sbuffer_release(this);
|
||||
}
|
||||
|
||||
private:
|
||||
void expand_buffer(size_t len)
|
||||
{
|
||||
size_t nsize = (base::alloc) ?
|
||||
base::alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
|
||||
|
||||
while(nsize < base::size + len) { nsize *= 2; }
|
||||
|
||||
void* tmp = realloc(base::data, nsize);
|
||||
if(!tmp) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
base::data = (char*)tmp;
|
||||
base::alloc = nsize;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef msgpack_sbuffer base;
|
||||
|
||||
private:
|
||||
sbuffer(const sbuffer&);
|
||||
};
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/sbuffer.hpp */
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue