-
Notifications
You must be signed in to change notification settings - Fork 177
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
72 additions
and
124 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 | ||
// FuncCloser implements io.Closer-interface for convenience when wrapping functions | ||
type FuncCloser func() error | ||
|
||
func (f FuncCloser) 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
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.