PacketEncoder is the interface providing helpers for writing with Kafka's encoding rules. Types implementing Encoder only need to worry about calling methods like PutString, not about how a string is represented in Kafka.
| 10 | // Types implementing Encoder only need to worry about calling methods like PutString, |
| 11 | // not about how a string is represented in Kafka. |
| 12 | type packetEncoder interface { |
| 13 | // Primitives |
| 14 | putInt8(in int8) |
| 15 | putInt16(in int16) |
| 16 | putInt32(in int32) |
| 17 | putInt64(in int64) |
| 18 | putVarint(in int64) |
| 19 | putUVarint(in uint64) |
| 20 | putFloat64(in float64) |
| 21 | putArrayLength(in int) error |
| 22 | putBool(in bool) |
| 23 | putKError(in KError) |
| 24 | putDurationMs(in time.Duration) |
| 25 | |
| 26 | // Collections |
| 27 | putBytes(in []byte) error |
| 28 | putVarintBytes(in []byte) error |
| 29 | putRawBytes(in []byte) error |
| 30 | putUuid(in Uuid) error |
| 31 | putString(in string) error |
| 32 | putNullableString(in *string) error |
| 33 | putStringArray(in []string) error |
| 34 | putInt32Array(in []int32) error |
| 35 | putInt64Array(in []int64) error |
| 36 | putNullableInt32Array(in []int32) error |
| 37 | putEmptyTaggedFieldArray() |
| 38 | |
| 39 | // Provide the current offset to record the batch size metric |
| 40 | offset() int |
| 41 | |
| 42 | // Stacks, see PushEncoder |
| 43 | push(in pushEncoder) |
| 44 | pop() error |
| 45 | |
| 46 | // To record metrics when provided |
| 47 | metricRegistry() metrics.Registry |
| 48 | } |
| 49 | |
| 50 | // PushEncoder is the interface for encoding fields like CRCs and lengths where the value |
| 51 | // of the field depends on what is encoded after it in the packet. Start them with PacketEncoder.Push() where |