experimental codec branch
This commit is contained in:
23
codec/bson/bson.go
Normal file
23
codec/bson/bson.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package bson
|
||||
|
||||
import (
|
||||
"labix.org/v2/mgo/bson"
|
||||
)
|
||||
|
||||
var (
|
||||
Codec = bsonCodec{}
|
||||
)
|
||||
|
||||
type bsonCodec struct {}
|
||||
|
||||
func (bsonCodec) Marshal(v interface{}) ([]byte, error) {
|
||||
return bson.Marshal(v)
|
||||
}
|
||||
|
||||
func (bsonCodec) Unmarshal(data []byte, v interface{}) error {
|
||||
return bson.Unmarshal(data, v)
|
||||
}
|
||||
|
||||
func (bsonCodec) String() string {
|
||||
return "bson"
|
||||
}
|
12
codec/codec.go
Normal file
12
codec/codec.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package codec
|
||||
|
||||
// Codec used to encode and decode request/responses
|
||||
type Codec interface {
|
||||
// Marshal returns the wire format of v.
|
||||
Marshal(v interface{}) ([]byte, error)
|
||||
// Unmarshal parses the wire format into v.
|
||||
Unmarshal(data []byte, v interface{}) error
|
||||
// String returns the name of the Codec implementation. The returned
|
||||
// string will be used as part of content type in transmission.
|
||||
String() string
|
||||
}
|
24
codec/pb/pb.go
Normal file
24
codec/pb/pb.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package pb
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
var (
|
||||
Codec = protoCodec{}
|
||||
)
|
||||
|
||||
type protoCodec struct {}
|
||||
|
||||
func (protoCodec) Marshal(v interface{}) ([]byte, error) {
|
||||
return proto.Marshal(v.(proto.Message))
|
||||
}
|
||||
|
||||
func (protoCodec) Unmarshal(data []byte, v interface{}) error {
|
||||
return proto.Unmarshal(data, v.(proto.Message))
|
||||
}
|
||||
|
||||
func (protoCodec) String() string {
|
||||
return "proto"
|
||||
}
|
||||
|
Reference in New Issue
Block a user