You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

  1. package segment
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb/message_fbs"
  4. flatbuffers "github.com/google/flatbuffers/go"
  5. )
  6. func CreateMessage(b *flatbuffers.Builder, producerId int32, producerSeq int64, segmentId int32, segmentSeq int64,
  7. eventTsNs int64, recvTsNs int64, properties map[string]string, key []byte, value []byte) {
  8. b.Reset()
  9. var names, values, pairs []flatbuffers.UOffsetT
  10. for k, v := range properties {
  11. names = append(names, b.CreateString(k))
  12. values = append(values, b.CreateString(v))
  13. }
  14. for i, _ := range names {
  15. message_fbs.NameValueStart(b)
  16. message_fbs.NameValueAddName(b, names[i])
  17. message_fbs.NameValueAddValue(b, values[i])
  18. pair := message_fbs.NameValueEnd(b)
  19. pairs = append(pairs, pair)
  20. }
  21. message_fbs.MessageStartPropertiesVector(b, len(properties))
  22. for i := len(pairs) - 1; i >= 0; i-- {
  23. b.PrependUOffsetT(pairs[i])
  24. }
  25. prop := b.EndVector(len(properties))
  26. k := b.CreateByteVector(key)
  27. v := b.CreateByteVector(value)
  28. message_fbs.MessageStart(b)
  29. message_fbs.MessageAddProducerId(b, producerId)
  30. message_fbs.MessageAddProducerSeq(b, producerSeq)
  31. message_fbs.MessageAddSegmentId(b, segmentId)
  32. message_fbs.MessageAddSegmentSeq(b, segmentSeq)
  33. message_fbs.MessageAddEventTsNs(b, eventTsNs)
  34. message_fbs.MessageAddRecvTsNs(b, recvTsNs)
  35. message_fbs.MessageAddProperties(b, prop)
  36. message_fbs.MessageAddKey(b, k)
  37. message_fbs.MessageAddData(b, v)
  38. message := message_fbs.MessageEnd(b)
  39. b.Finish(message)
  40. }