add read/write SkData methods

git-svn-id: http://skia.googlecode.com/svn/trunk@4427 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2012-07-02 19:35:13 +00:00
parent b3c0f4886e
commit 2e07942f42
2 changed files with 20 additions and 0 deletions

View File

@ -65,6 +65,12 @@ public:
SkScalar readScalar();
size_t readPackedUInt();
/**
* Create a new SkData from the stream contents. This balances the call
* SkWStream::writeData().
*/
SkData* readData();
private:
typedef SkRefCnt INHERITED;
};

View File

@ -93,6 +93,17 @@ size_t SkStream::readPackedUInt() {
}
}
SkData* SkStream::readStream() {
size_t size = this->readU32();
if (0 == size) {
return SkData::NewEmpty();
} else {
void* buffer = sk_malloc_throw(size);
stream->read(buffer, size);
return SkData::NewFromMalloc(buffer, size);
}
}
//////////////////////////////////////////////////////////////////////////////////////
SkWStream::~SkWStream()
@ -200,7 +211,10 @@ bool SkWStream::writeStream(SkStream* stream, size_t length) {
bool SkWStream::writeData(const SkData* data) {
if (data) {
this->write32(data->size());
this->write(data->data(), data->size());
} else {
this->write32(0);
}
return true;
}