/boarding-pass

Primary LanguageGoMIT LicenseMIT

boarding-pass

GitHub Workflow Status Codecov Go Report Card Go Reference FOSSA Status

boarding-pass is a partial Go port of georgesmith64/bcbp with some inspiration from martinmroz/iata_bcbp.

The main difference between the libraries is that boarding-pass only offers users the ability to decode the data in a Bar Coded Boarding Pass into structured data.

From an implementation perspective, georgesmith64/bcbp is written in JavaScript and thus has the flexibility to create the structured data on the fly. martinmroz/iata_bcbp is written in Rust and uses impl to expose the data through method calls. boarding-pass aims to build the BCBP struct on the fly as efficiently as possible and return that to the caller.

boarding-pass supports up to version 8 of the IATA Resolution 792 spec. Although, both georgesmith64/bcbp and martinmroz/iata_bcbp support up to version 6, information on version 7 and 8 were gleaned from this issue.

Installation

go get github.com/jandauz/boarding-pass

Getting started

package main

import (
	"fmt"

	"github.com/jandauz/boarding-pass"
)

func main() {
	const s = "M1DESMARAIS/LUC       EABC123 YULFRAAC 0834 326J001A0025 100"
	b, err := bcbp.FromStr(s)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("Format Code:", b.FormatCode)
	fmt.Println("NumberOfLegsEncoded:", b.NumberOfLegsEncoded)
	fmt.Println("PassengerName:", b.PassengerName)
	fmt.Println("ElectronicTicketIndicator:", b.ElectronicTicketIndicator)
	fmt.Println("OperatingCarrierPNRCode:", b.Legs[0].OperatingCarrierPNRCode)
	fmt.Println("FromCityAirportCode:", b.Legs[0].FromCityAirportCode)
	fmt.Println("ToCityAirportCode:", b.Legs[0].ToCityAirportCode)
	fmt.Println("OperatingCarrierDesignator:", b.Legs[0].OperatingCarrierDesignator)
	fmt.Println("FlightNumber:", b.Legs[0].FlightNumber)
	fmt.Println("DateOfFlight:", b.Legs[0].DateOfFlight)
	fmt.Println("CompartmentCode:", b.Legs[0].CompartmentCode)
	fmt.Println("SeatNumber:", b.Legs[0].SeatNumber)
	fmt.Println("CheckInSequenceNumber:", b.Legs[0].CheckInSequenceNumber)
	fmt.Println("PassengerStatus:", b.Legs[0].PassengerStatus)
	// Output:
	// Format Code: M
	// NumberOfLegsEncoded: 1
	// PassengerName: DESMARAIS/LUC
	// ElectronicTicketIndicator: E
	// OperatingCarrierPNRCode: ABC123
	// FromCityAirportCode: YUL
	// ToCityAirportCode: FRA
	// OperatingCarrierDesignator: AC
	// FlightNumber: 0834
	// DateOfFlight: 2021-11-22
	// CompartmentCode: J
	// SeatNumber: 001A
	// CheckInSequenceNumber: 0025
	// PassengerStatus: 1
}

Notes

boarding-pass currently does not attempt to interpret the data except forNumberOfLegsEncoded, DateOfFlight, and DateOfBoardingPassIssuance.

NumberOfLegsEncoded is a uint. This is necessary for determing how many Legs to process.

Both DateOfFlight and DateOfBoardingPassIssuance are strings formatted using RFC 3339 full-date format. There is currently no attempt to determine if the values are realistic dates e.g. an unrealistic date would be on that is far ahead in the future.

Benchmark

goos: windows
goarch: amd64
pkg: github.com/jandauz/boarding-pass
cpu: AMD Ryzen 5 3600 6-Core Processor
BenchmarkFromStr_Mandatory_No_Security_Single
BenchmarkFromStr_Mandatory_No_Security_Single-12    	  350959	      3261 ns/op	      16 B/op	       1 allocs/op
BenchmarkFromStr_Mandatory_Single
BenchmarkFromStr_Mandatory_Single-12                	  226207	      5299 ns/op	      16 B/op	       1 allocs/op
BenchmarkFromStr_Full_No_Security_Single
BenchmarkFromStr_Full_No_Security_Single-12         	  148012	      8169 ns/op	      16 B/op	       1 allocs/op
BenchmarkFromStr_Full_Single
BenchmarkFromStr_Full_Single-12                     	  116398	     10138 ns/op	      16 B/op	       1 allocs/op
BenchmarkFromStr_Full_No_Security_Multi
BenchmarkFromStr_Full_No_Security_Multi-12          	   94401	     12638 ns/op	      16 B/op	       1 allocs/op
BenchmarkFromStr_Full_Multi
BenchmarkFromStr_Full_Multi-12                      	   81558	     14758 ns/op	      16 B/op	       1 allocs/op
PASS

License

FOSSA Status