Skip to content

Commit 17140d6

Browse files
committed
optimize: add tunmarshal
1 parent f03ddc3 commit 17140d6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

raft.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"strings"
2222

2323
rt "github.com/B1NARY-GR0UP/raft/raftthrift"
24-
"github.com/apache/thrift/lib/go/thrift"
2524
)
2625

2726
// None should not be used as a simply number zero
@@ -437,8 +436,7 @@ func (r *raft) stepLeader(msg rt.Message) error {
437436
var cc rt.ConfChange
438437
if entry.Type == rt.EntryType_Config {
439438
hasConfChange = true
440-
deserializer := thrift.NewTDeserializer()
441-
if err := deserializer.Read(&cc, entry.Data); err != nil {
439+
if err := TUnmarshal(entry.Data, &cc); err != nil {
442440
panic(err)
443441
}
444442
}

utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,8 @@ func TMarshal(ctx context.Context, data thrift.TStruct) ([]byte, error) {
111111
serializer := thrift.NewTSerializer()
112112
return serializer.Write(ctx, data)
113113
}
114+
115+
func TUnmarshal(data []byte, v thrift.TStruct) error {
116+
deserializer := thrift.NewTDeserializer()
117+
return deserializer.Read(v, data)
118+
}

0 commit comments

Comments
 (0)