summaryrefslogtreecommitdiff
path: root/template_impl.go
diff options
context:
space:
mode:
authorPaul Montag <pmontag@iseeme.com>2018-11-07 08:51:37 -0600
committerPaul Montag <pmontag@iseeme.com>2018-11-07 08:51:37 -0600
commit01381ea7603b12304064fcd01a49b1cc4434b4ca (patch)
tree386c29e73ec1d2d34633f6d76971e168f9bcbdb5 /template_impl.go
parentbc10d22b451bd5ecfdc2d06dc12c1c7d94adb2d2 (diff)
Created helper functions for serialiation
Diffstat (limited to 'template_impl.go')
-rw-r--r--template_impl.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/template_impl.go b/template_impl.go
index 001b2d9..9c690c1 100644
--- a/template_impl.go
+++ b/template_impl.go
@@ -86,6 +86,23 @@ func (t *FpdfTpl) Templates() []Template {
return t.templates
}
+// Turn a template into a byte string for later deserialization
+func (t *FpdfTpl) Serialize() ([]byte, error) {
+ b := new(bytes.Buffer)
+ enc := gob.NewEncoder(b)
+ err := enc.Encode(t)
+
+ return b.Bytes(), err
+}
+
+// Create a template from a previously serialized template
+func DeserializeTemplate(b []byte) (Template, error) {
+ tpl := new(FpdfTpl)
+ dec := gob.NewDecoder(bytes.NewBuffer(b))
+ err := dec.Decode(tpl)
+ return tpl, err
+}
+
// returns the next layer of children images, it doesn't dig into
// children of children. Applies template namespace to keys to ensure
// no collisions. See UseTemplateScaled