Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2020 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 | |
| 17 | #include <ui/DeviceProductInfo.h> |
| 18 | |
| 19 | #include <ui/FlattenableHelpers.h> |
| 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | size_t DeviceProductInfo::getFlattenedSize() const { |
| 24 | return FlattenableHelpers::getFlattenedSize(name) + sizeof(manufacturerPnpId) + |
| 25 | FlattenableHelpers::getFlattenedSize(productId) + sizeof(manufactureOrModelDate); |
| 26 | } |
| 27 | |
| 28 | status_t DeviceProductInfo::flatten(void* buffer, size_t size) const { |
| 29 | if (size < getFlattenedSize()) { |
| 30 | return NO_MEMORY; |
| 31 | } |
| 32 | FlattenableHelpers::write(buffer, size, name); |
| 33 | FlattenableUtils::write(buffer, size, manufacturerPnpId); |
| 34 | FlattenableHelpers::write(buffer, size, productId); |
| 35 | FlattenableUtils::write(buffer, size, manufactureOrModelDate); |
| 36 | return NO_ERROR; |
| 37 | } |
| 38 | |
| 39 | status_t DeviceProductInfo::unflatten(void const* buffer, size_t size) { |
| 40 | if (size < getFlattenedSize()) { |
| 41 | return NO_MEMORY; |
| 42 | } |
| 43 | FlattenableHelpers::read(buffer, size, &name); |
| 44 | FlattenableUtils::read(buffer, size, manufacturerPnpId); |
| 45 | FlattenableHelpers::read(buffer, size, &productId); |
| 46 | FlattenableUtils::read(buffer, size, manufactureOrModelDate); |
| 47 | return NO_ERROR; |
| 48 | } |
| 49 | |
| 50 | } // namespace android |