Revert "Revert "DynamicBuffer: implement BDataIO""
This reverts commit 747b401e87
.
This commit is contained in:
parent
4260c14601
commit
739f15e144
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2009-2014, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@ -9,10 +9,11 @@
|
||||
#ifndef _DYNAMIC_BUFFER_H
|
||||
#define _DYNAMIC_BUFFER_H
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
class DynamicBuffer {
|
||||
class DynamicBuffer : public BDataIO {
|
||||
public:
|
||||
DynamicBuffer(size_t initialSize = 0);
|
||||
~DynamicBuffer();
|
||||
@ -25,11 +26,11 @@ public:
|
||||
|
||||
// Insert data at the end of the buffer. The buffer will be increased to
|
||||
// accomodate the data if needed.
|
||||
status_t Insert(const void* data, size_t size);
|
||||
status_t Write(const void* data, size_t size);
|
||||
|
||||
// Remove data from the start of the buffer. Move the buffer start
|
||||
// pointer to point to the data following it.
|
||||
status_t Remove(void* data, size_t size);
|
||||
ssize_t Read(void* data, size_t size);
|
||||
|
||||
// Return a pointer to the underlying buffer. Note this will not
|
||||
// necessarily be a pointer to the start of the allocated memory as the
|
||||
|
@ -68,7 +68,7 @@ DynamicBuffer::InitCheck() const
|
||||
|
||||
|
||||
status_t
|
||||
DynamicBuffer::Insert(const void* data, size_t size)
|
||||
DynamicBuffer::Write(const void* data, size_t size)
|
||||
{
|
||||
if (fInit != B_OK)
|
||||
return fInit;
|
||||
@ -84,14 +84,14 @@ DynamicBuffer::Insert(const void* data, size_t size)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DynamicBuffer::Remove(void* data, size_t size)
|
||||
ssize_t
|
||||
DynamicBuffer::Read(void* data, size_t size)
|
||||
{
|
||||
if (fInit != B_OK)
|
||||
return fInit;
|
||||
|
||||
if (fDataStart + size > fDataEnd)
|
||||
return B_BUFFER_OVERFLOW;
|
||||
if (size > Size())
|
||||
size = Size();
|
||||
|
||||
memcpy(data, fBuffer + fDataStart, size);
|
||||
fDataStart += size;
|
||||
@ -99,7 +99,7 @@ DynamicBuffer::Remove(void* data, size_t size)
|
||||
if (fDataStart == fDataEnd)
|
||||
fDataStart = fDataEnd = 0;
|
||||
|
||||
return B_OK;
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,7 +54,7 @@ BNetBuffer::BNetBuffer(BMessage* archive) :
|
||||
&bufferSize) == B_OK) {
|
||||
fImpl = new (std::nothrow) DynamicBuffer(bufferSize);
|
||||
if (fImpl != NULL) {
|
||||
status_t result = fImpl->Insert(bufferPtr, bufferSize);
|
||||
status_t result = fImpl->Write(bufferPtr, bufferSize);
|
||||
if (result == B_OK)
|
||||
fInit = fImpl->InitCheck();
|
||||
else
|
||||
@ -185,7 +185,7 @@ BNetBuffer::AppendString(const char* data)
|
||||
status_t
|
||||
BNetBuffer::AppendData(const void* data, size_t size)
|
||||
{
|
||||
return fImpl->Insert(data, size);
|
||||
return fImpl->Write(data, size);
|
||||
}
|
||||
|
||||
|
||||
@ -332,7 +332,7 @@ BNetBuffer::RemoveString(char* data, size_t size)
|
||||
status_t
|
||||
BNetBuffer::RemoveData(void* data, size_t size)
|
||||
{
|
||||
return fImpl->Remove(data, size);
|
||||
return fImpl->Read(data, size);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user