Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
SvDebitLogRecordAdapter.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
14
15/* Keyple Core Util */
16#include "ByteArrayUtil.h"
17#include "KeypleStd.h"
18#include "System.h"
19
20namespace keyple {
21namespace card {
22namespace calypso {
23
24using namespace keyple::core::util;
25using namespace keyple::core::util::cpp;
26
28 const std::vector<uint8_t>& cardResponse, const int offset)
29: mOffset(offset), mCardResponse(cardResponse) {}
30
31const std::vector<uint8_t>& SvDebitLogRecordAdapter::getRawData() const
32{
33 return mCardResponse;
34}
35
37{
38 return ByteArrayUtil::twoBytesSignedToInt(mCardResponse, mOffset);
39}
40
42{
43 return ByteArrayUtil::threeBytesSignedToInt(mCardResponse, mOffset + 14);
44}
45
46const std::vector<uint8_t> SvDebitLogRecordAdapter::getDebitTime() const
47{
48 std::vector<uint8_t> loadTime(2);
49 loadTime[0] = mCardResponse[mOffset + 4];
50 loadTime[1] = mCardResponse[mOffset + 5];
51
52 return loadTime;
53}
54
55const std::vector<uint8_t> SvDebitLogRecordAdapter::getDebitDate() const
56{
57 std::vector<uint8_t> loadDate(2);
58 loadDate[0] = mCardResponse[mOffset + 2];
59 loadDate[1] = mCardResponse[mOffset + 3];
60
61 return loadDate;
62}
63
65{
66 return mCardResponse[mOffset + 6];
67}
68
69const std::vector<uint8_t> SvDebitLogRecordAdapter::getSamId() const
70{
71 std::vector<uint8_t> samId(4);
72 System::arraycopy(mCardResponse, mOffset + 7, samId, 0, 4);
73
74 return samId;
75}
76
78{
79 std::vector<uint8_t> tnNum(2);
80 tnNum[0] = mCardResponse[mOffset + 17];
81 tnNum[1] = mCardResponse[mOffset + 18];
82
83 return ByteArrayUtil::twoBytesToInt(tnNum, 0);
84}
85
87{
88 std::vector<uint8_t> samTNum(3);
89 System::arraycopy(mCardResponse, mOffset + 11, samTNum, 0, 3);
90
91 return ByteArrayUtil::threeBytesToInt(samTNum, 0);
92}
93
94std::ostream& operator<<(std::ostream& os, const SvDebitLogRecordAdapter& ra)
95{
96 os << "SV_DEBIT_LOG_RECORD_ADAPTER: {"
97 << "AMOUNT: " << ra.getAmount() << ", "
98 << "BALANCE: " << ra.getBalance() << ", "
99 << "DEBIT_DATE:" << ra.getDebitDate() << ", "
100 << "LOAD_TIME:" << ra.getDebitDate() << ", "
101 << "KVC: " << ra.getKvc() << ", "
102 << "SAM_ID: " << ra.getSamId() << ", "
103 << "SV_TRANSACTION_NUMBER: " << ra.getSvTNum() << ", "
104 << "SV_SAM_TRANSACTION_NUMBER: " << ra.getSamTNum()
105 << "}";
106
107 return os;
108}
109
110std::ostream& operator<<(std::ostream& os, const std::shared_ptr<SvDebitLogRecordAdapter> ra)
111{
112 if (ra == nullptr) {
113 os << "SV_DEBIT_LOG_RECORD_ADAPTER: null";
114 } else {
115 os << *ra.get();
116 }
117
118 return os;
119}
120
122{
123 return "{" \
124 "\"amount\":" + std::to_string(getAmount()) + ", " \
125 "\"balance\":" + std::to_string(getBalance()) + ", " \
126 "\"debitDate\":" + ByteArrayUtil::toHex(getDebitDate()) + ", " \
127 "\"loadTime\":" + ByteArrayUtil::toHex(getDebitDate()) + ", " \
128 "\"kvc\":" + std::to_string(getKvc()) + ", " \
129 "\"samId\": \"" + ByteArrayUtil::toHex(getSamId()) + "\", " \
130 "\"svTransactionNumber\":" + std::to_string(getSvTNum()) + ", " \
131 "\"svSamTransactionNumber\":" + std::to_string(getSamTNum()) + "" \
132 "}";
133}
134
135}
136}
137}
const std::vector< uint8_t > & getRawData() const override
SvDebitLogRecordAdapter(const std::vector< uint8_t > &cardResponse, const int offset)
const std::vector< uint8_t > getDebitDate() const override
const std::vector< uint8_t > getSamId() const override
const std::vector< uint8_t > getDebitTime() const override
std::ostream & operator<<(std::ostream &os, const std::shared_ptr< ApduRequestAdapter > ara)