md2gmi/pipe/streamitem.go

43 lines
742 B
Go
Raw Normal View History

2021-07-05 17:12:10 +03:00
package pipe
import (
"context"
)
type StreamItem struct {
ctx context.Context
index int
payload []byte
}
func (s *StreamItem) Context() context.Context {
return s.ctx
}
func NewItem(index int, payload []byte) StreamItem {
return newItem(context.Background(), index, payload)
}
2021-07-05 17:12:10 +03:00
func NewItemWithContext(ctx context.Context, index int, payload []byte) StreamItem {
return newItem(ctx, index, payload)
}
2021-07-05 17:12:10 +03:00
func newItem(ctx context.Context, index int, payload []byte) StreamItem {
s := StreamItem{
ctx: ctx,
index: index,
payload: make([]byte, len(payload)),
2021-07-05 17:12:10 +03:00
}
copy(s.payload, payload)
2021-07-11 12:12:57 +03:00
2021-07-05 20:06:41 +03:00
return s
2021-07-05 17:12:10 +03:00
}
2021-07-05 20:06:41 +03:00
func (s *StreamItem) Index() int {
return s.index
2021-07-05 17:12:10 +03:00
}
2021-07-05 20:06:41 +03:00
func (s *StreamItem) Payload() []byte {
return s.payload
2021-07-05 17:12:10 +03:00
}