realEncoder.go 847 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package kafka
  2. import "encoding/binary"
  3. type realEncoder struct {
  4. raw []byte
  5. off int
  6. }
  7. func (re *realEncoder) putInt16(in int16) {
  8. binary.BigEndian.PutUint16(re.raw[re.off:], uint16(in))
  9. re.off += 2
  10. }
  11. func (re *realEncoder) putInt32(in int32) {
  12. binary.BigEndian.PutUint32(re.raw[re.off:], uint32(in))
  13. re.off += 4
  14. }
  15. func (re *realEncoder) putError(in kafkaError) {
  16. re.putInt16(int16(in))
  17. }
  18. func (re *realEncoder) putString(in *string) {
  19. if in == nil {
  20. re.putInt16(-1)
  21. return
  22. }
  23. re.putInt16(int16(len(*in)))
  24. re.off += 2
  25. copy(re.raw[re.off:], *in)
  26. re.off += len(*in)
  27. }
  28. func (re *realEncoder) putBytes(in *[]byte) {
  29. if in == nil {
  30. re.putInt32(-1)
  31. return
  32. }
  33. re.putInt32(int32(len(*in)))
  34. re.off += 4
  35. copy(re.raw[re.off:], *in)
  36. re.off += len(*in)
  37. }
  38. func (re *realEncoder) putArrayCount(in int) {
  39. re.putInt32(int32(in))
  40. }