summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Montag <pmontag@iseeme.com>2018-11-07 08:21:00 -0600
committerPaul Montag <pmontag@iseeme.com>2018-11-07 08:21:00 -0600
commitbc10d22b451bd5ecfdc2d06dc12c1c7d94adb2d2 (patch)
tree9fcc9363a0145caf0c3348e92c27ea5bf7908275
parenta90e8ab8a5ab8b8bb484c51df7c29e721f31e184 (diff)
Fixed nil encoding
-rw-r--r--template_impl.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/template_impl.go b/template_impl.go
index 174e893..001b2d9 100644
--- a/template_impl.go
+++ b/template_impl.go
@@ -124,9 +124,12 @@ func (t *FpdfTpl) GobEncode() ([]byte, error) {
}
if _, ok := childrenImgs[key]; ok {
- err = encoder.Encode(nil)
+ err = encoder.Encode("p")
} else {
- err = encoder.Encode(img)
+ err = encoder.Encode("o")
+ if err == nil {
+ err = encoder.Encode(img)
+ }
}
}
if err == nil {
@@ -161,30 +164,37 @@ func (t *FpdfTpl) GobDecode(buf []byte) error {
if err == nil {
err = decoder.Decode(&numImgs)
}
+
t.images = make(map[string]*ImageInfoType)
childrenImgs := t.childrenImages()
for x := 0; x < numImgs; x++ {
var key string
- var img *ImageInfoType
+ var tpe string
if err == nil {
err = decoder.Decode(&key)
}
if err == nil {
- err = decoder.Decode(&img)
+ err = decoder.Decode(&tpe)
}
if err == nil {
- if img != nil {
- t.images[key] = img
- } else {
+ switch tpe {
+ case "p":
if _, ok := childrenImgs[key]; !ok {
err = fmt.Errorf("Encoded template is corrupt, could not find image %s", key)
} else {
t.images[key] = childrenImgs[key]
}
+ case "o":
+ var img *ImageInfoType
+ err = decoder.Decode(&img)
+
+ if err == nil {
+ t.images[key] = img
+ }
}
}
}