From 6c25964c0165530e7db6650eea79cbac99031353 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sat, 2 Jul 2022 00:16:02 +0200 Subject: gtfs realtime proof of concept this adds a package for protobuf stuff, generated via hprotoc. Seems to work kinda fine? (the generated API is horrible though, will have to write some wrappers for that) --- .../Realtime/VehiclePosition/CongestionLevel.hs | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 gtfs/GTFS/Realtime/VehiclePosition/CongestionLevel.hs (limited to 'gtfs/GTFS/Realtime/VehiclePosition/CongestionLevel.hs') diff --git a/gtfs/GTFS/Realtime/VehiclePosition/CongestionLevel.hs b/gtfs/GTFS/Realtime/VehiclePosition/CongestionLevel.hs new file mode 100644 index 0000000..4f84eac --- /dev/null +++ b/gtfs/GTFS/Realtime/VehiclePosition/CongestionLevel.hs @@ -0,0 +1,85 @@ +{-# LANGUAGE BangPatterns, DataKinds, DeriveDataTypeable, DeriveGeneric, FlexibleInstances, MultiParamTypeClasses, OverloadedStrings + #-} +{-# OPTIONS_GHC -w #-} +module GTFS.Realtime.VehiclePosition.CongestionLevel (CongestionLevel(..)) where +import Prelude ((+), (/), (.)) +import qualified Prelude as Prelude' +import qualified Data.List as Prelude' +import qualified Data.Typeable as Prelude' +import qualified GHC.Generics as Prelude' +import qualified Data.Data as Prelude' +import qualified Text.ProtocolBuffers.Header as P' + +data CongestionLevel = UNKNOWN_CONGESTION_LEVEL + | RUNNING_SMOOTHLY + | STOP_AND_GO + | CONGESTION + | SEVERE_CONGESTION + deriving (Prelude'.Read, Prelude'.Show, Prelude'.Eq, Prelude'.Ord, Prelude'.Typeable, Prelude'.Data, + Prelude'.Generic) + +instance P'.Mergeable CongestionLevel + +instance Prelude'.Bounded CongestionLevel where + minBound = UNKNOWN_CONGESTION_LEVEL + maxBound = SEVERE_CONGESTION + +instance P'.Default CongestionLevel where + defaultValue = UNKNOWN_CONGESTION_LEVEL + +toMaybe'Enum :: Prelude'.Int -> P'.Maybe CongestionLevel +toMaybe'Enum 0 = Prelude'.Just UNKNOWN_CONGESTION_LEVEL +toMaybe'Enum 1 = Prelude'.Just RUNNING_SMOOTHLY +toMaybe'Enum 2 = Prelude'.Just STOP_AND_GO +toMaybe'Enum 3 = Prelude'.Just CONGESTION +toMaybe'Enum 4 = Prelude'.Just SEVERE_CONGESTION +toMaybe'Enum _ = Prelude'.Nothing + +instance Prelude'.Enum CongestionLevel where + fromEnum UNKNOWN_CONGESTION_LEVEL = 0 + fromEnum RUNNING_SMOOTHLY = 1 + fromEnum STOP_AND_GO = 2 + fromEnum CONGESTION = 3 + fromEnum SEVERE_CONGESTION = 4 + toEnum + = P'.fromMaybe (Prelude'.error "hprotoc generated code: toEnum failure for type GTFS.Realtime.VehiclePosition.CongestionLevel") . + toMaybe'Enum + succ UNKNOWN_CONGESTION_LEVEL = RUNNING_SMOOTHLY + succ RUNNING_SMOOTHLY = STOP_AND_GO + succ STOP_AND_GO = CONGESTION + succ CONGESTION = SEVERE_CONGESTION + succ _ = Prelude'.error "hprotoc generated code: succ failure for type GTFS.Realtime.VehiclePosition.CongestionLevel" + pred RUNNING_SMOOTHLY = UNKNOWN_CONGESTION_LEVEL + pred STOP_AND_GO = RUNNING_SMOOTHLY + pred CONGESTION = STOP_AND_GO + pred SEVERE_CONGESTION = CONGESTION + pred _ = Prelude'.error "hprotoc generated code: pred failure for type GTFS.Realtime.VehiclePosition.CongestionLevel" + +instance P'.Wire CongestionLevel where + wireSize ft' enum = P'.wireSize ft' (Prelude'.fromEnum enum) + wirePut ft' enum = P'.wirePut ft' (Prelude'.fromEnum enum) + wireGet 14 = P'.wireGetEnum toMaybe'Enum + wireGet ft' = P'.wireGetErr ft' + wireGetPacked 14 = P'.wireGetPackedEnum toMaybe'Enum + wireGetPacked ft' = P'.wireGetErr ft' + +instance P'.GPB CongestionLevel + +instance P'.MessageAPI msg' (msg' -> CongestionLevel) CongestionLevel where + getVal m' f' = f' m' + +instance P'.ReflectEnum CongestionLevel where + reflectEnum + = [(0, "UNKNOWN_CONGESTION_LEVEL", UNKNOWN_CONGESTION_LEVEL), (1, "RUNNING_SMOOTHLY", RUNNING_SMOOTHLY), + (2, "STOP_AND_GO", STOP_AND_GO), (3, "CONGESTION", CONGESTION), (4, "SEVERE_CONGESTION", SEVERE_CONGESTION)] + reflectEnumInfo _ + = P'.EnumInfo + (P'.makePNF (P'.pack ".transit_realtime.VehiclePosition.CongestionLevel") [] ["GTFS", "Realtime", "VehiclePosition"] + "CongestionLevel") + ["GTFS", "Realtime", "VehiclePosition", "CongestionLevel.hs"] + [(0, "UNKNOWN_CONGESTION_LEVEL"), (1, "RUNNING_SMOOTHLY"), (2, "STOP_AND_GO"), (3, "CONGESTION"), (4, "SEVERE_CONGESTION")] + Prelude'.False + +instance P'.TextType CongestionLevel where + tellT = P'.tellShow + getT = P'.getRead \ No newline at end of file -- cgit v1.2.3