diff options
Diffstat (limited to 'template_impl.go')
-rw-r--r-- | template_impl.go | 17 |
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 |