File indexing completed on 2024-12-29 04:51:05
0001 /* 0002 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 function readTime(stream) 0007 { 0008 let timeStream = stream.readSubMessage(); 0009 return new Date(timeStream.readVarintField()); 0010 } 0011 0012 // see https://community.kde.org/KDE_PIM/KItinerary/SBB_Barcode 0013 function parseQrCode(content) { 0014 let res = JsonLd.newTrainReservation(); 0015 res.reservedTicket.ticketToken = 'qrcodebin:' + ByteArray.toBase64(content); 0016 res.reservationFor.provider.identifier = 'uic:1085'; 0017 let top = ByteArray.toProtobufStreamReader(content); 0018 while (!top.atEnd()) { 0019 switch (top.fieldNumber()) { 0020 case 1: 0021 let level1 = top.readSubMessage(); 0022 while (!level1.atEnd()) { 0023 switch (level1.fieldNumber()) { 0024 case 1: 0025 res.reservationNumber = level1.readVarintField() + ""; 0026 break; 0027 case 2: 0028 let tripData = level1.readSubMessage(); 0029 while (!tripData.atEnd()) { 0030 switch (tripData.fieldNumber()) { 0031 case 1: 0032 let ticketNameData = tripData.readSubMessage(); 0033 while (!ticketNameData.atEnd()) { 0034 switch (ticketNameData.fieldNumber()) { 0035 case 2: 0036 res.reservedTicket.name = ticketNameData.readString(); 0037 break; 0038 default: 0039 ticketNameData.skip(); 0040 } 0041 } 0042 break; 0043 case 2: 0044 res.reservationFor.departureStation.name = tripData.readString(); 0045 break; 0046 case 3: 0047 res.reservationFor.arrivalStation.name = tripData.readString(); 0048 break; 0049 case 4: 0050 res.reservedTicket.ticketedSeat.seatingType = tripData.readVarintField() + ""; 0051 case 8: 0052 res.reservationFor.departureTime = readTime(tripData); 0053 break; 0054 case 9: 0055 res.reservationFor.arrivalTime = readTime(tripData); 0056 break; 0057 default: 0058 tripData.skip(); 0059 } 0060 } 0061 break; 0062 case 3: 0063 let travelerData = level1.readSubMessage(); 0064 while (!travelerData.atEnd()) { 0065 switch (travelerData.fieldNumber()) { 0066 case 3: 0067 res.underName.givenName = travelerData.readString(); 0068 break; 0069 case 4: 0070 res.underName.familyName = travelerData.readString(); 0071 break; 0072 case 7: 0073 res.programMembershipUsed.programName = travelerData.readString(); 0074 default: 0075 travelerData.skip(); 0076 } 0077 } 0078 break; 0079 case 6: 0080 let paymentData = level1.readSubMessage(); 0081 while (!paymentData.atEnd()) { 0082 switch (paymentData.fieldNumber()) { 0083 case 2: 0084 res.priceCurrency = paymentData.readString(); 0085 break; 0086 case 3: 0087 res.totalPrice = paymentData.readString(); 0088 break; 0089 default: 0090 paymentData.skip(); 0091 } 0092 } 0093 case 8: 0094 let trainData = level1.readSubMessage(); 0095 while (!trainData.atEnd()) { 0096 switch (trainData.fieldNumber()) { 0097 case 11: 0098 if (res.reservationFor.trainNumber) 0099 res.reservationFor.trainNumber += ', ' 0100 else 0101 res.reservationFor.trainNumber = '' 0102 res.reservationFor.trainNumber += trainData.readString(); 0103 break; 0104 default: 0105 trainData.skip(); 0106 } 0107 } 0108 break; 0109 default: 0110 level1.skip(); 0111 } 0112 } 0113 break; 0114 default: 0115 top.skip(); 0116 } 0117 } 0118 0119 // convert unbound tickets 0120 if (!res.reservationFor.trainNumber) { 0121 res.reservedTicket.validFrom = res.reservationFor.departureTime; 0122 res.reservedTicket.validUntil = res.reservationFor.arrivalTime; 0123 res.reservationFor.departureDay = res.reservationFor.departureTime; 0124 res.reservationFor.departureTime = undefined; 0125 res.reservationFor.arrivalTime = undefined; 0126 } 0127 0128 // convert unbound passes to a Ticket 0129 if (!res.reservationFor.departureStation.name) { 0130 res.reservedTicket.underName = res.underName; 0131 res.reservedTicket.ticketNumber = res.reservationNumber; 0132 return res.reservedTicket; 0133 } 0134 0135 return res; 0136 }