Skip to content

Flex

This extension for Channels implements the middleware to decode and encode data using the Flex protocol.

Getting started

Install the package from NuGet

dotnet add package Faactory.Channels.Flex

To enable the decoding of messages on the input pipeline, register the adapters with the channel builder.

IChannelBuilder channel = ...;

channel.AddFlexMiddleware();

Since Flex is a base protocol, you'll still need to decode the modules payload. The existing pipeline will forward a Message object into the pipeline for you to handle. Each message will contain a list with the modules found in the message. You can extend the pipeline with your own adapters to decode the modules, or you can just use the Message object as is in a handler.

Acknowledge messages

The library automatically writes to the output pipeline an acknowledge message for each message received (with modules). If required, you can disable this behavior by setting the AutoAcknowledge property to false on the decoder options when registering the adapters. If you disable the automatic acknowledge, you'll need to manually write the acknowledge message to the output pipeline.

channel.AddFlexMiddleware( options =>
{
    options.AutoAcknowledge = false;
} );

Heartbeat messages

The library does not automatically deal with received heartbeat messages nor does it send them. Since the protocol does not enforce this behaviour nor defines any rules for it, it's up to you to decide if and how to implement it.

Heartbeat messages don't have a payload and are forwarded as a Heartbeat object. You can write a handler to deal with them in accordance to your needs.

Output Pipeline

The library does not build on the output pipeline. Instead, it provides a MessageBuilder helper class to help you create outgoing messages. Messages built this way will already be encoded and ready to be written to the output pipeline as a IByteBuffer object.

// create a message with a passthrough module
var passthrough = MessageBuilder.Create()
    .AddModule(
        0xffff,
        Encoding.UTF8.GetBytes( "$ enable 0x0001" )
    )
    .Build();

await channel.WriteAsync( passthrough );

Input Pipeline Flowchart

flowchart LR
    buffer["byte[]"] --> BinaryMessage
    BinaryMessage --> Heartbeat
    BinaryMessage --> Message
    Message -.-> p["Your Pipeline"]
    Heartbeat -.-> p