Revert "DynamicBuffer: implement BDataIO"

This reverts commit 36b1f55a18.
This commit is contained in:
Ingo Weinhold
2014-06-18 22:13:39 +02:00
parent 256080b112
commit 747b401e87
3 changed files with 13 additions and 14 deletions
+4 -5
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009-2014, Haiku, Inc. All Rights Reserved. * Copyright 2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -9,11 +9,10 @@
#ifndef _DYNAMIC_BUFFER_H #ifndef _DYNAMIC_BUFFER_H
#define _DYNAMIC_BUFFER_H #define _DYNAMIC_BUFFER_H
#include <DataIO.h>
#include <SupportDefs.h> #include <SupportDefs.h>
class DynamicBuffer : public BDataIO { class DynamicBuffer {
public: public:
DynamicBuffer(size_t initialSize = 0); DynamicBuffer(size_t initialSize = 0);
~DynamicBuffer(); ~DynamicBuffer();
@@ -26,11 +25,11 @@ public:
// Insert data at the end of the buffer. The buffer will be increased to // Insert data at the end of the buffer. The buffer will be increased to
// accomodate the data if needed. // accomodate the data if needed.
status_t Write(const void* data, size_t size); status_t Insert(const void* data, size_t size);
// Remove data from the start of the buffer. Move the buffer start // Remove data from the start of the buffer. Move the buffer start
// pointer to point to the data following it. // pointer to point to the data following it.
ssize_t Read(void* data, size_t size); status_t Remove(void* data, size_t size);
// Return a pointer to the underlying buffer. Note this will not // Return a pointer to the underlying buffer. Note this will not
// necessarily be a pointer to the start of the allocated memory as the // necessarily be a pointer to the start of the allocated memory as the
+6 -6
View File
@@ -68,7 +68,7 @@ DynamicBuffer::InitCheck() const
status_t status_t
DynamicBuffer::Write(const void* data, size_t size) DynamicBuffer::Insert(const void* data, size_t size)
{ {
if (fInit != B_OK) if (fInit != B_OK)
return fInit; return fInit;
@@ -84,14 +84,14 @@ DynamicBuffer::Write(const void* data, size_t size)
} }
ssize_t status_t
DynamicBuffer::Read(void* data, size_t size) DynamicBuffer::Remove(void* data, size_t size)
{ {
if (fInit != B_OK) if (fInit != B_OK)
return fInit; return fInit;
if (size > Size()) if (fDataStart + size > fDataEnd)
size = Size(); return B_BUFFER_OVERFLOW;
memcpy(data, fBuffer + fDataStart, size); memcpy(data, fBuffer + fDataStart, size);
fDataStart += size; fDataStart += size;
@@ -99,7 +99,7 @@ DynamicBuffer::Read(void* data, size_t size)
if (fDataStart == fDataEnd) if (fDataStart == fDataEnd)
fDataStart = fDataEnd = 0; fDataStart = fDataEnd = 0;
return size; return B_OK;
} }
+3 -3
View File
@@ -54,7 +54,7 @@ BNetBuffer::BNetBuffer(BMessage* archive) :
&bufferSize) == B_OK) { &bufferSize) == B_OK) {
fImpl = new (std::nothrow) DynamicBuffer(bufferSize); fImpl = new (std::nothrow) DynamicBuffer(bufferSize);
if (fImpl != NULL) { if (fImpl != NULL) {
status_t result = fImpl->Write(bufferPtr, bufferSize); status_t result = fImpl->Insert(bufferPtr, bufferSize);
if (result == B_OK) if (result == B_OK)
fInit = fImpl->InitCheck(); fInit = fImpl->InitCheck();
else else
@@ -185,7 +185,7 @@ BNetBuffer::AppendString(const char* data)
status_t status_t
BNetBuffer::AppendData(const void* data, size_t size) BNetBuffer::AppendData(const void* data, size_t size)
{ {
return fImpl->Write(data, size); return fImpl->Insert(data, size);
} }
@@ -332,7 +332,7 @@ BNetBuffer::RemoveString(char* data, size_t size)
status_t status_t
BNetBuffer::RemoveData(void* data, size_t size) BNetBuffer::RemoveData(void* data, size_t size)
{ {
return fImpl->Read(data, size); return fImpl->Remove(data, size);
} }