BFlattenable

Member Functions

Flatten(), Unflatten()

virtual status_t Flatten(void *buffer, ssize_t numBytes) const = 0
virtual status_t Unflatten(type_code code, const void *buffer, ssize_t numBytes) = 0

Flatten() is implemented by derived classes to write the object into the buffer. There are numBytes bytes of memory available at the buffer address. If this isn’t at least as much memory as the FlattenedSize() function says is necessary, Flatten() should return an error. If successful, it should return B_OK.

Unflatten() is implemented by derived classes to set object values from numBytes bytes of data taken from the buffer. However, it should read the data only if the type code it’s passed indicates that the data is a type that it supports—that is, only if it’s AllowsTypeCode() function returns true for the code. If successful in reconstructing the object from the flattened data, Unflatten() should return B_OK. If not, it should return B_ERROR or a more descriptive error code.

FlattenedSize()

virtual ssize_t BFlattenable::FlattenedSize() const = 0

Implemented by derived classes to return the amount of memory needed to hold the flattened object. This is the minimal amount that must be allocated and passed to Flatten().

TypeCode(), AllowsTypeCode()

virtual type_code BFlattenable::TypeCode() const = 0
virtual bool BFlattenable::AllowsTypeCode(type_code code) const

TypeCode() is implemented by derived classes to return the type code that identifies the class type. The code is used to identify an instance of the class in its flattened state, for example when it’s added to a BMessage.

AllowsType() returns true if the code it’s passed matches the code returned by TypeCode() and false if not. It can be modified in derived classes to apply a more liberal standard—to allow more than one type code to identify the object.

See also: BMessage::AddData()