public final class MarshalHelpers extends Object
The intention is to statically import everything from this file into another file when implementing a new marshaler (or marshal queryable).
The helpers are centered around providing primitive knowledge of the native types, such as the native size, the managed class wrappers, and various precondition checks.
Modifier and Type | Field and Description |
---|---|
static int |
SIZEOF_BYTE |
static int |
SIZEOF_DOUBLE |
static int |
SIZEOF_FLOAT |
static int |
SIZEOF_INT32 |
static int |
SIZEOF_INT64 |
static int |
SIZEOF_RATIONAL |
Modifier and Type | Method and Description |
---|---|
static int |
checkNativeType(int nativeType)
Ensure that the
nativeType is one of the native types supported
by CameraMetadataNative . |
static int |
checkNativeTypeEquals(int expectedNativeType,
int actualNativeType)
Ensure that the expected and actual native types are equal.
|
static <T> Class<T> |
checkPrimitiveClass(Class<T> klass)
Ensure that the
klass is one of the metadata-primitive classes. |
static int |
getPrimitiveTypeSize(int nativeType)
Get the size in bytes for the native camera metadata type.
|
static <T> boolean |
isPrimitiveClass(Class<T> klass)
Checks whether or not
klass is one of the metadata-primitive classes. |
static String |
toStringNativeType(int nativeType)
Return a human-readable representation of the
nativeType , e.g. |
static <T> Class<T> |
wrapClassIfPrimitive(Class<T> klass)
Wrap
klass with its wrapper variant if it was a Class corresponding
to a Java primitive. |
public static final int SIZEOF_BYTE
public static final int SIZEOF_INT32
public static final int SIZEOF_INT64
public static final int SIZEOF_FLOAT
public static final int SIZEOF_DOUBLE
public static final int SIZEOF_RATIONAL
public static int getPrimitiveTypeSize(int nativeType)
This used to determine how many bytes it would take to encode/decode a single value
of that nativeType
.
nativeType
- the native type, e.g.
TYPE_BYTE
.UnsupportedOperationException
- if nativeType was not one of the built-in typespublic static <T> Class<T> checkPrimitiveClass(Class<T> klass)
klass
is one of the metadata-primitive classes.klass
- a non-null
referenceklass
instanceUnsupportedOperationException
- if klass was not one of the built-in classesNullPointerException
- if klass was nullisPrimitiveClass(java.lang.Class<T>)
public static <T> boolean isPrimitiveClass(Class<T> klass)
klass
is one of the metadata-primitive classes.
The following types (whether boxed or unboxed) are considered primitive:
This doesn't strictly follow the java understanding of primitive since boxed objects are included, Rational is included, and other types such as char and short are not included.
klass
- a Class
instance; using null
will return false
true
if primitive, false
otherwisepublic static <T> Class<T> wrapClassIfPrimitive(Class<T> klass)
klass
with its wrapper variant if it was a Class
corresponding
to a Java primitive.
Non-primitive classes are passed through as-is.
For example, for a primitive int.class => Integer.class
,
but for a non-primitive Rational.class => Rational.class
.
klass
- a Class
referencepublic static String toStringNativeType(int nativeType)
nativeType
, e.g. "TYPE_INT32"
Out-of-range values return a string with "UNKNOWN" as the prefix.
nativeType
- the native typepublic static int checkNativeType(int nativeType)
nativeType
is one of the native types supported
by CameraMetadataNative
.nativeType
- the native typeUnsupportedOperationException
- if the native type was invalidpublic static int checkNativeTypeEquals(int expectedNativeType, int actualNativeType)
expectedNativeType
- the expected native typeactualNativeType
- the actual native typeUnsupportedOperationException
- if the types are not equal