andersca@apple.com | 4bcf0a0 | 2017-03-09 22:34:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #if ENABLE(APPLE_PAY) |
| 29 | |
drousso@apple.com | 69adf6c | 2021-02-19 17:38:37 +0000 | [diff] [blame] | 30 | #include "ApplePayDetailsUpdateBase.h" |
andersca@apple.com | 4bcf0a0 | 2017-03-09 22:34:52 +0000 | [diff] [blame] | 31 | #include "ApplePayError.h" |
andersca@apple.com | 4bcf0a0 | 2017-03-09 22:34:52 +0000 | [diff] [blame] | 32 | #include "ApplePayShippingMethod.h" |
drousso@apple.com | 69adf6c | 2021-02-19 17:38:37 +0000 | [diff] [blame] | 33 | #include <wtf/RefPtr.h> |
| 34 | #include <wtf/Vector.h> |
andersca@apple.com | 4bcf0a0 | 2017-03-09 22:34:52 +0000 | [diff] [blame] | 35 | |
| 36 | namespace WebCore { |
| 37 | |
drousso@apple.com | 69adf6c | 2021-02-19 17:38:37 +0000 | [diff] [blame] | 38 | struct ApplePayShippingContactUpdate final : public ApplePayDetailsUpdateBase { |
andersca@apple.com | 4bcf0a0 | 2017-03-09 22:34:52 +0000 | [diff] [blame] | 39 | Vector<RefPtr<ApplePayError>> errors; |
| 40 | |
| 41 | Vector<ApplePayShippingMethod> newShippingMethods; |
drousso@apple.com | 69adf6c | 2021-02-19 17:38:37 +0000 | [diff] [blame] | 42 | |
| 43 | template<class Encoder> void encode(Encoder&) const; |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 44 | template<class Decoder> static std::optional<ApplePayShippingContactUpdate> decode(Decoder&); |
andersca@apple.com | 4bcf0a0 | 2017-03-09 22:34:52 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
drousso@apple.com | 69adf6c | 2021-02-19 17:38:37 +0000 | [diff] [blame] | 47 | template<class Encoder> |
| 48 | void ApplePayShippingContactUpdate::encode(Encoder& encoder) const |
| 49 | { |
| 50 | ApplePayDetailsUpdateBase::encode(encoder); |
| 51 | encoder << errors; |
| 52 | encoder << newShippingMethods; |
andersca@apple.com | 4bcf0a0 | 2017-03-09 22:34:52 +0000 | [diff] [blame] | 53 | } |
| 54 | |
drousso@apple.com | 69adf6c | 2021-02-19 17:38:37 +0000 | [diff] [blame] | 55 | template<class Decoder> |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 56 | std::optional<ApplePayShippingContactUpdate> ApplePayShippingContactUpdate::decode(Decoder& decoder) |
drousso@apple.com | 69adf6c | 2021-02-19 17:38:37 +0000 | [diff] [blame] | 57 | { |
| 58 | ApplePayShippingContactUpdate result; |
| 59 | |
| 60 | if (!result.decodeBase(decoder)) |
darin@apple.com | 7c840b6 | 2021-05-28 01:26:23 +0000 | [diff] [blame] | 61 | return std::nullopt; |
drousso@apple.com | 69adf6c | 2021-02-19 17:38:37 +0000 | [diff] [blame] | 62 | |
| 63 | #define DECODE(name, type) \ |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 64 | std::optional<type> name; \ |
drousso@apple.com | 69adf6c | 2021-02-19 17:38:37 +0000 | [diff] [blame] | 65 | decoder >> name; \ |
| 66 | if (!name) \ |
darin@apple.com | 7c840b6 | 2021-05-28 01:26:23 +0000 | [diff] [blame] | 67 | return std::nullopt; \ |
drousso@apple.com | 69adf6c | 2021-02-19 17:38:37 +0000 | [diff] [blame] | 68 | result.name = WTFMove(*name); \ |
| 69 | |
| 70 | DECODE(errors, Vector<RefPtr<ApplePayError>>) |
| 71 | DECODE(newShippingMethods, Vector<ApplePayShippingMethod>) |
| 72 | |
| 73 | #undef DECODE |
| 74 | |
| 75 | return result; |
| 76 | } |
| 77 | |
| 78 | } // namespace WebCore |
| 79 | |
andersca@apple.com | 4bcf0a0 | 2017-03-09 22:34:52 +0000 | [diff] [blame] | 80 | #endif |