Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
iobuffer.hpp
Go to the documentation of this file.
1#pragma once
2#include <fc/io/iostream.hpp>
4
5namespace fc
6{
10 class size_stream : public virtual fc::ostream
11 {
12 public:
13 size_stream( size_t s = 0):_size(s){}
14
15 size_t size()const { return _size; }
16 size_t seek( size_t pos ) { return _size = pos; }
17
18 virtual size_t writesome( const char* /*ignored buf*/, size_t len )
19 {
20 _size += len;
21 return len;
22 }
23
24 virtual void close(){}
25 virtual void flush(){}
26
27 private:
28 size_t _size;
29 };
30
31
32 class iobuffer : public virtual fc::iostream
33 {
34 public:
35 iobuffer( size_t s )
36 :_data(s){}
37
38 size_t size()const { return _data.size(); }
39 size_t pos()const { return _pos; }
40 size_t seek( size_t pos )
41 {
42 return _pos = std::min<size_t>(_data.size(),pos);
43 }
44
45 virtual size_t readsome( char* buf, size_t len )
46 {
47 auto avail = std::min<size_t>( _data.size()-_pos, len );
48 if( avail == 0 ) throw fc::eof_exception();
49 memcpy( buf, _data.data()+_pos, avail );
50 _pos += avail;
51 return avail;
52 }
57 char peek()const
58 {
59 if( _pos == _data.size() ) throw fc::eof_exception();
60 return _data[_pos];
61 }
62
63 virtual size_t writesome( const char* buf, size_t len )
64 {
65 auto avail = std::max<size_t>( _data.size(), _pos + len );
66 _data.resize(avail);
67 memcpy( _data.data()+_pos, buf, len );
68 _pos += avail;
69 return avail;
70 }
71 char* data() { return _data.data(); }
72
73 virtual void close(){}
74 virtual void flush(){}
75
76 private:
77 std::vector<char> _data;
78 size_t _pos;
79 };
80
81}
virtual size_t writesome(const char *buf, size_t len)
Definition iobuffer.hpp:63
char peek() const
Definition iobuffer.hpp:57
size_t size() const
Definition iobuffer.hpp:38
char * data()
Definition iobuffer.hpp:71
virtual size_t readsome(char *buf, size_t len)
Definition iobuffer.hpp:45
size_t seek(size_t pos)
Definition iobuffer.hpp:40
virtual void flush()
Definition iobuffer.hpp:74
virtual void close()
Definition iobuffer.hpp:73
iobuffer(size_t s)
Definition iobuffer.hpp:35
size_t pos() const
Definition iobuffer.hpp:39
virtual void close()
Definition iobuffer.hpp:24
size_t size() const
Definition iobuffer.hpp:15
virtual size_t writesome(const char *, size_t len)
Definition iobuffer.hpp:18
size_stream(size_t s=0)
Definition iobuffer.hpp:13
size_t seek(size_t pos)
Definition iobuffer.hpp:16
virtual void flush()
Definition iobuffer.hpp:25
Defines exception's used by fc.
namespace sysio::chain
Definition authority.cpp:3
char * s
size_t len
uint8_t buf[2048]
memcpy((char *) pInfo->slotDescription, s, l)