From 89e0985b7d7c0577c4251be1736a438289d3c088 Mon Sep 17 00:00:00 2001 From: Andrei Mihu Date: Mon, 26 Oct 2020 11:23:50 +0000 Subject: [PATCH] Add extra gob registration types. --- server/match_registry.go | 15 ++++++++++----- server/match_registry_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 server/match_registry_test.go diff --git a/server/match_registry.go b/server/match_registry.go index 91228ccd6..6c98f06eb 100644 --- a/server/match_registry.go +++ b/server/match_registry.go @@ -20,26 +20,31 @@ import ( "encoding/gob" "encoding/json" "fmt" - "github.com/blevesearch/bleve/search/query" "strings" "sync" "time" "github.com/blevesearch/bleve" "github.com/blevesearch/bleve/analysis/analyzer/keyword" + "github.com/blevesearch/bleve/search/query" "github.com/gofrs/uuid" "github.com/golang/protobuf/ptypes/wrappers" "github.com/heroiclabs/nakama-common/api" + "github.com/heroiclabs/nakama-common/runtime" "github.com/pkg/errors" "go.uber.org/atomic" "go.uber.org/zap" ) func init() { - // Ensure gob can deal with maps of interfaces. - gob.Register(map[string]interface{}{}) - // Ensure gob can deal with slices of interfaces. - gob.Register([]interface{}{}) + // Ensure gob can deal with typical types that might be used in match parameters. + gob.Register(map[string]interface{}(nil)) + gob.Register([]interface{}(nil)) + gob.Register([]runtime.MatchmakerEntry(nil)) + gob.Register(MatchmakerEntry{}) + gob.Register([]*api.User(nil)) + gob.Register([]*api.Account(nil)) + gob.Register([]*api.Friend(nil)) } var ( diff --git a/server/match_registry_test.go b/server/match_registry_test.go new file mode 100644 index 000000000..fd41f5aa2 --- /dev/null +++ b/server/match_registry_test.go @@ -0,0 +1,35 @@ +// Copyright 2020 The Nakama Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package server + +import ( + "bytes" + "encoding/gob" + "github.com/gofrs/uuid" + "github.com/heroiclabs/nakama-common/runtime" + "testing" +) + +func TestEncode(t *testing.T) { + entries := []runtime.MatchmakerEntry{ + &MatchmakerEntry{Ticket: "123", Presence: &MatchmakerPresence{Username: "a"}, SessionID: uuid.Must(uuid.NewV4())}, + &MatchmakerEntry{Ticket: "456", Presence: &MatchmakerPresence{Username: "b"}, SessionID: uuid.Must(uuid.NewV4())}, + } + var buf bytes.Buffer + if err := gob.NewEncoder(&buf).Encode(map[string]interface{}{"foo": entries}); err != nil { + t.Fatalf("error: %v", err) + } + t.Log("ok") +} -- GitLab