memory.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2021 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import "github.com/lf-edge/ekuiper/pkg/api"
  16. type memory struct {
  17. results [][]byte
  18. }
  19. func (m *memory) Open(ctx api.StreamContext) error {
  20. log := ctx.GetLogger()
  21. log.Debug("Opening memory sink")
  22. m.results = make([][]byte, 0)
  23. return nil
  24. }
  25. func (m *memory) Collect(ctx api.StreamContext, item interface{}) error {
  26. logger := ctx.GetLogger()
  27. if v, ok := item.([]byte); ok {
  28. logger.Debugf("memory sink receive %s", item)
  29. m.results = append(m.results, v)
  30. } else {
  31. logger.Debug("memory sink receive non byte data")
  32. }
  33. return nil
  34. }
  35. func (m *memory) Close(ctx api.StreamContext) error {
  36. //do nothing
  37. return nil
  38. }
  39. func (m *memory) Configure(props map[string]interface{}) error {
  40. return nil
  41. }
  42. func Memory() api.Sink {
  43. return &memory{}
  44. }