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 */
16package android.hardware.camera2.impl;
17
18import android.hardware.camera2.Size;
19
20import java.nio.ByteBuffer;
21
22public class MetadataMarshalSize implements MetadataMarshalClass<Size> {
23
24    private static final int SIZE = 8;
25
26    @Override
27    public int marshal(Size value, ByteBuffer buffer, int nativeType, boolean sizeOnly) {
28        if (sizeOnly) {
29            return SIZE;
30        }
31
32        buffer.putInt(value.getWidth());
33        buffer.putInt(value.getHeight());
34
35        return SIZE;
36    }
37
38    @Override
39    public Size unmarshal(ByteBuffer buffer, int nativeType) {
40        int width = buffer.getInt();
41        int height = buffer.getInt();
42
43        return new Size(width, height);
44    }
45
46    @Override
47    public Class<Size> getMarshalingClass() {
48        return Size.class;
49    }
50
51    @Override
52    public boolean isNativeTypeSupported(int nativeType) {
53        return nativeType == CameraMetadataNative.TYPE_INT32;
54    }
55
56    @Override
57    public int getNativeSize(int nativeType) {
58        return SIZE;
59    }
60}
61