record.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package kafka
  2. import (
  3. "github.com/segmentio/kafka-go/protocol"
  4. )
  5. // Header is a key/value pair type representing headers set on records.
  6. type Header = protocol.Header
  7. // Bytes is an interface representing a sequence of bytes. This abstraction
  8. // makes it possible for programs to inject data into produce requests without
  9. // having to load in into an intermediary buffer, or read record keys and values
  10. // from a fetch response directly from internal buffers.
  11. //
  12. // Bytes are not safe to use concurrently from multiple goroutines.
  13. type Bytes = protocol.Bytes
  14. // NewBytes constructs a Bytes value from a byte slice.
  15. //
  16. // If b is nil, nil is returned.
  17. func NewBytes(b []byte) Bytes { return protocol.NewBytes(b) }
  18. // ReadAll reads b into a byte slice.
  19. func ReadAll(b Bytes) ([]byte, error) { return protocol.ReadAll(b) }
  20. // Record is an interface representing a single kafka record.
  21. //
  22. // Record values are not safe to use concurrently from multiple goroutines.
  23. type Record = protocol.Record
  24. // RecordReader is an interface representing a sequence of records. Record sets
  25. // are used in both produce and fetch requests to represent the sequence of
  26. // records that are sent to or receive from kafka brokers.
  27. //
  28. // RecordReader values are not safe to use concurrently from multiple goroutines.
  29. type RecordReader = protocol.RecordReader
  30. // NewRecordReade rconstructs a RecordSet which exposes the sequence of records
  31. // passed as arguments.
  32. func NewRecordReader(records ...Record) RecordReader {
  33. return protocol.NewRecordReader(records...)
  34. }