-
Notifications
You must be signed in to change notification settings - Fork 269
/
sink_protocol.go
106 lines (97 loc) · 2.49 KB
/
sink_protocol.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2021 PingCAP, Inc.
//
// 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,
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
"strings"
cerror "github.com/pingcap/tiflow/pkg/errors"
)
const (
// ProtocolKey specifies the key of the protocol in the SinkURI.
ProtocolKey = "protocol"
)
// Protocol is the protocol of the message.
type Protocol int
// Enum types of the Protocol.
const (
ProtocolUnknown Protocol = iota
ProtocolDefault
ProtocolCanal
ProtocolAvro
ProtocolMaxwell
ProtocolCanalJSON
ProtocolCraft
ProtocolOpen
ProtocolCsv
ProtocolDebezium
ProtocolSimple
)
// IsBatchEncode returns whether the protocol is a batch encoder.
func (p Protocol) IsBatchEncode() bool {
return p == ProtocolOpen || p == ProtocolCanal || p == ProtocolMaxwell || p == ProtocolCraft
}
// ParseSinkProtocolFromString converts the protocol from string to Protocol enum type.
func ParseSinkProtocolFromString(protocol string) (Protocol, error) {
switch strings.ToLower(protocol) {
case "default":
return ProtocolOpen, nil
case "canal":
return ProtocolCanal, nil
case "avro":
return ProtocolAvro, nil
case "flat-avro":
return ProtocolAvro, nil
case "maxwell":
return ProtocolMaxwell, nil
case "canal-json":
return ProtocolCanalJSON, nil
case "craft":
return ProtocolCraft, nil
case "open-protocol":
return ProtocolOpen, nil
case "csv":
return ProtocolCsv, nil
case "debezium":
return ProtocolDebezium, nil
case "simple":
return ProtocolSimple, nil
default:
return ProtocolUnknown, cerror.ErrSinkUnknownProtocol.GenWithStackByArgs(protocol)
}
}
// String converts the Protocol enum type string to string.
func (p Protocol) String() string {
switch p {
case ProtocolDefault:
return "default"
case ProtocolCanal:
return "canal"
case ProtocolAvro:
return "avro"
case ProtocolMaxwell:
return "maxwell"
case ProtocolCanalJSON:
return "canal-json"
case ProtocolCraft:
return "craft"
case ProtocolOpen:
return "open-protocol"
case ProtocolCsv:
return "csv"
case ProtocolDebezium:
return "debezium"
case ProtocolSimple:
return "simple"
default:
panic("unreachable")
}
}