package fanch.multijeu.common.core;

import android.os.Parcel;
import android.os.Parcelable;

public class SerializedObject<T extends DataLoader.ISaveable> extends Saveable implements Parcelable {
    protected byte[] mData;

    public SerializedObject(byte[] b)
    {
        mData=b;
    }

    public SerializedObject(T x)
    {
        mData=x.saveToByteArray();
    }


    public byte[] getBytes()
    {
        return mData;
    }

    public T newObject()
    {
        return (T)DataLoader.load(this);
    }


    protected SerializedObject(Parcel in) {
        mData = in.createByteArray();
    }

    public static final Creator<SerializedObject> CREATOR = new Creator<SerializedObject>() {
        @Override
        public SerializedObject createFromParcel(Parcel in) {
            return new SerializedObject(in);
        }

        @Override
        public SerializedObject[] newArray(int size) {
            return new SerializedObject[size];
        }
    };




    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeByteArray(mData);
    }
}
