'Decode Polyline with T-SQL

I'm using the Valhalla routing engine and want to decode the route shape within T-SQL and store it as a geography line object.

The decoding is documented here https://valhalla.readthedocs.io/en/latest/decoding/

My problems in T-SQL are the byte shifts, has anyone an idea how to implement this within T-SQL?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source