From cfa573e7cfb1a09a9a23c728c16a9f3da7923672 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 27 Nov 2017 11:16:29 +0000 Subject: [PATCH] Ensure Model can be encoded<->decoded into CORK --- sql/cork.go | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/sql/cork.go b/sql/cork.go index 406daee8..79f85b40 100644 --- a/sql/cork.go +++ b/sql/cork.go @@ -556,6 +556,38 @@ func (this *ContentExpression) UnmarshalCORK(r *cork.Reader) (err error) { // ################################################## // ################################################## +// -------------------------------------------------- +// Model +// -------------------------------------------------- + +func init() { + cork.Register(&Model{}) +} + +func (this *Model) ExtendCORK() byte { + return 0x51 +} + +func (this *Model) MarshalCORK(w *cork.Writer) (err error) { + w.EncodeString(this.TB) + w.EncodeFloat64(this.MIN) + w.EncodeFloat64(this.INC) + w.EncodeFloat64(this.MAX) + return +} + +func (this *Model) UnmarshalCORK(r *cork.Reader) (err error) { + r.DecodeString(&this.TB) + r.DecodeFloat64(&this.MIN) + r.DecodeFloat64(&this.INC) + r.DecodeFloat64(&this.MAX) + return +} + +func (this Model) MarshalText() (data []byte, err error) { + return []byte(this.String()), err +} + // -------------------------------------------------- // Param // -------------------------------------------------- @@ -565,7 +597,7 @@ func init() { } func (this *Param) ExtendCORK() byte { - return 0x51 + return 0x52 } func (this *Param) MarshalCORK(w *cork.Writer) (err error) { @@ -591,7 +623,7 @@ func init() { } func (this *Value) ExtendCORK() byte { - return 0x52 + return 0x53 } func (this *Value) MarshalCORK(w *cork.Writer) (err error) { @@ -617,7 +649,7 @@ func init() { } func (this *Ident) ExtendCORK() byte { - return 0x53 + return 0x54 } func (this *Ident) MarshalCORK(w *cork.Writer) (err error) { @@ -643,7 +675,7 @@ func init() { } func (this *Table) ExtendCORK() byte { - return 0x54 + return 0x55 } func (this *Table) MarshalCORK(w *cork.Writer) (err error) { @@ -669,7 +701,7 @@ func init() { } func (this *Batch) ExtendCORK() byte { - return 0x55 + return 0x56 } func (this *Batch) MarshalCORK(w *cork.Writer) (err error) { @@ -699,7 +731,7 @@ func (this Thing) Bytes() []byte { } func (this *Thing) ExtendCORK() byte { - return 0x56 + return 0x57 } func (this *Thing) MarshalCORK(w *cork.Writer) (err error) { @@ -727,7 +759,7 @@ func init() { } func (this *Point) ExtendCORK() byte { - return 0x57 + return 0x58 } func (this *Point) MarshalCORK(w *cork.Writer) (err error) { @@ -759,7 +791,7 @@ func init() { } func (this *Circle) ExtendCORK() byte { - return 0x58 + return 0x59 } func (this *Circle) MarshalCORK(w *cork.Writer) (err error) { @@ -791,7 +823,7 @@ func init() { } func (this *Polygon) ExtendCORK() byte { - return 0x59 + return 0x60 } func (this *Polygon) MarshalCORK(w *cork.Writer) (err error) {