psi icon indicating copy to clipboard operation
psi copied to clipboard

Is there any Framing component?

Open KanaHayama opened this issue 4 years ago • 1 comments

A Frame operator or component for returning non-overlapped grouped messages? A similar operator is Window, but it gives overlapped messages.

KanaHayama avatar Aug 10 '21 19:08 KanaHayama

We don't currently have such an operator, but it's a good idea, and we will look into the possibility of extending our current set of Window operators to handle such a case.

For now, you can probably accomplish what you want pretty easily with a Process operator and some state. For example, for a stream with messages of type T, you could try the following:

var group = new T[groupSize];
var index = 0;
var groupedStream = myStream.Process<T, T[]>((data, envelope, emitter) =>
{
    group[index++] = data.DeepClone();
    if (index >= groupSize)
    {
        index = 0;
        emitter.Post(group, envelope.OriginatingTime);
    }
});

sandrist avatar Aug 12 '21 19:08 sandrist