cubefs

Форк
0
/
packet_decoder.go 
69 строк · 2.7 Кб
1
package sarama
2

3
// PacketDecoder is the interface providing helpers for reading with Kafka's encoding rules.
4
// Types implementing Decoder only need to worry about calling methods like GetString,
5
// not about how a string is represented in Kafka.
6
type packetDecoder interface {
7
	// Primitives
8
	getInt8() (int8, error)
9
	getInt16() (int16, error)
10
	getInt32() (int32, error)
11
	getInt64() (int64, error)
12
	getVarint() (int64, error)
13
	getUVarint() (uint64, error)
14
	getFloat64() (float64, error)
15
	getArrayLength() (int, error)
16
	getCompactArrayLength() (int, error)
17
	getBool() (bool, error)
18
	getEmptyTaggedFieldArray() (int, error)
19

20
	// Collections
21
	getBytes() ([]byte, error)
22
	getVarintBytes() ([]byte, error)
23
	getCompactBytes() ([]byte, error)
24
	getRawBytes(length int) ([]byte, error)
25
	getString() (string, error)
26
	getNullableString() (*string, error)
27
	getCompactString() (string, error)
28
	getCompactNullableString() (*string, error)
29
	getCompactInt32Array() ([]int32, error)
30
	getInt32Array() ([]int32, error)
31
	getInt64Array() ([]int64, error)
32
	getStringArray() ([]string, error)
33

34
	// Subsets
35
	remaining() int
36
	getSubset(length int) (packetDecoder, error)
37
	peek(offset, length int) (packetDecoder, error) // similar to getSubset, but it doesn't advance the offset
38
	peekInt8(offset int) (int8, error)              // similar to peek, but just one byte
39

40
	// Stacks, see PushDecoder
41
	push(in pushDecoder) error
42
	pop() error
43
}
44

45
// PushDecoder is the interface for decoding fields like CRCs and lengths where the validity
46
// of the field depends on what is after it in the packet. Start them with PacketDecoder.Push() where
47
// the actual value is located in the packet, then PacketDecoder.Pop() them when all the bytes they
48
// depend upon have been decoded.
49
type pushDecoder interface {
50
	// Saves the offset into the input buffer as the location to actually read the calculated value when able.
51
	saveOffset(in int)
52

53
	// Returns the length of data to reserve for the input of this encoder (eg 4 bytes for a CRC32).
54
	reserveLength() int
55

56
	// Indicates that all required data is now available to calculate and check the field.
57
	// SaveOffset is guaranteed to have been called first. The implementation should read ReserveLength() bytes
58
	// of data from the saved offset, and verify it based on the data between the saved offset and curOffset.
59
	check(curOffset int, buf []byte) error
60
}
61

62
// dynamicPushDecoder extends the interface of pushDecoder for uses cases where the length of the
63
// fields itself is unknown until its value was decoded (for instance varint encoded length
64
// fields).
65
// During push, dynamicPushDecoder.decode() method will be called instead of reserveLength()
66
type dynamicPushDecoder interface {
67
	pushDecoder
68
	decoder
69
}
70

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

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

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

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