func ReadRide(filename string) *Ride { encodedBits, err := ioutil.ReadFile(filename) bitsWithoutChecksum := encodedBits[:len(encodedBits)-4] if err != nil { panic(err) } z := rle.NewReader(bytes.NewReader(bitsWithoutChecksum)) if err != nil { panic(err) } var bitbuffer bytes.Buffer bitbuffer.ReadFrom(z) decrypted := bitbuffer.Bytes() // r is a pointer r := new(Ride) Unmarshal(decrypted, r) if DEBUG { begin := 0xa2 + 2*len(r.TrackData.Elements) - 3 for i := begin; i < begin+DEBUG_LENGTH; i++ { // encode the value of i as hex if i > len(decrypted) { continue } ds := hex.EncodeToString([]byte{byte(i)}) bitValueInHex := hex.EncodeToString([]byte{decrypted[i]}) fmt.Printf("%s: %s\n", ds, bitValueInHex) } } return r }
func readRaptor() Ride { encodedBits, err := ioutil.ReadFile("rides/raptor.td4") if err != nil { panic(err) } z := rle.NewReader(bytes.NewReader(encodedBits)) if err != nil { panic(err) } var bitbuffer bytes.Buffer bitbuffer.ReadFrom(z) decrypted := bitbuffer.Bytes() for i := 0; i < 40; i++ { // encode the value of i as hex ds := hex.EncodeToString([]byte{byte(i)}) bitValueInHex := hex.EncodeToString([]byte{decrypted[i]}) fmt.Printf("%s: %s\n", ds, bitValueInHex) } // r is a pointer r := new(Ride) Unmarshal(decrypted, r) bits, err := Marshal(r) fmt.Println(bits) return *r }
func main() { filename := flag.String("filename", "", "td6 file to decode") flag.Parse() if *filename == "" { log.Fatal("please enter a filename") } f, err := os.Open(*filename) if err != nil { log.Fatal(err) } reader := rle.NewReader(f) // xxx is there a better way to do this? rr := io.TeeReader(reader, os.Stdout) var bitbuffer bytes.Buffer bitbuffer.ReadFrom(rr) }