cubefs

Форк
0
/
packet_encoder.go 
74 строки · 2.6 Кб
1
package sarama
2

3
import "github.com/rcrowley/go-metrics"
4

5
// PacketEncoder is the interface providing helpers for writing with Kafka's encoding rules.
6
// Types implementing Encoder only need to worry about calling methods like PutString,
7
// not about how a string is represented in Kafka.
8
type packetEncoder interface {
9
	// Primitives
10
	putInt8(in int8)
11
	putInt16(in int16)
12
	putInt32(in int32)
13
	putInt64(in int64)
14
	putVarint(in int64)
15
	putUVarint(in uint64)
16
	putFloat64(in float64)
17
	putCompactArrayLength(in int)
18
	putArrayLength(in int) error
19
	putBool(in bool)
20

21
	// Collections
22
	putBytes(in []byte) error
23
	putVarintBytes(in []byte) error
24
	putCompactBytes(in []byte) error
25
	putRawBytes(in []byte) error
26
	putCompactString(in string) error
27
	putNullableCompactString(in *string) error
28
	putString(in string) error
29
	putNullableString(in *string) error
30
	putStringArray(in []string) error
31
	putCompactInt32Array(in []int32) error
32
	putNullableCompactInt32Array(in []int32) error
33
	putInt32Array(in []int32) error
34
	putInt64Array(in []int64) error
35
	putEmptyTaggedFieldArray()
36

37
	// Provide the current offset to record the batch size metric
38
	offset() int
39

40
	// Stacks, see PushEncoder
41
	push(in pushEncoder)
42
	pop() error
43

44
	// To record metrics when provided
45
	metricRegistry() metrics.Registry
46
}
47

48
// PushEncoder is the interface for encoding fields like CRCs and lengths where the value
49
// of the field depends on what is encoded after it in the packet. Start them with PacketEncoder.Push() where
50
// the actual value is located in the packet, then PacketEncoder.Pop() them when all the bytes they
51
// depend upon have been written.
52
type pushEncoder interface {
53
	// Saves the offset into the input buffer as the location to actually write the calculated value when able.
54
	saveOffset(in int)
55

56
	// Returns the length of data to reserve for the output of this encoder (eg 4 bytes for a CRC32).
57
	reserveLength() int
58

59
	// Indicates that all required data is now available to calculate and write the field.
60
	// SaveOffset is guaranteed to have been called first. The implementation should write ReserveLength() bytes
61
	// of data to the saved offset, based on the data between the saved offset and curOffset.
62
	run(curOffset int, buf []byte) error
63
}
64

65
// dynamicPushEncoder extends the interface of pushEncoder for uses cases where the length of the
66
// fields itself is unknown until its value was computed (for instance varint encoded length
67
// fields).
68
type dynamicPushEncoder interface {
69
	pushEncoder
70

71
	// Called during pop() to adjust the length of the field.
72
	// It should return the difference in bytes between the last computed length and current length.
73
	adjustLength(currOffset int) int
74
}
75

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.