1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.hardware.camera2.impl; 18 19 import java.nio.ByteBuffer; 20 21 public interface MetadataMarshalClass<T> { 22 23 /** 24 * Marshal the specified object instance (value) into a byte buffer. 25 * 26 * @param value the value of type T that we wish to write into the byte buffer 27 * @param buffer the byte buffer into which the marshalled object will be written 28 * @param nativeType the native type, e.g. 29 * {@link android.hardware.camera2.impl.CameraMetadataNative#TYPE_BYTE TYPE_BYTE}. 30 * Guaranteed to be one for which isNativeTypeSupported returns true. 31 * @param sizeOnly if this is true, don't write to the byte buffer. calculate the size only. 32 * @return the size that needs to be written to the byte buffer 33 */ 34 int marshal(T value, ByteBuffer buffer, int nativeType, boolean sizeOnly); 35 36 /** 37 * Unmarshal a new object instance from the byte buffer. 38 * @param buffer the byte buffer, from which we will read the object 39 * @param nativeType the native type, e.g. 40 * {@link android.hardware.camera2.impl.CameraMetadataNative#TYPE_BYTE TYPE_BYTE}. 41 * Guaranteed to be one for which isNativeTypeSupported returns true. 42 * @return a new instance of type T read from the byte buffer 43 */ 44 T unmarshal(ByteBuffer buffer, int nativeType); 45 46 Class<T> getMarshalingClass(); 47 48 /** 49 * Determines whether or not this marshaller supports this native type. Most marshallers 50 * will are likely to only support one type. 51 * 52 * @param nativeType the native type, e.g. 53 * {@link android.hardware.camera2.impl.CameraMetadataNative#TYPE_BYTE TYPE_BYTE} 54 * @return true if it supports, false otherwise 55 */ 56 boolean isNativeTypeSupported(int nativeType); 57 58 public static int NATIVE_SIZE_DYNAMIC = -1; 59 60 /** 61 * How many bytes T will take up if marshalled to/from nativeType 62 * @param nativeType the native type, e.g. 63 * {@link android.hardware.camera2.impl.CameraMetadataNative#TYPE_BYTE TYPE_BYTE} 64 * @return a size in bytes, or NATIVE_SIZE_DYNAMIC if the size is dynamic 65 */ 66 int getNativeSize(int nativeType); 67 } 68