diff options
author | Determinant <[email protected]> | 2019-06-28 15:41:55 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-06-28 15:41:55 -0400 |
commit | ea27f0de65f79d7ee56e964f6c966e7c43c66f86 (patch) | |
tree | 3a0b868b7c560311b21a5a653d034148817d84c2 /test_msgnet | |
parent | 82153433ebdbe775ac3d7b12668dd222192e8dce (diff) |
...
Diffstat (limited to 'test_msgnet')
-rw-r--r-- | test_msgnet/main.go | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/test_msgnet/main.go b/test_msgnet/main.go index cad1697..292fb8f 100644 --- a/test_msgnet/main.go +++ b/test_msgnet/main.go @@ -11,7 +11,6 @@ package main import "C" import ( - "encoding/binary" "os" "fmt" "unsafe" @@ -25,9 +24,7 @@ const ( func msgHelloSerialize(name string, text string) salticidae.Msg { serialized := salticidae.NewDataStream() - t := make([]byte, 4) - binary.LittleEndian.PutUint32(t, uint32(len(name))) - serialized.PutData(t) + serialized.PutU32(salticidae.ToLittleEndianU32(uint32(len(name)))) serialized.PutData([]byte(name)) serialized.PutData([]byte(text)) return salticidae.NewMsgMovedFromByteArray( @@ -36,8 +33,9 @@ func msgHelloSerialize(name string, text string) salticidae.Msg { func msgHelloUnserialize(msg salticidae.Msg) (name string, text string) { p := msg.GetPayloadByMove() - t := p.GetDataInPlace(4); length := binary.LittleEndian.Uint32(t.Get()); t.Release() - t = p.GetDataInPlace(int(length)); name = string(t.Get()); t.Release() + succ := true + length := salticidae.FromLittleEndianU32(p.GetU32(&succ)) + t := p.GetDataInPlace(int(length)); name = string(t.Get()); t.Release() t = p.GetDataInPlace(p.Size()); text = string(t.Get()); t.Release() return } @@ -139,9 +137,10 @@ func genMyNet(ec salticidae.EventContext, func main() { ec = salticidae.NewEventContext() + err := salticidae.NewError() - aliceAddr := salticidae.NewAddrFromIPPortString("127.0.0.1:12345") - bobAddr := salticidae.NewAddrFromIPPortString("127.0.0.1:12346") + aliceAddr := salticidae.NewAddrFromIPPortString("127.0.0.1:12345", &err) + bobAddr := salticidae.NewAddrFromIPPortString("127.0.0.1:12346", &err) alice = genMyNet(ec, "alice", aliceAddr, bobAddr) bob = genMyNet(ec, "bob", bobAddr, aliceAddr) |