From 4aa3e39d7df093a5fa41cef76b6aeac61e37d504 Mon Sep 17 00:00:00 2001
From: Markus Birth <mbirth@gmail.com>
Date: Thu, 18 Oct 2018 00:57:30 +0200
Subject: [PATCH] Small optimisations.

---
 grmn/gcd.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/grmn/gcd.py b/grmn/gcd.py
index 8fbb4a6..875ddff 100644
--- a/grmn/gcd.py
+++ b/grmn/gcd.py
@@ -12,6 +12,9 @@ DEFAULT_ALIGN = 0x1000    # second padding block pads until 0x1000
 # first 0x1000 Bytes: GCD_SIG > 0x0001 > 0x0002 > 0x0003 > 0x0005 > 0x0001 > 0x0002
 # then: 0x0001 > ( 0x0006 > 0x0007 > 0x???? > 0x0001 ... ) > 0xffff
 
+class ParseException(Exception):
+    pass
+
 class Gcd:
     def __init__(self, filename: str=None):
         self.filename = filename
@@ -26,12 +29,12 @@ class Gcd:
         with open(self.filename, "rb") as f:
             sig = f.read(8)
             if sig != GCD_SIG:
-                raise Exception("Signature mismatch ({}, should be {})!".format(repr(sig), repr(GCD_SIG)))
+                raise ParseException("Signature mismatch ({}, should be {})!".format(repr(sig), repr(GCD_SIG)))
             while True:
                 cur_offset = f.tell()
                 header = f.read(4)
                 tlv = TLV.factory(header, offset=cur_offset)
-                self.struct.append(tlv)
+                self.add_tlv(tlv)
                 if tlv.type_id == 0xFFFF:
                     # End of file reached
                     break
@@ -44,7 +47,13 @@ class Gcd:
                     tlv.set_tlv6(last_tlv6)
             f.close()
 
+    def add_tlv(self, new_tlv: TLV):
+        self.struct.append(new_tlv)
+
     def print_struct(self):
+        """
+        Prints the structure of the parsed GCD file
+        """
         last_tlv = 0xffff
         tlv_count = 0
         tlv_length = 0