22#include < iostream>
33#include < limits.h>
44
5- ByteBuffer::ByteBuffer ( bufsize_t v_size, bufsize_t v_padding)
6- : ByteBuffer( )
5+
6+ void ByteBuffer::_init ( const bufsize_t & v_size, const bufsize_t & v_padding )
77{
88 if (v_size == 0 ) throw BufferException (" Zero size requested" );
99
@@ -15,17 +15,23 @@ ByteBuffer::ByteBuffer(bufsize_t v_size, bufsize_t v_padding)
1515 }
1616}
1717
18+ ByteBuffer::ByteBuffer (bufsize_t v_size, bufsize_t v_padding)
19+ : content(nullptr ), contentSize(0 ), padding(0 ), originalSize(0 )
20+ {
21+ _init (v_size, v_padding);
22+ }
23+
1824ByteBuffer::ByteBuffer (BYTE* v_content, bufsize_t v_size, bufsize_t v_padding)
19- : ByteBuffer(v_size, v_padding )
25+ : content( nullptr ), contentSize( 0 ), padding( 0 ), originalSize( 0 )
2026{
21- if (v_size == 0 ) throw BufferException ( " Zero size requested " );
27+ _init (v_size, v_padding );
2228 if (this ->content && v_content) {
2329 ::memcpy (this ->content, v_content, v_size);
2430 }
2531}
2632
2733ByteBuffer::ByteBuffer (AbstractByteBuffer *v_parent, offset_t v_offset, bufsize_t v_size, bufsize_t v_padding)
28- : ByteBuffer( )
34+ : content( nullptr ), contentSize( 0 ), padding( 0 ), originalSize( 0 )
2935{
3036 if (!v_parent) throw BufferException (" Cannot make subBuffer for NULL buffer!" );
3137 if (!v_size) throw BufferException (" Cannot make 0 size buffer!" );
@@ -38,12 +44,9 @@ ByteBuffer::ByteBuffer(AbstractByteBuffer *v_parent, offset_t v_offset, bufsize_
3844 BYTE *bContent = v_parent->getContentAt (v_offset, copySize);
3945 if (!bContent) throw BufferException (" Cannot make Buffer for NULL content!" );
4046
41- this ->content = allocContent (allocSize, v_padding);
42- if (this ->content ) {
43- this ->padding = v_padding;
44- this ->contentSize = allocSize;
45- this ->originalSize = this ->contentSize ;
46- ::memcpy (this ->content, bContent, copySize);
47+ _init (v_size, v_padding);
48+ if (this ->content && bContent) {
49+ ::memcpy (this ->content, bContent, v_size);
4750 }
4851}
4952
0 commit comments