-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert breaking API changes, wrap CodecP internally
- Loading branch information
Showing
25 changed files
with
74 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,42 @@ | ||
package goka | ||
|
||
import "io" | ||
import ( | ||
"io" | ||
|
||
"github.com/lovoo/goka/codec" | ||
) | ||
|
||
// Codec decodes and encodes from and to []byte | ||
type Codec interface { | ||
Encode(value interface{}) (data []byte, err error) | ||
Decode(data []byte) (value interface{}, err error) | ||
} | ||
|
||
type CodecP interface { | ||
Codec | ||
|
||
DecodeP(data []byte) (value interface{}, closer io.Closer, err error) | ||
} | ||
|
||
// FuncCloser implements io.Closer-interface for convenience | ||
type FuncCloser func() error | ||
// CloserFunc implements io.Closer-interface for convenience when wrapping functions | ||
type CloserFunc func() error | ||
|
||
func (f FuncCloser) Close() error { | ||
func (f CloserFunc) Close() error { | ||
return f() | ||
} | ||
|
||
type codecWrapper struct { | ||
Codec | ||
} | ||
|
||
func (cw *codecWrapper) DecodeP(data []byte) (value interface{}, closer io.Closer, err error) { | ||
val, err := cw.Codec.Decode(data) | ||
return val, codec.NoopCloser, err | ||
} | ||
|
||
func convertOrFakeCodec(c Codec) CodecP { | ||
if cp, ok := c.(CodecP); ok { | ||
return cp | ||
} | ||
return &codecWrapper{Codec: c} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
package codec | ||
|
||
type Closer interface { | ||
Close() | ||
} | ||
|
||
type nullCloser struct{} | ||
|
||
func (n *nullCloser) Close() error { return nil } | ||
|
||
// NoopCloser can be used for returning io.Closer interfaces, whose Close call does | ||
// nothing. | ||
var NoopCloser = new(nullCloser) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.