2016-09-06 11:41:03 +00:00
|
|
|
// Copyright © 2016 Abcum Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package pack
|
|
|
|
|
|
|
|
import (
|
2016-09-19 11:02:10 +00:00
|
|
|
"bytes"
|
|
|
|
"encoding/gob"
|
2016-10-01 23:17:19 +00:00
|
|
|
"github.com/abcum/cork"
|
2016-09-06 11:41:03 +00:00
|
|
|
"github.com/abcum/surreal/sql"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-09-14 21:25:18 +00:00
|
|
|
|
2016-09-19 11:02:10 +00:00
|
|
|
gob.Register(sql.Null{})
|
|
|
|
gob.Register(sql.Void{})
|
|
|
|
gob.Register(sql.Empty{})
|
|
|
|
gob.Register(sql.Field{})
|
|
|
|
gob.Register(sql.Group{})
|
|
|
|
gob.Register(sql.Order{})
|
|
|
|
gob.Register(sql.Ident{})
|
|
|
|
gob.Register(sql.Table{})
|
|
|
|
gob.Register(sql.Thing{})
|
|
|
|
gob.Register(sql.DiffExpression{})
|
|
|
|
gob.Register(sql.MergeExpression{})
|
|
|
|
gob.Register(sql.ContentExpression{})
|
|
|
|
gob.Register(sql.SelectStatement{})
|
|
|
|
gob.Register(sql.CreateStatement{})
|
|
|
|
gob.Register(sql.UpdateStatement{})
|
|
|
|
gob.Register(sql.ModifyStatement{})
|
|
|
|
gob.Register(sql.DeleteStatement{})
|
|
|
|
gob.Register(sql.RelateStatement{})
|
|
|
|
gob.Register(sql.DefineViewStatement{})
|
|
|
|
gob.Register(sql.DefineTableStatement{})
|
|
|
|
gob.Register(sql.DefineRulesStatement{})
|
|
|
|
gob.Register(sql.DefineFieldStatement{})
|
|
|
|
gob.Register(sql.DefineIndexStatement{})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode encodes a data object into a GOB.
|
|
|
|
func Encode(src interface{}) (dst []byte) {
|
|
|
|
buf := bytes.NewBuffer(nil)
|
2016-10-01 23:17:19 +00:00
|
|
|
// gob.NewEncoder(buf).Encode(src)
|
|
|
|
cork.NewEncoder(buf).Encode(src)
|
2016-09-19 11:02:10 +00:00
|
|
|
return buf.Bytes()
|
|
|
|
}
|
2016-09-14 21:25:18 +00:00
|
|
|
|
2016-10-01 23:17:19 +00:00
|
|
|
// Decode decodes a GOB into a data object.
|
|
|
|
func Decode(src []byte, dst interface{}) {
|
2016-09-19 11:02:10 +00:00
|
|
|
buf := bytes.NewBuffer(src)
|
2016-10-01 23:17:19 +00:00
|
|
|
// gob.NewDecoder(buf).Decode(&dst)
|
|
|
|
cork.NewDecoder(buf).Decode(dst)
|
2016-09-06 11:41:03 +00:00
|
|
|
return
|
|
|
|
}
|