• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang encoder.JsonEncoderDecoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/awesomegroupidunno/game-server/encoder.JsonEncoderDecoder的典型用法代码示例。如果您正苦于以下问题:Golang JsonEncoderDecoder类的具体用法?Golang JsonEncoderDecoder怎么用?Golang JsonEncoderDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了JsonEncoderDecoder类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestConnection

func TestConnection(t *testing.T) {

	ack_channel := make(chan state.Ack, 100)
	state_channel := make(chan state.StateResponse, 5)
	physics := processor.DefaultPhysics()
	factory := processor.NewFactory(&physics)
	manager := game.NewManager(physics.NewGameState(), state_channel, &factory)
	router := game.CommandRouter{GameManager: &manager, Acks: ack_channel}
	go manager.Start()

	reciever := network.UdpReceiver{
		Router:     router,
		Acks:       ack_channel,
		Responses:  state_channel,
		PortNumber: ":10002"}

	reciever.Run()
	conn, err := net.DialTimeout("udp", "127.0.0.1:10002", 1*time.Second)
	Convey("Test connect", t, func() {
		So(err, ShouldEqual, nil)
		So(conn, ShouldNotEqual, nil)
	})

	Convey("Test Connect command", t, func() {
		a := cmd.NewConnect("Dan")
		a.UniqueId = "abc123"
		message, err := json.Marshal(a)

		So(err, ShouldEqual, nil)

		i, error := conn.Write(message)

		So(i, ShouldBeGreaterThan, 0)
		So(error, ShouldEqual, nil)
	})

	Convey("Test State Responder", t, func() {
		reciever.Responses <- state.StateResponse{State: physics.NewGameState()}
		response := make([]byte, 2048)
		// read response
		conn.SetDeadline(time.Now().Add(2 * time.Second))
		n, err := bufio.NewReader(conn).Read(response)
		So(err, ShouldEqual, nil)
		So(string(response[:n]), ShouldEqual, "abc123")

		conn.SetDeadline(time.Now().Add(2 * time.Second))
		n, err = bufio.NewReader(conn).Read(response)
		So(err, ShouldEqual, nil)

		encoder := encoder.JsonEncoderDecoder{}

		_, encode_error := encoder.Decode(response[:n])
		So(encode_error, ShouldEqual, nil)

	})

}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:57,代码来源:udpReciever_test.go


示例2: TestDecode

func TestDecode(t *testing.T) {
	Convey("Decode", t, func() {
		formatter := encoder.JsonEncoderDecoder{Tag: "DecodeTest"}
		data := cmd.BaseCommand{Type: "GET", Subtype: "STATE", UniqueId: "ABC123"}
		buffer, error := json.Marshal(data)

		command, error := formatter.Decode(buffer)

		So(error, ShouldEqual, nil)
		So(command.Command().Type, ShouldEqual, "GET")
		So(command.Command().Subtype, ShouldEqual, "STATE")
		So(command.Command().UniqueId, ShouldEqual, "ABC123")
	})
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:14,代码来源:jsonEncoderDecoder_test.go


示例3: TestEncode

func TestEncode(t *testing.T) {
	Convey("Encode", t, func() {
		formatter := encoder.JsonEncoderDecoder{Tag: "EncodeTest"}
		data := state.GameState{Val: "test Val"}

		decoded := state.GameState{}

		buffer, error := formatter.Encode(data)

		unmarshal_error := json.Unmarshal(buffer, &decoded)

		So(error, ShouldEqual, nil)
		So(unmarshal_error, ShouldEqual, nil)
		So(decoded.Val, ShouldEqual, "test Val")

	})
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:17,代码来源:jsonEncoderDecoder_test.go


示例4: TestDecodePowerup

func TestDecodePowerup(t *testing.T) {
	Convey("Fire powerup", t, func() {
		formatter := encoder.JsonEncoderDecoder{Tag: "DecodeTest"}

		data := cmd.NewPowerup()
		data.UniqueId = "ABC123"
		buffer, error := json.Marshal(data)

		command, err := formatter.Decode(buffer)

		turn := command.(*cmd.PowerupCommand)

		So(error, ShouldEqual, nil)
		So(turn.Command().Type, ShouldEqual, cmd.Post)
		So(turn.Command().Subtype, ShouldEqual, cmd.POWERUP)
		So(err, ShouldEqual, nil)
		So(turn.Command().UniqueId, ShouldEqual, "ABC123")
	})
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:19,代码来源:jsonEncoderDecoder_test.go


示例5: TestDecodeConnect

func TestDecodeConnect(t *testing.T) {
	Convey("Connect Decode", t, func() {
		formatter := encoder.JsonEncoderDecoder{Tag: "DecodeTest"}

		data := cmd.NewConnect("myname")
		data.UniqueId = "ABC123"
		buffer, error := json.Marshal(data)

		command, err := formatter.Decode(buffer)

		turn := command.(*cmd.ConnectCommand)

		So(error, ShouldEqual, nil)
		So(turn.Command().Type, ShouldEqual, cmd.Post)
		So(turn.Command().Subtype, ShouldEqual, cmd.Connect)
		So(err, ShouldEqual, nil)
		So(turn.Value, ShouldEqual, "myname")
		So(turn.Command().UniqueId, ShouldEqual, "ABC123")
	})
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:20,代码来源:jsonEncoderDecoder_test.go


示例6: TestDecodeTurn

func TestDecodeTurn(t *testing.T) {
	Convey("Turn Decode", t, func() {
		formatter := encoder.JsonEncoderDecoder{Tag: "DecodeTest"}

		data := cmd.NewTurn(.2)
		data.UniqueId = "ABC123"
		buffer, error := json.Marshal(data)

		command, err := formatter.Decode(buffer)

		turn := command.(*cmd.TurnCommand)

		So(error, ShouldEqual, nil)
		So(turn.Command().Type, ShouldEqual, cmd.Post)
		So(turn.Command().Subtype, ShouldEqual, cmd.Turn)
		So(err, ShouldEqual, nil)
		So(turn.Value, ShouldAlmostEqual, .2, .000001)
		So(turn.Command().UniqueId, ShouldEqual, "ABC123")
	})
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:20,代码来源:jsonEncoderDecoder_test.go



注:本文中的github.com/awesomegroupidunno/game-server/encoder.JsonEncoderDecoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang state.GameState类代码示例发布时间:2022-05-24
下一篇:
Golang gographviz.Graph类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap