SParcel Class Reference
[Binder]

#include <support/Parcel.h>

List of all members.


Detailed Description

Container for a raw block of data that can be transfered through IPC.


Typed Data Handling

These functions read and write typed data in the parcel. This data is formatted the same way as SValue's archived representation, so it is valid to write a single chunk of data through these APIs, which is read back as a generic SValue (or vice-versa).

ssize_t MarshalFixedData (type_code type, const void *data, size_t amount)
 Write fixed-sized marshalled data to parcel.
ssize_t ReadFlatBinderObject (flat_binder_object *out)
 Core API for reading a driver binder type.
ssize_t ReadSmallData (small_flat_data *out)
 Core API for reading the next type header from the parcel.
ssize_t ReadSmallDataOrObject (small_flat_data *out, const void *who)
 Like ReadSmallData(), but will also read object references.
status_t ReadTypedData (type_code type, void *data)
 Read data by type code.
SValue ReadValue ()
 Read an SValue.
status_t SkipValue ()
 Skip over a typed value in the parcel, without reading it.
status_t UnmarshalFixedData (type_code type, void *data, size_t amount)
 Read fixed-sized marshalled data from parcel.
ssize_t WriteBinder (const flat_binder_object &val)
 Core API for writing a binder type.
ssize_t WriteLargeData (uint32_t packedType, size_t length, const void *data)
 Core API for writing a large type header and its data.
ssize_t WriteSmallData (const small_flat_data &flat)
 Core API for writing small flat data structure.
ssize_t WriteSmallData (uint32_t packedType, uint32_t packedData)
 Core API for writing a small type header and its data.
ssize_t WriteTypedData (type_code type, const void *data)
 Write data by type code.
ssize_t WriteTypeHeader (type_code type, size_t amount)
 Write only the header part of a typed data.
ssize_t WriteTypeHeaderAndData (type_code type, const void *data, size_t amount)
 Write header and data.
ssize_t WriteValue (const SValue &val)
 Write an SValue.
static ssize_t TypedDataSize (type_code type, const void *data)
 If you were to use WriteTypedData() to write this data, how much would it write?

Reading and Writing Objects

This is the high-level object API. Objects are written as structured types, so you can you can mix between reading/writing with these functions and with SValue.

sptr< IBinderReadBinder ()
sptr< SKeyIDReadKeyID ()
wptr< IBinderReadWeakBinder ()
ssize_t WriteBinder (const small_flat_data &val)
ssize_t WriteBinder (const sptr< IBinder > &val)
ssize_t WriteKeyID (const sptr< SKeyID > &val)
ssize_t WriteWeakBinder (const wptr< IBinder > &val)
static ssize_t BinderSize (const sptr< IBinder > &val)
static ssize_t WeakBinderSize (const wptr< IBinder > &val)

Public Types

typedef void(* free_func )(const void *data, ssize_t len, void *context)
typedef status_t(* reply_func )(const SParcel &buffer, void *context)

Public Member Functions

void * Alloc (ssize_t len)
 Allocate data in the parcel that you can edit.
ssize_t Avail () const
 Return the bytes available for use in this parcel, or an error code.
ssize_t AvailBinders () const
 Return the number of Binders that will still fit in the parcel, or an error code.
status_t Copy (const SParcel &src)
 Allocate data in the parcel, copying from another parcel.
status_t Copy (const void *data, ssize_t len)
 Allocate data in the parcel, copying from somewhere else.
int32_t CountValues () const
 Return the number of values in the parcel.
const void * Data () const
 Return a pointer to the data in this parcel.
void * EditData ()
 Return an editable pointer to the data in this parcel.
status_t ErrorCheck () const
 Return the current operating status of the parcel.
void Free ()
 Deallocating data currently in the parcel.
int32_t GetValues (int32_t maxCount, SValue *outValues) const
 Retrieve flattened values from the parcel.
bool IsCacheable () const
 Will PutParcel() be able to return this parcel to the cache?
ssize_t Length () const
 Return the number of bytes in this parcel, or an error code.
off_t Position () const
void PrintToStream (const sptr< ITextOutput > &io, uint32_t flags=0) const
void * ReAlloc (ssize_t len)
 Modify data in the parcel.
void Reference (const void *data, ssize_t len, free_func freeFunc=NULL, void *context=NULL)
 Set the parcel to reference an external block of data.
status_t Reserve (ssize_t len)
 Create space in the parcel for data.
void Reset ()
 Release all binders and forget the contents, but don't free the data buffer.
status_t SetLength (ssize_t len)
void SetPosition (off_t pos)
status_t SetValues (const SValue *value1,...)
 Allocate data in the parcel as an array of flattened values.
 SParcel (const void *data, ssize_t len, free_func freeFunc=NULL, void *freeContext=NULL, reply_func replyFunc=NULL, void *replyContext=NULL)
 SParcel (reply_func replyFunc, void *replyContext=NULL)
 SParcel (sptr< IByteOutput > output, sptr< IByteInput > input, sptr< IByteSeekable > seek, ssize_t bufferSize=-1)
 SParcel (ssize_t bufferSize=-1)
void Transfer (SParcel *src)
 Transfer ownership of the data from the given SParcel to this one, leaving.
virtual ~SParcel ()
Binder Management
Retrieving and restoring binder information in the parcel.

const void * BinderOffsetsData () const
size_t BinderOffsetsLength () const
status_t SetBinderOffsets (binder_ipc_info const *const offsets, size_t count, bool takeRefs=true)
Raw Data Functions
These functions do not read/write a type header. Consider them 'low level'.

ssize_t Drain (size_t amount)
ssize_t DrainPadding ()
 Skip past padding to next 8-byte boundary.
ssize_t Flush ()
ssize_t Read (void *buffer, size_t amount)
bool ReadBool ()
double ReadDouble ()
float ReadFloat ()
const void * ReadInPlace (size_t amount)
int16_t ReadInt16 ()
int32_t ReadInt32 ()
int64_t ReadInt64 ()
int8_t ReadInt8 ()
ssize_t ReadPadded (void *buffer, size_t amount)
SString ReadString ()
uint16_t ReadUInt16 ()
uint32_t ReadUInt32 ()
uint64_t ReadUInt64 ()
uint8_t ReadUInt8 ()
ssize_t Sync ()
ssize_t Write (const void *buffer, size_t amount)
ssize_t WriteBool (bool val)
ssize_t WriteDouble (double val)
ssize_t WriteFloat (float val)
void * WriteInPlace (size_t amount)
 Extend the data stream by amount and return a pointer to the begining of the new chunk.
ssize_t WriteInt16 (int16_t val)
ssize_t WriteInt32 (int32_t val)
ssize_t WriteInt64 (int64_t val)
ssize_t WriteInt8 (int8_t val)
ssize_t WritePadded (const void *buffer, size_t amount)
 Write data, padded appropriated (by 8 bytes).
ssize_t WritePadding ()
 Add padding to ensure next write is at 8-byte boundary.
ssize_t WriteString (const char *val)
ssize_t WriteString (const SString &val)
ssize_t WriteUInt16 (uint16_t val)
ssize_t WriteUInt32 (uint32_t val)
ssize_t WriteUInt64 (uint64_t val)
ssize_t WriteUInt8 (uint8_t val)
status_t Reply ()
bool ReplyRequested () const
 Sending replies. XXX REMOVE.

Static Public Member Functions

static SParcelGetParcel (void)
static void PutParcel (SParcel *)

Protected Member Functions

virtual ssize_t ReadBuffer (void *buffer, size_t len)
virtual ssize_t WriteBuffer (const void *buffer, size_t len) const


Member Typedef Documentation

typedef void(* free_func)(const void *data, ssize_t len, void *context)
 

typedef status_t(* reply_func)(const SParcel &buffer, void *context)
 


Constructor & Destructor Documentation

SParcel ssize_t  bufferSize = -1  ) 
 

SParcel sptr< IByteOutput output,
sptr< IByteInput input,
sptr< IByteSeekable seek,
ssize_t  bufferSize = -1
 

SParcel reply_func  replyFunc,
void *  replyContext = NULL
 

SParcel const void *  data,
ssize_t  len,
free_func  freeFunc = NULL,
void *  freeContext = NULL,
reply_func  replyFunc = NULL,
void *  replyContext = NULL
 

~SParcel  )  [virtual]
 


Member Function Documentation

void * Alloc ssize_t  len  ) 
 

Allocate data in the parcel that you can edit.

ssize_t Avail  )  const
 

Return the bytes available for use in this parcel, or an error code.

ssize_t AvailBinders  )  const
 

Return the number of Binders that will still fit in the parcel, or an error code.

Note that this number is somewhat fuzzy, as the real number depends on the kind of binder being written. We guarantee there is enough room to write the returned number of binders of any type.

const void * BinderOffsetsData  )  const
 

size_t BinderOffsetsLength  )  const
 

ssize_t BinderSize const sptr< IBinder > &  val  )  [static]
 

status_t Copy const SParcel src  ) 
 

Allocate data in the parcel, copying from another parcel.

status_t Copy const void *  data,
ssize_t  len
 

Allocate data in the parcel, copying from somewhere else.

int32_t CountValues  )  const
 

Return the number of values in the parcel.

const void * Data  )  const
 

Return a pointer to the data in this parcel.

ssize_t Drain size_t  amount  ) 
 

ssize_t DrainPadding  ) 
 

Skip past padding to next 8-byte boundary.

void * EditData  ) 
 

Return an editable pointer to the data in this parcel.

status_t ErrorCheck  )  const
 

Return the current operating status of the parcel.

ssize_t Flush  ) 
 

void Free  ) 
 

Deallocating data currently in the parcel.

SParcel * GetParcel void   )  [static]
 

int32_t GetValues int32_t  maxCount,
SValue outValues
const
 

Retrieve flattened values from the parcel.

bool IsCacheable  )  const
 

Will PutParcel() be able to return this parcel to the cache?

ssize_t Length  )  const
 

Return the number of bytes in this parcel, or an error code.

ssize_t MarshalFixedData type_code  type,
const void *  data,
size_t  amount
 

Write fixed-sized marshalled data to parcel.

This is the same as WriteTypeHeaderAndData(), except if 'data' is NULL then it writes a NULL value.

off_t Position  )  const
 

void PrintToStream const sptr< ITextOutput > &  io,
uint32_t  flags = 0
const
 

void PutParcel SParcel  )  [static]
 

ssize_t Read void *  buffer,
size_t  amount
 

sptr< IBinder > ReadBinder  ) 
 

bool ReadBool  ) 
 

ssize_t ReadBuffer void *  buffer,
size_t  len
[protected, virtual]
 

double ReadDouble  ) 
 

ssize_t ReadFlatBinderObject flat_binder_object out  ) 
 

Core API for reading a driver binder type.

float ReadFloat  ) 
 

void const * ReadInPlace size_t  amount  ) 
 

int16_t ReadInt16  ) 
 

int32_t ReadInt32  ) 
 

int64_t ReadInt64  ) 
 

int8_t ReadInt8  ) 
 

sptr< SKeyID > ReadKeyID  ) 
 

ssize_t ReadPadded void *  buffer,
size_t  amount
 

ssize_t ReadSmallData small_flat_data out  ) 
 

Core API for reading the next type header from the parcel.

ssize_t ReadSmallDataOrObject small_flat_data out,
const void *  who
 

Like ReadSmallData(), but will also read object references.

If the data being read is an object, this function will automatically acquire the appropriate reference on it that is owned by 'who'.

SString ReadString  ) 
 

status_t ReadTypedData type_code  type,
void *  data
 

Read data by type code.

If the given type doesn't match what is currently in the parcel, nothing will be read; the object will remain unchanged and a type mismatch error will be returned. If this function fails due to a mismatch between the size stored in the type header and the amount read, consider the parcel invalid. Notice that B_NULL_TYPE can match any type (because a NULL pointer was passed on other side). In this case, the special error code B_BINDER_READ_NULL_VALUE will be returned so that clients can react if needed.

uint16_t ReadUInt16  )  [inline]
 

uint32_t ReadUInt32  )  [inline]
 

uint64_t ReadUInt64  )  [inline]
 

uint8_t ReadUInt8  )  [inline]
 

SValue ReadValue  ) 
 

Read an SValue.

This is a synonym for SValue::Unarchive(parcel).

wptr< IBinder > ReadWeakBinder  ) 
 

void * ReAlloc ssize_t  len  ) 
 

Modify data in the parcel.

void Reference const void *  data,
ssize_t  len,
free_func  freeFunc = NULL,
void *  context = NULL
 

Set the parcel to reference an external block of data.

status_t Reply  ) 
 

bool ReplyRequested  )  const
 

Sending replies. XXX REMOVE.

status_t Reserve ssize_t  len  ) 
 

Create space in the parcel for data.

void Reset  ) 
 

Release all binders and forget the contents, but don't free the data buffer.

status_t SetBinderOffsets binder_ipc_info const *const   offsets,
size_t  count,
bool  takeRefs = true
 

status_t SetLength ssize_t  len  ) 
 

void SetPosition off_t  pos  ) 
 

status_t SetValues const SValue value1,
  ...
 

Allocate data in the parcel as an array of flattened values.

status_t SkipValue  ) 
 

Skip over a typed value in the parcel, without reading it.

Returns B_OK if the value was skipped. If the data at the current location is not a valid typed data, an error is returned in the parcel should be considered corrupt.

ssize_t Sync  ) 
 

void Transfer SParcel src  ) 
 

Transfer ownership of the data from the given SParcel to this one, leaving.

Parameters:
src empty.

ssize_t TypedDataSize type_code  type,
const void *  data
[static]
 

If you were to use WriteTypedData() to write this data, how much would it write?

status_t UnmarshalFixedData type_code  type,
void *  data,
size_t  amount
 

Read fixed-sized marshalled data from parcel.

If the data in the parcel matches the given type and size, it will be written to 'data'. Otherwise an error is returned and the parcel must be considered invalid.

ssize_t WeakBinderSize const wptr< IBinder > &  val  )  [static]
 

ssize_t Write const void *  buffer,
size_t  amount
 

ssize_t WriteBinder const small_flat_data val  ) 
 

ssize_t WriteBinder const sptr< IBinder > &  val  ) 
 

ssize_t WriteBinder const flat_binder_object val  ) 
 

Core API for writing a binder type.

ssize_t WriteBool bool  val  ) 
 

ssize_t WriteBuffer const void *  buffer,
size_t  len
const [protected, virtual]
 

ssize_t WriteDouble double  val  ) 
 

ssize_t WriteFloat float  val  ) 
 

void * WriteInPlace size_t  amount  ) 
 

Extend the data stream by amount and return a pointer to the begining of the new chunk.

ssize_t WriteInt16 int16_t  val  ) 
 

ssize_t WriteInt32 int32_t  val  ) 
 

ssize_t WriteInt64 int64_t  val  ) 
 

ssize_t WriteInt8 int8_t  val  ) 
 

ssize_t WriteKeyID const sptr< SKeyID > &  val  ) 
 

ssize_t WriteLargeData uint32_t  packedType,
size_t  length,
const void *  data
 

Core API for writing a large type header and its data.

If 'data' is NULL, only the header will be written.

ssize_t WritePadded const void *  buffer,
size_t  amount
 

Write data, padded appropriated (by 8 bytes).

ssize_t WritePadding  ) 
 

Add padding to ensure next write is at 8-byte boundary.

ssize_t WriteSmallData const small_flat_data flat  ) 
 

Core API for writing small flat data structure.

ssize_t WriteSmallData uint32_t  packedType,
uint32_t  packedData
 

Core API for writing a small type header and its data.

ssize_t WriteString const char *  val  ) 
 

ssize_t WriteString const SString val  ) 
 

ssize_t WriteTypedData type_code  type,
const void *  data
 

Write data by type code.

Write the requested typed data into the parcel. The amount written is determined based on the type code -- 'data' must have that amount of data.

ssize_t WriteTypeHeader type_code  type,
size_t  amount
 

Write only the header part of a typed data.

If the 'amount' is enough to fit into a small data representation, only the packed int32 type code is written (with the length encoded inside of it). Otherwise the type code and length is written in 8 bytes.

ssize_t WriteTypeHeaderAndData type_code  type,
const void *  data,
size_t  amount
 

Write header and data.

This uses WriteTypeHeader() to write the header, and then writes the given data immediately after.

ssize_t WriteUInt16 uint16_t  val  )  [inline]
 

ssize_t WriteUInt32 uint32_t  val  )  [inline]
 

ssize_t WriteUInt64 uint64_t  val  )  [inline]
 

ssize_t WriteUInt8 uint8_t  val  )  [inline]
 

ssize_t WriteValue const SValue val  ) 
 

Write an SValue.

This is a synomym for val.Archive(parcel).

ssize_t WriteWeakBinder const wptr< IBinder > &  val  ) 
 


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