Skia
2D Graphics Library
SkMemoryStream Class Reference

#include <SkStream.h>

Inheritance diagram for SkMemoryStream:

Public Member Functions

 SkMemoryStream ()
 
 SkMemoryStream (size_t length)
 We allocate (and free) the memory. More...
 
 SkMemoryStream (const void *data, size_t length, bool copyData=false)
 If copyData is true, the stream makes a private copy of the data. More...
 
 SkMemoryStream (sk_sp< SkData > data)
 Creates the stream to read from the specified data. More...
 
virtual void setMemory (const void *data, size_t length, bool copyData=false)
 Resets the stream to the specified data and length, just like the constructor. More...
 
void setMemoryOwned (const void *data, size_t length)
 Replace any memory buffer with the specified buffer. More...
 
sk_sp< SkDataasData () const
 
void setData (sk_sp< SkData > data)
 
void skipToAlign4 ()
 
const void * getAtPos ()
 
size_t read (void *buffer, size_t size) override
 Reads or skips size number of bytes. More...
 
bool isAtEnd () const override
 Returns true when all the bytes in the stream have been read. More...
 
size_t peek (void *buffer, size_t size) const override
 Attempt to peek at size bytes. More...
 
bool rewind () override
 Rewinds to the beginning of the stream. More...
 
std::unique_ptr< SkMemoryStreamduplicate () const
 
size_t getPosition () const override
 Returns the current position in the stream. More...
 
bool seek (size_t position) override
 Seeks to an absolute position in the stream. More...
 
bool move (long offset) override
 Seeks to an relative offset in the stream. More...
 
std::unique_ptr< SkMemoryStreamfork () const
 
size_t getLength () const override
 Returns the total length of the stream. More...
 
const void * getMemoryBase () override
 Returns the starting address for the data. More...
 
bool hasLength () const override
 Returns true if this stream can report its total length. More...
 
bool hasPosition () const override
 Returns true if this stream can report its current position. More...
 
size_t skip (size_t size)
 Skip size number of bytes. More...
 
bool readS8 (int8_t *)
 
bool readS16 (int16_t *)
 
bool readS32 (int32_t *)
 
bool readU8 (uint8_t *i)
 
bool readU16 (uint16_t *i)
 
bool readU32 (uint32_t *i)
 
bool readBool (bool *b)
 
bool readScalar (SkScalar *)
 
bool readPackedUInt (size_t *)
 

Static Public Member Functions

static std::unique_ptr< SkMemoryStreamMakeCopy (const void *data, size_t length)
 Returns a stream with a copy of the input data. More...
 
static std::unique_ptr< SkMemoryStreamMakeDirect (const void *data, size_t length)
 Returns a stream with a bare pointer reference to the input data. More...
 
static std::unique_ptr< SkMemoryStreamMake (sk_sp< SkData > data)
 Returns a stream with a shared reference to the input data. More...
 
static std::unique_ptr< SkStreamAssetMakeFromFile (const char path[])
 Attempts to open the specified file as a stream, returns nullptr on failure. More...
 

Constructor & Destructor Documentation

◆ SkMemoryStream() [1/4]

SkMemoryStream::SkMemoryStream ( )

◆ SkMemoryStream() [2/4]

SkMemoryStream::SkMemoryStream ( size_t  length)

We allocate (and free) the memory.

Write to it via getMemoryBase()

◆ SkMemoryStream() [3/4]

SkMemoryStream::SkMemoryStream ( const void *  data,
size_t  length,
bool  copyData = false 
)

If copyData is true, the stream makes a private copy of the data.

◆ SkMemoryStream() [4/4]

SkMemoryStream::SkMemoryStream ( sk_sp< SkData data)

Creates the stream to read from the specified data.

Member Function Documentation

◆ asData()

sk_sp<SkData> SkMemoryStream::asData ( ) const
inline

◆ duplicate()

std::unique_ptr<SkMemoryStream> SkMemoryStream::duplicate ( ) const
inline

◆ fork()

std::unique_ptr<SkMemoryStream> SkMemoryStream::fork ( ) const
inline

◆ getAtPos()

const void* SkMemoryStream::getAtPos ( )

◆ getLength()

size_t SkMemoryStream::getLength ( ) const
overridevirtual

Returns the total length of the stream.

If this cannot be done, returns 0.

Implements SkStreamAsset.

◆ getMemoryBase()

const void* SkMemoryStream::getMemoryBase ( )
overridevirtual

Returns the starting address for the data.

If this cannot be done, returns NULL.

Implements SkStreamMemory.

◆ getPosition()

size_t SkMemoryStream::getPosition ( ) const
overridevirtual

Returns the current position in the stream.

If this cannot be done, returns 0.

Implements SkStreamSeekable.

◆ hasLength()

bool SkStreamAsset::hasLength ( ) const
inlineoverridevirtualinherited

Returns true if this stream can report its total length.

Reimplemented from SkStream.

◆ hasPosition()

bool SkStreamSeekable::hasPosition ( ) const
inlineoverridevirtualinherited

Returns true if this stream can report its current position.

Reimplemented from SkStream.

◆ isAtEnd()

bool SkMemoryStream::isAtEnd ( ) const
overridevirtual

Returns true when all the bytes in the stream have been read.

As SkStream represents synchronous I/O, isAtEnd returns false when the final stream length isn't known yet, even when all the bytes available so far have been read. This may return true early (when there are no more bytes to be read) or late (after the first unsuccessful read).

Implements SkStream.

◆ Make()

static std::unique_ptr<SkMemoryStream> SkMemoryStream::Make ( sk_sp< SkData data)
static

Returns a stream with a shared reference to the input data.

◆ MakeCopy()

static std::unique_ptr<SkMemoryStream> SkMemoryStream::MakeCopy ( const void *  data,
size_t  length 
)
static

Returns a stream with a copy of the input data.

◆ MakeDirect()

static std::unique_ptr<SkMemoryStream> SkMemoryStream::MakeDirect ( const void *  data,
size_t  length 
)
static

Returns a stream with a bare pointer reference to the input data.

◆ MakeFromFile()

static std::unique_ptr<SkStreamAsset> SkStream::MakeFromFile ( const char  path[])
staticinherited

Attempts to open the specified file as a stream, returns nullptr on failure.

◆ move()

bool SkMemoryStream::move ( long  )
overridevirtual

Seeks to an relative offset in the stream.

If this cannot be done, returns false. If an attempt is made to move to a position outside the stream, the position will be set to the closest point within the stream (beginning or end).

Implements SkStreamSeekable.

◆ peek()

size_t SkMemoryStream::peek ( void *  ,
size_t   
) const
overridevirtual

Attempt to peek at size bytes.

If this stream supports peeking, copy min(size, peekable bytes) into buffer, and return the number of bytes copied. If the stream does not support peeking, or cannot peek any bytes, return 0 and leave buffer unchanged. The stream is guaranteed to be in the same visible state after this call, regardless of success or failure.

Parameters
bufferMust not be NULL, and must be at least size bytes. Destination to copy bytes.
sizeNumber of bytes to copy.
Returns
The number of bytes peeked/copied.

Reimplemented from SkStream.

◆ read()

size_t SkMemoryStream::read ( void *  buffer,
size_t  size 
)
overridevirtual

Reads or skips size number of bytes.

If buffer == NULL, skip size bytes, return how many were skipped. If buffer != NULL, copy size bytes into buffer, return how many were copied.

Parameters
bufferwhen NULL skip size bytes, otherwise copy size bytes into buffer
sizethe number of bytes to skip or copy
Returns
the number of bytes actually read.

Implements SkStream.

◆ readBool()

bool SkStream::readBool ( bool *  b)
inlineinherited

◆ readPackedUInt()

bool SkStream::readPackedUInt ( size_t *  )
inherited

◆ readS16()

bool SkStream::readS16 ( int16_t *  )
inherited

◆ readS32()

bool SkStream::readS32 ( int32_t *  )
inherited

◆ readS8()

bool SkStream::readS8 ( int8_t *  )
inherited

◆ readScalar()

bool SkStream::readScalar ( SkScalar )
inherited

◆ readU16()

bool SkStream::readU16 ( uint16_t *  i)
inlineinherited

◆ readU32()

bool SkStream::readU32 ( uint32_t *  i)
inlineinherited

◆ readU8()

bool SkStream::readU8 ( uint8_t *  i)
inlineinherited

◆ rewind()

bool SkMemoryStream::rewind ( )
overridevirtual

Rewinds to the beginning of the stream.

Returns true if the stream is known to be at the beginning after this call returns.

Implements SkStreamRewindable.

◆ seek()

bool SkMemoryStream::seek ( size_t  )
overridevirtual

Seeks to an absolute position in the stream.

If this cannot be done, returns false. If an attempt is made to seek past the end of the stream, the position will be set to the end of the stream.

Implements SkStreamSeekable.

◆ setData()

void SkMemoryStream::setData ( sk_sp< SkData data)

◆ setMemory()

virtual void SkMemoryStream::setMemory ( const void *  data,
size_t  length,
bool  copyData = false 
)
virtual

Resets the stream to the specified data and length, just like the constructor.

if copyData is true, the stream makes a private copy of the data

◆ setMemoryOwned()

void SkMemoryStream::setMemoryOwned ( const void *  data,
size_t  length 
)

Replace any memory buffer with the specified buffer.

The caller must have allocated data with sk_malloc or sk_realloc, since it will be freed with sk_free.

◆ skip()

size_t SkStream::skip ( size_t  size)
inlineinherited

Skip size number of bytes.

Returns
the actual number bytes that could be skipped.

◆ skipToAlign4()

void SkMemoryStream::skipToAlign4 ( )

The documentation for this class was generated from the following file: