本文整理汇总了C++中buf_t类的典型用法代码示例。如果您正苦于以下问题:C++ buf_t类的具体用法?C++ buf_t怎么用?C++ buf_t使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了buf_t类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: NET_SendPacket
void NET_SendPacket (buf_t &buf, netadr_t &to)
{
int ret;
struct sockaddr_in addr;
NetadrToSockadr (&to, &addr);
ret = sendto (net_socket, (const char *)buf.ptr(), buf.size(), 0, (struct sockaddr *)&addr, sizeof(addr));
buf.clear();
if (ret == -1)
{
#ifdef _WIN32
int err = WSAGetLastError();
// wouldblock is silent
if (err == WSAEWOULDBLOCK)
return;
#else
if (errno == EWOULDBLOCK)
return;
if (errno == ECONNREFUSED)
return;
Printf (PRINT_HIGH, "NET_SendPacket: %s\n", strerror(errno));
#endif
}
}
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:28,代码来源:i_net.cpp
示例2: append_from_buf
bool buf_t::append_from_buf(
const buf_t &other,
int start,
int len
)
{
// find how much data is available in other buf from start point.
int actual_len = other.get_data_length() - start;
if( actual_len < 0 )
{
// there is no data to copy - just return success.
return true;
}
int copy_len = actual_len;
// if he wants to copy a maximum number of bytes get the minimum of
// actual length and len.
if( len!=-1 )
{
if( len<actual_len )
copy_len = len;
}
// ok, it is safe now, append it
return append_from_data( other.get_data() + start, copy_len );
}
开发者ID:jdkoftinoff,项目名称:if3-cpp,代码行数:31,代码来源:if3_buf.cpp
示例3: read
void read(void *data, size_t bytes)
{
if (pos==typename buf_t::const_iterator())
pos=buffer.begin();
if (buffer.end()-pos < bytes)
throw std::out_of_range("Premature end of buffer");
std::copy(pos, pos+bytes, static_cast<char*>(data));
pos += bytes;
}
开发者ID:Cyberax,项目名称:SofaDb,代码行数:11,代码来源:binary_stream.hpp
示例4: deserialize_as
obj deserialize_as(const buf_t& buffer, obj result = obj())
{
if (!buffer.empty())
make_deserializer(buffer)(result);
return result;
}
开发者ID:Nocte-,项目名称:hexahedra,代码行数:7,代码来源:serialize.hpp
示例5: merge_n_adaptive
I merge_n_adaptive(I f0, DifferenceType<I> n0,
I f1, DifferenceType<I> n1,
buf_t<I>& buf, Comp& comp, Proj& proj) {
if (n0 <= buf.size()) {
if (!n0 || !n1) {
return __stl2::next(f0, n0 + n1);
}
return fsort::merge_n_with_buffer(f0, n0, f1, n1, buf, comp, proj);
}
I f0_0, f0_1, f1_0, f1_1;
DifferenceType<I> n0_0, n0_1, n1_0, n1_1;
if (n0 < n1) {
fsort::merge_n_step_0(f0, n0, f1, n1, comp, proj,
f0_0, n0_0, f0_1, n0_1,
f1_0, n1_0, f1_1, n1_1);
} else {
fsort::merge_n_step_1(f0, n0, f1, n1, comp, proj,
f0_0, n0_0, f0_1, n0_1,
f1_0, n1_0, f1_1, n1_1);
}
fsort::merge_n_adaptive(f0_0, n0_0, f0_1, n0_1,
buf, comp, proj);
return fsort::merge_n_adaptive(f1_0, n1_0, f1_1, n1_1,
buf, comp, proj);
}
开发者ID:respu,项目名称:cmcstl2,代码行数:26,代码来源:forward_sort.hpp
示例6: forward
requires
models::Permutable<I>
ext::range<I>
forward(I first, difference_type_t<I> n,
buf_t<I>& buf, Pred& pred, Proj& proj)
{
// Precondition: !pred(proj(*first)))
STL2_ASSUME(n > 0);
auto middle = __stl2::next(first);
if (n == difference_type_t<I>(1)) {
return {__stl2::move(first), __stl2::move(middle)};
}
// n >= 2
if (n <= buf.size()) {
return stable_part::forward_buffer(
__stl2::move(first), __stl2::move(middle),
n, buf, pred, proj);
}
const auto half_n = n / 2;
auto res1 = stable_part::forward(__stl2::move(first), half_n, buf, pred, proj);
auto res2 = stable_part::forward_reduce(res1.end(), n - half_n, buf, pred, proj);
auto pp = __stl2::rotate(__stl2::move(res1.begin()),
__stl2::move(res1.end()),
__stl2::move(res2.begin())).begin();
return {__stl2::move(pp), __stl2::move(res2.end())};
}
开发者ID:mkurdej,项目名称:cmcstl2,代码行数:29,代码来源:stable_partition.hpp
示例7: bidirectional
requires
models::Permutable<I>
I bidirectional(I first, I last, difference_type_t<I> n,
buf_t<I>& buf, Pred& pred, Proj& proj)
{
// Precondition: !pred(proj(*first))
// Precondition: pred(proj(*last))
// Precondition: n == distance(first, last)
STL2_ASSUME(n >= difference_type_t<I>(1));
if (n == difference_type_t<I>(1)) {
__stl2::iter_swap(first, last);
return last;
}
// n >= 2
if (n <= buf.size()) {
return stable_part::bidirectional_buffer(
__stl2::move(first), __stl2::move(last),
n, buf, pred, proj);
}
const auto half_n = n / 2;
auto middle = __stl2::next(first, half_n);
auto pp1 = stable_part::bidirectional_reduce_back(
__stl2::move(first), middle, half_n, buf, pred, proj);
auto pp2 = stable_part::bidirectional_reduce_front(
middle, __stl2::move(last), n - half_n, buf, pred, proj);
return __stl2::rotate(__stl2::move(pp1), __stl2::move(middle),
__stl2::move(pp2)).begin();
}
开发者ID:mkurdej,项目名称:cmcstl2,代码行数:31,代码来源:stable_partition.hpp
示例8: bidirectional_buffer
requires
models::Permutable<I>
I bidirectional_buffer(I first, I last, difference_type_t<I> n,
buf_t<I>& buf, Pred& pred, Proj& proj)
{
// Precondition: !pred(proj(*first))
// Precondition: pred(proj(*last))
// Precondition: n == distance(first, last)
STL2_ASSUME(n >= 2);
STL2_ASSUME(n <= buf.size());
// Move the false values into the temporary buffer
// and the true values to the front of the sequence.
auto&& vec = detail::make_temporary_vector(buf);
vec.push_back(__stl2::iter_move(first));
auto middle = __stl2::next(first);
middle = __stl2::partition_move(__stl2::move(middle), last,
__stl2::move(first),
__stl2::back_inserter(vec),
__stl2::ref(pred),
__stl2::ref(proj)).out1();
*middle = __stl2::iter_move(last);
++middle;
__stl2::move(vec, middle);
return middle;
}
开发者ID:mkurdej,项目名称:cmcstl2,代码行数:26,代码来源:stable_partition.hpp
示例9: stable_sort_adaptive
void stable_sort_adaptive(I first, I last, buf_t<I>& buf, C &comp, P &proj) {
auto len = DifferenceType<I>((last - first + 1) / 2);
auto middle = first + len;
if (len > buf.size()) {
ssort::stable_sort_adaptive(first, middle, buf, comp, proj);
ssort::stable_sort_adaptive(middle, last, buf, comp, proj);
} else {
ssort::merge_sort_with_buffer(first, middle, buf, comp, proj);
ssort::merge_sort_with_buffer(middle, last, buf, comp, proj);
}
detail::merge_adaptive(first, middle, last,
middle - first, last - middle, buf,
__stl2::ref(comp), __stl2::ref(proj));
}
开发者ID:respu,项目名称:cmcstl2,代码行数:14,代码来源:stable_sort.hpp
示例10: entry
TarHeader::EntryType UnTar::entry(buf_t& buf, int accepted_types, bool skip_apple_resource_forks)
{
do {
m_header.reset();
read(*m_header, TarHeader::HeaderLen);
m_header.analyze();
// this is the only valid exit condition from reading a tar archive - end header reached
if (m_header.is_end()) return TarHeader::Unknown;
if (m_header.type() == TarHeader::File) {
// make sure we reserve space for at least one more character than the file size
// (to cheaply add a 0 byte if the user wants to)
buf.reserve(m_header.filesize() + 1);
// resize the buffer to be able to read the file size
buf.resize(m_header.filesize());
// read the file into the buffer
read(&buf[0], m_header.filesize());
// check if we have to skip some padding bytes (tar files have a block size of 512)
size_t padding = (TarHeader::HeaderLen - (m_header.filesize() % TarHeader::HeaderLen)) % TarHeader::HeaderLen;
if (padding) {
// this invalidates the (raw) header, but it is a handy buffer to read up to 512 bytes into here
read(*m_header, padding);
}
}
} while ((m_header.type() & accepted_types) == 0 || (skip_apple_resource_forks && CDDB::begins_with(m_header.filename(), ("./._"))));
return m_header.type();
}
开发者ID:JoachimSchurig,项目名称:CppCDDB,代码行数:37,代码来源:untar.cpp
示例11: merge_n_with_buffer
inline I merge_n_with_buffer(I f0, DifferenceType<I> n0,
I f1, DifferenceType<I> n1,
buf_t<I>& buf, Comp& comp, Proj& proj) {
STL2_ASSUME(n0 <= buf.size());
auto&& vec = make_temporary_vector(buf);
__stl2::move(__stl2::make_counted_iterator(f0, n0),
__stl2::default_sentinel{},
__stl2::back_inserter(vec));
return __stl2::merge_move(
vec.begin(), vec.end(),
__stl2::make_counted_iterator(__stl2::move(f1), n1),
__stl2::default_sentinel{},
__stl2::move(f0), __stl2::ref(comp),
__stl2::ref(proj), __stl2::ref(proj)).out();
}
开发者ID:respu,项目名称:cmcstl2,代码行数:15,代码来源:forward_sort.hpp
示例12: NET_SendPacket
void NET_SendPacket (buf_t &buf, netadr_t &to)
{
int ret;
struct sockaddr_in addr;
// [SL] 2011-07-06 - Don't try to send a packet if we're not really connected
// (eg, a netdemo is being played back)
if (simulated_connection)
{
buf.clear();
return;
}
NetadrToSockadr (&to, &addr);
ret = sendto (inet_socket, (const char *)buf.ptr(), buf.size(), 0, (struct sockaddr *)&addr, sizeof(addr));
buf.clear();
if (ret == -1)
{
#ifdef _WIN32
int err = WSAGetLastError();
// wouldblock is silent
if (err == WSAEWOULDBLOCK)
return;
#else
if (errno == EWOULDBLOCK)
return;
if (errno == ECONNREFUSED)
return;
Printf (PRINT_HIGH, "NET_SendPacket: %s\n", strerror(errno));
#endif
}
}
开发者ID:davidsgalbraith,项目名称:odamex,代码行数:36,代码来源:i_net.cpp
示例13: SV_CompressPacket
//
// SV_CompressPacket
//
// [Russell] - reason this was failing is because of huffman routines, so just
// use minilzo for now (cuts a packet size down by roughly 45%), huffman is the
// if 0'd sections
void SV_CompressPacket(buf_t &send, unsigned int reserved, client_t *cl)
{
if(plain.maxsize() < send.maxsize())
plain.resize(send.maxsize());
plain.setcursize(send.size());
memcpy(plain.ptr(), send.ptr(), send.size());
byte method = 0;
int need_gap = 2; // for svc_compressed and method, below
#if 0
if(MSG_CompressAdaptive(cl->compressor.get_codec(), send, reserved, need_gap))
{
reserved += need_gap;
need_gap = 0;
method |= adaptive_mask;
if(cl->compressor.get_codec_id())
method |= adaptive_select_mask;
}
#endif
DPrintf("SV_CompressPacket stage 2: %x %d\n", (int)method, (int)send.size());
if(MSG_CompressMinilzo(send, reserved, need_gap))
method |= minilzo_mask;
if((method & adaptive_mask) || (method & minilzo_mask))
{
#if 0
if(cl->compressor.packet_sent(cl->sequence - 1, plain.ptr() + sizeof(int), plain.size() - sizeof(int)))
method |= adaptive_record_mask;
#endif
send.ptr()[sizeof(int)] = svc_compressed;
send.ptr()[sizeof(int) + 1] = method;
}
DPrintf("SV_CompressPacket %x %d\n", (int)method, (int)send.size());
}
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:47,代码来源:sv_rproto.cpp
示例14: MSG_CompressAdaptive
//
// MSG_CompressAdaptive
//
bool MSG_CompressAdaptive (huffman &huff, buf_t &buf, size_t start_offset, size_t write_gap)
{
size_t outlen = OUT_LEN(buf.maxsize() - start_offset - write_gap);
size_t total_len = outlen + start_offset + write_gap;
if(compressed.maxsize() < total_len)
compressed.resize(total_len);
bool r = huff.compress (buf.ptr() + start_offset,
buf.size() - start_offset,
compressed.ptr() + start_offset + write_gap,
outlen);
// worth the effort?
if(!r || outlen >= (buf.size() - start_offset - write_gap))
return false;
memcpy(compressed.ptr(), buf.ptr(), start_offset);
SZ_Clear(&buf);
MSG_WriteChunk(&buf, compressed.ptr(), outlen + start_offset + write_gap);
return true;
}
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:27,代码来源:i_net.cpp
示例15: forward_buffer
requires
models::Permutable<I>
ext::range<I>
forward_buffer(I first, I next, difference_type_t<I> n,
buf_t<I>& buf, Pred& pred, Proj& proj)
{
// Precondition: !pred(proj(*first)))
// Precondition: __stl2::next(first) == next
STL2_ASSUME(n >= 2);
STL2_ASSUME(n <= buf.size());
auto&& vec = detail::make_temporary_vector(buf);
vec.push_back(__stl2::iter_move(first));
auto counted = __stl2::make_counted_iterator(
ext::uncounted(next), n - 1);
auto pp = __stl2::partition_move(
__stl2::move(counted), default_sentinel{},
__stl2::move(first), __stl2::back_inserter(vec),
__stl2::ref(pred), __stl2::ref(proj)).out1();
auto last = __stl2::move(vec, pp).out();
return {__stl2::move(pp), __stl2::move(last)};
}
开发者ID:mkurdej,项目名称:cmcstl2,代码行数:22,代码来源:stable_partition.hpp
示例16: MSG_CompressMinilzo
//
// MSG_CompressMinilzo
//
bool MSG_CompressMinilzo (buf_t &buf, size_t start_offset, size_t write_gap)
{
if(buf.size() < MINILZO_COMPRESS_MINPACKETSIZE)
return false;
lzo_uint outlen = OUT_LEN(buf.maxsize() - start_offset - write_gap);
size_t total_len = outlen + start_offset + write_gap;
if(compressed.maxsize() < total_len)
compressed.resize(total_len);
int r = lzo1x_1_compress (buf.ptr() + start_offset,
buf.size() - start_offset,
compressed.ptr() + start_offset + write_gap,
&outlen,
wrkmem);
// worth the effort?
if(r != LZO_E_OK || outlen >= (buf.size() - start_offset - write_gap))
return false;
memcpy(compressed.ptr(), buf.ptr(), start_offset);
SZ_Clear(&buf);
MSG_WriteChunk(&buf, compressed.ptr(), outlen + start_offset + write_gap);
return true;
}
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:31,代码来源:i_net.cpp
示例17: write_internal
void write_internal(VALUE self, VALUE handle, VALUE obj, VALUE type, buf_t& buf) {
Model& model = MODEL(handle);
Msg& msg = get_msg_for_type(model, type);
buf.reserve(MSG_INITIAL_CAPACITY);
msg.write(buf, msg, obj);
}
开发者ID:wintonpc,项目名称:pbr,代码行数:6,代码来源:pbr_ext.cpp
示例18: CopyString
void CopyString(buf_t &in, buf_t &out)
{
const char *p = in.ReadString();
if(p)
out.WriteString(p);
}
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:6,代码来源:protocol.cpp
示例19: Copy
void Copy(buf_t &in, buf_t &out, int len)
{
byte *p = in.ReadChunk(len);
if(p)
out.WriteChunk((const char *)p, len);
}
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:6,代码来源:protocol.cpp
示例20: Go
void Go(buf_t &in, buf_t &out)
{
while(in.BytesLeftToRead())
{
byte cmd = in.NextByte();
//std::cout << cmd << " " << (int)cmd << std::endl;
switch(cmd)
{
case svc_loadmap:
{
Copy(in, out, 1);
map = in.ReadString();
out.WriteString(map.c_str());
std::cout<< "map " << map << std::endl; // todo unsafe
}
break;
case svc_playerinfo:
Copy(in, out, 1+ 9 + 4*4 + 5);
break;
case svc_consoleplayer:
Copy(in, out, 1);
consoleplayer = in.ReadByte();
out.WriteByte(consoleplayer);
digest = in.ReadString();
out.WriteString(digest.c_str());
break;
case svc_updatefrags:
Copy(in, out, 1+ 7);
break;
case svc_moveplayer:
Copy(in, out, 1+ 37);
break;
case svc_updatelocalplayer:
//in.ReadChunk(28);
Copy(in, out, 1+ 28);
break;
case svc_userinfo:
Copy(in, out, 1+ 1);
CopyString(in, out);
Copy(in, out, 9);
CopyString(in, out);
Copy(in, out, 2);
break;
case svc_teampoints:
Copy(in, out, 1+ 3*2);
break;
case svc_svgametic:
Copy(in, out, 1+ 4);
break;
case svc_updateping:
Copy(in, out, 1+ 5);
break;
case svc_spawnmobj:
{
Copy(in, out, 1+ 16);
unsigned short type = in.ReadShort();
out.WriteShort(type); // todo: if this line is missing, odamex client crashes
Copy(in, out, 5);
if(type == 0x10000/*MF_MISSILE*/)
{
out.WriteShort(type);
Copy(in, out, 16); //SpeedAndAngle
}
}
break;
case svc_mobjspeedangle:
Copy(in, out, 1+ 18);
break;
case svc_mobjinfo:
Copy(in, out, 1+ 6);
break;
case svc_explodemissile:
Copy(in, out, 1+ 2);
break;
case svc_removemobj:
Copy(in, out, 1+ 2);
break;
case svc_killmobj:
Copy(in, out, 1+ 13);
break;
case svc_movemobj:
Copy(in, out, 1+ 15);
break;
case svc_damagemobj:
Copy(in, out, 1+ 5);
break;
case svc_corpse:
Copy(in, out, 1+ 4);
break;
case svc_spawnplayer:
{
Copy(in, out, 1);
byte player = in.ReadByte();
out.WriteByte(player);
unsigned short netid = in.ReadShort();
if(player == consoleplayer)
playermobj = netid;
out.WriteShort(netid);
spawnang = in.ReadLong();
out.WriteLong(spawnang);
//.........这里部分代码省略.........
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:101,代码来源:protocol.cpp
注:本文中的buf_t类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论