-
Notifications
You must be signed in to change notification settings - Fork 647
/
creator.go
54 lines (45 loc) · 1.66 KB
/
creator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package message
import (
"fmt"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/ava-labs/avalanchego/utils/constants"
)
var _ Creator = &creator{}
type Creator interface {
OutboundMsgBuilder
InboundMsgBuilder
InternalMsgBuilder
}
type creator struct {
OutboundMsgBuilder
InboundMsgBuilder
InternalMsgBuilder
}
func NewCreator(metrics prometheus.Registerer, parentNamespace string, compressionEnabled bool, maxInboundMessageTimeout time.Duration) (Creator, error) {
namespace := fmt.Sprintf("%s_codec", parentNamespace)
codec, err := NewCodecWithMemoryPool(namespace, metrics, int64(constants.DefaultMaxMessageSize), maxInboundMessageTimeout)
if err != nil {
return nil, err
}
return &creator{
OutboundMsgBuilder: NewOutboundBuilderWithPacker(codec, compressionEnabled),
InboundMsgBuilder: NewInboundBuilderWithPacker(codec),
InternalMsgBuilder: NewInternalBuilder(),
}, nil
}
func NewCreatorWithProto(metrics prometheus.Registerer, parentNamespace string, compressionEnabled bool, maxInboundMessageTimeout time.Duration) (Creator, error) {
// different namespace, not to be in conflict with packer
namespace := fmt.Sprintf("%s_proto_codec", parentNamespace)
builder, err := newMsgBuilderProtobuf(namespace, metrics, int64(constants.DefaultMaxMessageSize), maxInboundMessageTimeout)
if err != nil {
return nil, err
}
return &creator{
OutboundMsgBuilder: newOutboundBuilderWithProto(compressionEnabled, builder),
InboundMsgBuilder: newInboundBuilderWithProto(builder),
InternalMsgBuilder: NewInternalBuilder(),
}, nil
}