1234567891011121314151617181920212223242526272829 |
- package sarama
- import "encoding/binary"
- type lengthField struct {
- startOffset int
- }
- func (l *lengthField) saveOffset(in int) {
- l.startOffset = in
- }
- func (l *lengthField) reserveLength() int {
- return 4
- }
- func (l *lengthField) run(curOffset int, buf []byte) error {
- binary.BigEndian.PutUint32(buf[l.startOffset:], uint32(curOffset-l.startOffset-4))
- return nil
- }
- func (l *lengthField) check(curOffset int, buf []byte) error {
- if uint32(curOffset-l.startOffset-4) != binary.BigEndian.Uint32(buf[l.startOffset:]) {
- return PacketDecodingError{"length field invalid"}
- }
- return nil
- }
|