02 parcel

431
-1

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
431
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

02 parcel

  1. 1. Drive for better visionParcelFebruary, 2012 Himax Media Solutions 承景科技股份有限公司
  2. 2. Parcel  IBinder 是在 process 間傳遞資料的 class  Parcel 的功能是以 serialize 的方式包裝資料,用 IBinder 來 傳遞資料  實作  能夠使用 writeInt32, writeFloat 等函式包裝資料,將資料序列 化放在 buffer 中  空間不足時會自動分配新的 buffer  支援的資料型態分為六類  primitive: int, float, String, boolean, ...  primitive arrays: int[], float[], ...  Parcelable: interface  Bundle: a type-safe key/value mapping container  active object: binder, file descriptor  untyped container: Object, List, Map, SparseArrayHimax Media Solutions Proprietary & Confidential 2
  3. 3. initState mDataCapacity = 0 mData mDataSize = mDataPos = 0Himax Media Solutions Proprietary & Confidential 3
  4. 4. restartWrite (desireSize) mDataCapacity = desireSize mData mDataSize = mDataPos = 0Himax Media Solutions Proprietary & Confidential 4
  5. 5. setData (buffer, len) buffer copy mDataCapacity = len mData mDataSize = len mDataPos = 0Himax Media Solutions Proprietary & Confidential 5
  6. 6. appendFrom (parcel, offset, len) offset len parcel mDataCapacity mData mDataSize mDataPosHimax Media Solutions Proprietary & Confidential 6
  7. 7. writeXXX (val)  writeInt32, writeInt64, writeFloat, writeDouble mDataCapacity mData val mDataPos = mDataSizeHimax Media Solutions Proprietary & Confidential 7
  8. 8. readXXX()  readInt32(), readInt64(), readFloat(), readDouble() return value mDataCapacity mData val mDataSize mDataPos += sizeof(TYPE)Himax Media Solutions Proprietary & Confidential 8
  9. 9. write (data, len) len data mDataCapacity mData mDataPos = mDataSizeHimax Media Solutions Proprietary & Confidential 9
  10. 10. read (outData, len) len outData mDataSize mData mDataPos += lenHimax Media Solutions Proprietary & Confidential 10
  11. 11. writeString8, writeString16 (str) len str mDataCapacity mData len str mDataPos = mDataSizeHimax Media Solutions Proprietary & Confidential 11
  12. 12. readString8(), readString16() len readInt32() str mDataSize mData len mDataPos += sizeof(len) + lenHimax Media Solutions Proprietary & Confidential 12
  13. 13. Object 的概念 flat_binder_object type flags binder cookie mData mObject [0] [1] [2] mObjectSize = 3 mObjectCapacity = 6Himax Media Solutions Proprietary & Confidential 13
  14. 14. writeObject(flat_binder_object, mullMetaData) flat_binder_object type flags binder cookie mDataCapacity mData mDataPos = mDataSize mObject [0] mObjectSize++Himax Media Solutions Proprietary & Confidential 14
  15. 15. writeFileDescriptor, writeXXXBinder flat_binder_object binder type flags cookie handle writeFileDescriptor TYPE_FD 0x17F fd 1 or 0 TYPE_HANDLE handle() NULL writeStrongBinder 0x17F getWeakRefs( TYPE_BINDER localBinder() ) WEAK_HANDLE handle() NULL writeWeakBinder 0x17F WEAK_BINDER get_refs() unsafe_get()Himax Media Solutions Proprietary & Confidential 15
  16. 16. readFileDescriptor, readXXXBinder flat_binder_object binder type flags cookie handle writeFileDescriptor TYPE_FD 0x17F fd 1 or 0 getStrongProxyForHandle TYPE_HANDLE handle() NULL writeStrongBinder 0x17F getWeakRefs( TYPE_BINDER IBinder ) localBinder() getWeakProxyForHandle WEAK_HANDLE handle() NULL writeWeakBinder 0x17F set_object_and_refs WEAK_BINDER get_refs() unsafe_get()Himax Media Solutions Proprietary & Confidential 16
  17. 17. writeBlob (len, outBlob) len < 40kb WritableBlob writeInt32(0) mapping mDataCapacity mData 0 mDataPos = mDataSizeHimax Media Solutions Proprietary & Confidential 17
  18. 18. readBlob (len, outBlob) len < 40kb ReadableBlob readInt32() mapping mDataSize mData 0 mDataPosHimax Media Solutions Proprietary & Confidential 18
  19. 19. Drive for better vision

×