1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
11 Parcel
::Parcel() : data_position_(0), data_(), objects_() {}
15 void Parcel
::WriteInterfaceToken(const std
::string
& str
) {
19 void Parcel
::WriteUTF8(const std
::string
& str
) {
20 data_
.insert(data_
.end(), str
.begin(), str
.end());
23 void Parcel
::WriteUInt32(uint32_t ui32
) {
24 data_
.push_back((ui32
>> 24) & 0xff);
25 data_
.push_back((ui32
>> 16) & 0xff);
26 data_
.push_back((ui32
>> 8) & 0xff);
27 data_
.push_back((ui32
>> 0) & 0xff);
30 bool Parcel
::ReadUInt32(uint32_t* ui32
) {
31 return ReadBytes(sizeof(*ui32
), ui32
);
34 bool Parcel
::ReadBytes(size_t count
, void* buffer
) {
36 ALOG("count=%d, data_position_=%d, datasize=%d", count
, data_position_
, DataSize());
37 if (count
+ data_position_
>= DataSize())
40 memcpy(buffer
, &data_
[data_position_
], count
);
41 data_position_
+= count
;
45 binder_uintptr_t Parcel
::DataPointer() const {
46 return reinterpret_cast<binder_uintptr_t
>(&data_
[0]);
49 size_t Parcel
::DataSize() const {
53 void Parcel
::SetDataSize(size_t size
) {
54 // TODO: handle object lifetimes
59 void Parcel
::SetDataPosition(size_t pos
) {
60 CHECK(pos
< DataSize());
64 size_t Parcel
::DataPosition() const {
65 return data_position_
;
68 void Parcel
::Print() const {
69 for (size_t i
= 0; i
< data_
.size(); i
+= 4) {
70 ALOG("%0x %0x %0x %0x", data_
[i
], data_
[i
+1], data_
[i
+2], data_
[i
+3]);
74 } // namespace minibind