Marshalerpublic abstract class Marshaler extends Object Base class to marshal data to/from managed/native metadata byte buffers.
This class should not be created directly; an instance of it can be obtained
using {@link MarshalQueryable#createMarshaler} for the same type {@code T} if the native type
mapping for {@code T} {@link MarshalQueryable#isTypeMappingSupported supported}. |
Fields Summary |
---|
protected final android.hardware.camera2.utils.TypeReference | mTypeReference | protected final int | mNativeType | public static int | NATIVE_SIZE_DYNAMICUsed to denote variable-length data structures.
If the size is dynamic then we can't know ahead of time how big of a data structure
to preallocate for e.g. arrays, so one object must be unmarshaled at a time. |
Constructors Summary |
---|
protected Marshaler(MarshalQueryable query, android.hardware.camera2.utils.TypeReference typeReference, int nativeType)Instantiate a marshaler between a single managed/native type combination.
This particular managed/native type combination must be supported by
{@link #isTypeMappingSupported}.
mTypeReference = checkNotNull(typeReference, "typeReference must not be null");
mNativeType = checkNativeType(nativeType);
if (!query.isTypeMappingSupported(typeReference, nativeType)) {
throw new UnsupportedOperationException(
"Unsupported type marshaling for managed type "
+ typeReference + " and native type "
+ MarshalHelpers.toStringNativeType(nativeType));
}
|
Methods Summary |
---|
public int | calculateMarshalSize(T value)Get the size in bytes for how much space would be required to write this {@code value}
into a byte buffer using the given {@code nativeType}.
If the size of this {@code T} instance when serialized into a buffer is always constant,
then this method will always return the same value (and particularly, it will return
an equivalent value to {@link #getNativeSize()}.
Overriding this method is a must when the size is {@link NATIVE_SIZE_DYNAMIC dynamic}.
int nativeSize = getNativeSize();
if (nativeSize == NATIVE_SIZE_DYNAMIC) {
throw new AssertionError("Override this function for dynamically-sized objects");
}
return nativeSize;
| public abstract int | getNativeSize()How many bytes a single instance of {@code T} will take up if marshalled to/from
{@code nativeType}.
When unmarshaling data from native to managed, the instance {@code T} is not yet
available. If the native size is always a fixed mapping regardless of the instance of
{@code T} (e.g. if the type is not a container of some sort), it can be used to preallocate
containers for {@code T} to avoid resizing them.
In particular, the array marshaler takes advantage of this (when size is not dynamic)
to preallocate arrays of the right length when unmarshaling an array {@code T[]}.
| public int | getNativeType()The native type corresponding to this marshaler for the native side of this marshaler.
return mNativeType;
| public android.hardware.camera2.utils.TypeReference | getTypeReference()The type reference for {@code T} for the managed type side of this marshaler.
return mTypeReference;
| public abstract void | marshal(T value, java.nio.ByteBuffer buffer)Marshal the specified object instance (value) into a byte buffer.
Upon completion, the {@link ByteBuffer#position()} will have advanced by
the {@link #calculateMarshalSize marshal size} of {@code value}.
| public abstract T | unmarshal(java.nio.ByteBuffer buffer)Unmarshal a new object instance from the byte buffer into its managed type.
Upon completion, the {@link ByteBuffer#position()} will have advanced by
the {@link #calculateMarshalSize marshal size} of the returned {@code T} instance.
|
|