1 /* 2 * Copyright (C) 2023 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 com.android.adservices.service.common.bhttp; 18 19 import android.annotation.NonNull; 20 21 /** 22 * Define the ability to convert a binary http related object to bytes. 23 * 24 * <p>Methods in this interface should be package private by default. 25 */ 26 abstract class BinaryHttpSerializableComponent { 27 /** 28 * Returns the serialized representation with a 2D byte array. 29 * 30 * <p>Structure of the 2D array depends on the extending class. 31 * 32 * <p>General contract is the flattened 1D array is the binary representation of the object. 33 * 34 * <p>This is help to reduce array coping during serializing each component, so we can do actual 35 * data coping only when we actually construct the final byte array. 36 */ 37 @NonNull knownLengthSerialize()38 abstract byte[][] knownLengthSerialize(); 39 40 /** Returns the number of byte arrays returned by {@link #knownLengthSerialize()}. */ getKnownLengthSerializedSectionsCount()41 abstract int getKnownLengthSerializedSectionsCount(); 42 } 43