Home | History | Annotate | Download | only in vehiclenetwork
      1 /*
      2  * Copyright (C) 2015 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 package com.android.car.vehiclenetwork;
     17 
     18 import android.os.Parcel;
     19 import android.os.Parcelable;
     20 import android.os.Parcelable.Creator;
     21 
     22 import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropValue;
     23 import com.google.protobuf.InvalidProtocolBufferException;
     24 
     25 public class VehiclePropValueParcelable implements Parcelable {
     26 
     27     public final VehiclePropValue value;
     28 
     29     public VehiclePropValueParcelable(VehiclePropValue value) {
     30         this.value = value;
     31     }
     32 
     33     public VehiclePropValueParcelable(Parcel in) {
     34         byte[] blob = in.readBlob();
     35         try {
     36             value = VehiclePropValue.parseFrom(blob);
     37         } catch (InvalidProtocolBufferException e) {
     38             throw new IllegalArgumentException(e);
     39         }
     40     }
     41 
     42     @Override
     43     public int describeContents() {
     44         return 0;
     45     }
     46 
     47     @Override
     48     public void writeToParcel(Parcel dest, int flags) {
     49         // this is never used for java side as service is implemented in native side.
     50         dest.writeBlob(value.toByteArray());
     51     }
     52 
     53     public static final Creator<VehiclePropValueParcelable> CREATOR =
     54             new Creator<VehiclePropValueParcelable>() {
     55         @Override
     56         public VehiclePropValueParcelable createFromParcel(Parcel in) {
     57             return new VehiclePropValueParcelable(in);
     58         }
     59 
     60         @Override
     61         public VehiclePropValueParcelable[] newArray(int size) {
     62             return new VehiclePropValueParcelable[size];
     63         }
     64     };
     65 }
     66