mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
Structural binary serialization
This commit is contained in:
27
bytesconv/serialization_test.go
Normal file
27
bytesconv/serialization_test.go
Normal file
@ -0,0 +1,27 @@
|
||||
package bytesconv
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type SimpleUser struct {
|
||||
FirstName string
|
||||
LastName string
|
||||
}
|
||||
|
||||
func TestGob(t *testing.T) {
|
||||
u := SimpleUser{FirstName: "Radomir", LastName: "Sohlich"}
|
||||
buf, err := Encode(u)
|
||||
t.Log("Gob", BytesResult(buf).Hex(), err)
|
||||
|
||||
var u2 SimpleUser
|
||||
if err := Decode(buf, &u2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
jBytes, _ := json.Marshal(u2)
|
||||
t.Log("Json:", BytesResult(jBytes).Hex())
|
||||
|
||||
t.Logf("%+v", u2)
|
||||
}
|
Reference in New Issue
Block a user