1 /*
2  * This file is auto-generated.  DO NOT MODIFY.
3  */
4 package android.aidl.tests;
5 
6 public final class UnionWithFd implements android.os.Parcelable {
7   // tags for union fields
8   public final static int num = 0;  // int num;
9   public final static int pfd = 1;  // ParcelFileDescriptor pfd;
10 
11   private int _tag;
12   private Object _value;
13 
UnionWithFd()14   public UnionWithFd() {
15     int _value = 0;
16     this._tag = num;
17     this._value = _value;
18   }
19 
UnionWithFd(android.os.Parcel _aidl_parcel)20   private UnionWithFd(android.os.Parcel _aidl_parcel) {
21     readFromParcel(_aidl_parcel);
22   }
23 
UnionWithFd(int _tag, Object _value)24   private UnionWithFd(int _tag, Object _value) {
25     this._tag = _tag;
26     this._value = _value;
27   }
28 
getTag()29   public int getTag() {
30     return _tag;
31   }
32 
33   // int num;
34 
num(int _value)35   public static UnionWithFd num(int _value) {
36     return new UnionWithFd(num, _value);
37   }
38 
getNum()39   public int getNum() {
40     _assertTag(num);
41     return (int) _value;
42   }
43 
setNum(int _value)44   public void setNum(int _value) {
45     _set(num, _value);
46   }
47 
48   // ParcelFileDescriptor pfd;
49 
pfd(android.os.ParcelFileDescriptor _value)50   public static UnionWithFd pfd(android.os.ParcelFileDescriptor _value) {
51     return new UnionWithFd(pfd, _value);
52   }
53 
getPfd()54   public android.os.ParcelFileDescriptor getPfd() {
55     _assertTag(pfd);
56     return (android.os.ParcelFileDescriptor) _value;
57   }
58 
setPfd(android.os.ParcelFileDescriptor _value)59   public void setPfd(android.os.ParcelFileDescriptor _value) {
60     _set(pfd, _value);
61   }
62 
63   public static final android.os.Parcelable.Creator<UnionWithFd> CREATOR = new android.os.Parcelable.Creator<UnionWithFd>() {
64     @Override
65     public UnionWithFd createFromParcel(android.os.Parcel _aidl_source) {
66       return new UnionWithFd(_aidl_source);
67     }
68     @Override
69     public UnionWithFd[] newArray(int _aidl_size) {
70       return new UnionWithFd[_aidl_size];
71     }
72   };
73 
74   @Override
writeToParcel(android.os.Parcel _aidl_parcel, int _aidl_flag)75   public final void writeToParcel(android.os.Parcel _aidl_parcel, int _aidl_flag) {
76     _aidl_parcel.writeInt(_tag);
77     switch (_tag) {
78     case num:
79       _aidl_parcel.writeInt(getNum());
80       break;
81     case pfd:
82       if ((getPfd()!=null)) {
83         _aidl_parcel.writeInt(1);
84         getPfd().writeToParcel(_aidl_parcel, 0);
85       }
86       else {
87         _aidl_parcel.writeInt(0);
88       }
89       break;
90     }
91   }
92 
readFromParcel(android.os.Parcel _aidl_parcel)93   public void readFromParcel(android.os.Parcel _aidl_parcel) {
94     int _aidl_tag;
95     _aidl_tag = _aidl_parcel.readInt();
96     switch (_aidl_tag) {
97     case num: {
98       int _aidl_value;
99       _aidl_value = _aidl_parcel.readInt();
100       _set(_aidl_tag, _aidl_value);
101       return; }
102     case pfd: {
103       android.os.ParcelFileDescriptor _aidl_value;
104       if ((0!=_aidl_parcel.readInt())) {
105         _aidl_value = android.os.ParcelFileDescriptor.CREATOR.createFromParcel(_aidl_parcel);
106       }
107       else {
108         _aidl_value = null;
109       }
110       _set(_aidl_tag, _aidl_value);
111       return; }
112     }
113     throw new IllegalArgumentException("union: unknown tag: " + _aidl_tag);
114   }
115 
116   @Override
describeContents()117   public int describeContents() {
118     int _mask = 0;
119     switch (getTag()) {
120     case pfd:
121       _mask |= describeContents(getPfd());
122       break;
123     }
124     return _mask;
125   }
describeContents(Object _v)126   private int describeContents(Object _v) {
127     if (_v == null) return 0;
128     if (_v instanceof android.os.Parcelable) {
129       return ((android.os.Parcelable) _v).describeContents();
130     }
131     return 0;
132   }
133 
_assertTag(int tag)134   private void _assertTag(int tag) {
135     if (getTag() != tag) {
136       throw new IllegalStateException("bad access: " + _tagString(tag) + ", " + _tagString(getTag()) + " is available.");
137     }
138   }
139 
_tagString(int _tag)140   private String _tagString(int _tag) {
141     switch (_tag) {
142     case num: return "num";
143     case pfd: return "pfd";
144     }
145     throw new IllegalStateException("unknown field: " + _tag);
146   }
147 
_set(int _tag, Object _value)148   private void _set(int _tag, Object _value) {
149     this._tag = _tag;
150     this._value = _value;
151   }
152 }
153