forked from mostafa/xk6-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.go
32 lines (26 loc) · 994 Bytes
/
string.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
package kafka
import (
"fmt"
"github.com/riferrei/srclient"
)
const (
String srclient.SchemaType = "STRING"
StringSerializer string = "org.apache.kafka.common.serialization.StringSerializer"
StringDeserializer string = "org.apache.kafka.common.serialization.StringDeserializer"
)
// SerializeString serializes a string to bytes
func SerializeString(configuration Configuration, topic string, data interface{}, element Element, schema string, version int) ([]byte, *Xk6KafkaError) {
switch data := data.(type) {
case string:
return []byte(data), nil
default:
return nil, NewXk6KafkaError(
invalidDataType,
"Invalid data type provided for string serializer (requires string)",
fmt.Errorf("Expected: string, got: %T", data))
}
}
// DeserializeString deserializes a string from bytes
func DeserializeString(configuration Configuration, topic string, data []byte, element Element, schema string, version int) (interface{}, *Xk6KafkaError) {
return string(data), nil
}