From bc10d22b451bd5ecfdc2d06dc12c1c7d94adb2d2 Mon Sep 17 00:00:00 2001 From: Paul Montag Date: Wed, 7 Nov 2018 08:21:00 -0600 Subject: Fixed nil encoding --- template_impl.go | 24 +++++++++++++++++------- 1 file 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 + } } } } -- cgit v1.2.1-24-ge1ad