Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use protobuf protocol? #16

Open
edmand46 opened this issue May 6, 2017 · 6 comments
Open

How to use protobuf protocol? #16

edmand46 opened this issue May 6, 2017 · 6 comments
Labels

Comments

@edmand46
Copy link

edmand46 commented May 6, 2017

How to use protobuf protocol?

@lonng lonng added the question label May 7, 2017
@lonng
Copy link
Owner

lonng commented May 7, 2017

All you should do is that using protobuf protocol serializer before you call starx.Run()

starx.SetSerializer(protobuf.NewProtobufSerializer())

In addition, the second parameter of your handler method should be a struct that could be serialized/deserialized by protobuf.

func (f *Foo)Bar(s *session.Session, m *proto.SomeProtobufStruct) error {
    //you game logic
    s.Response(&proto.AnotherProtobufStruct{})
}

That all.

@edmand46
Copy link
Author

edmand46 commented May 7, 2017

Thanks for answer!
Serializer can by only one? I can`t combine JSON for infrequently and Protobuf for often data sending?

@lonng
Copy link
Owner

lonng commented May 8, 2017

You can't combine JSON and Protobuf in the current version of StarX, but could combine for different server type.

starx.Set("server-type", func(){
	starx.SetSerializer(json.NewJsonSerializer())
})

starx.Set("server-type-2", func() {
	starx.SetSerializer(protobuf.NewProtobufSerializer())
})

@edmand46
Copy link
Author

edmand46 commented May 8, 2017

Okay thanks, but what i doing wrong in message upper?

@lonng
Copy link
Owner

lonng commented May 8, 2017

Seems like you struct with wrong tags

Try this:

type Message struct {
	Data string `protobuf:"bytes,1,name=data"`
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants