Skip to content
Snippets Groups Projects
Commit 89e0985b authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Add extra gob registration types.

parent f4cfa6a6
Branches
Tags
No related merge requests found
......@@ -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 (
......
// 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")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment