forked from eatmoreapple/openwechat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat]: 支持用户自定义热存储数据的序列化和反序列化 (eatmoreapple#222)
- Loading branch information
1 parent
e9c89f9
commit d77bb0a
Showing
2 changed files
with
37 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package openwechat | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
) | ||
|
||
// Serializer is an interface for encoding and decoding data. | ||
type Serializer interface { | ||
Encode(writer io.Writer, v interface{}) error | ||
Decode(reader io.Reader, v interface{}) error | ||
} | ||
|
||
// JsonSerializer is a serializer for json. | ||
type JsonSerializer struct{} | ||
|
||
// Encode encodes v to writer. | ||
func (j JsonSerializer) Encode(writer io.Writer, v interface{}) error { | ||
return json.NewEncoder(writer).Encode(v) | ||
} | ||
|
||
// Decode decodes data from reader to v. | ||
func (j JsonSerializer) Decode(reader io.Reader, v interface{}) error { | ||
return json.NewDecoder(reader).Decode(v) | ||
} |