All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.digitalpetri.enip.cip.structs.MessageRouterRequest Maven / Gradle / Ivy

There is a newer version: 1.5.0-RC1
Show newest version
package com.digitalpetri.enip.cip.structs;

import com.digitalpetri.enip.cip.epath.EPath;
import io.netty.buffer.ByteBuf;

import java.util.function.Consumer;

public class MessageRouterRequest {

    private final int serviceCode;
    private final EPath.PaddedEPath requestPath;
    private final Consumer dataEncoder;

    public MessageRouterRequest(int serviceCode, EPath.PaddedEPath requestPath, ByteBuf requestData) {
        this.serviceCode = serviceCode;
        this.requestPath = requestPath;
        this.dataEncoder = (buffer) -> buffer.writeBytes(requestData);
    }

    public MessageRouterRequest(int serviceCode, EPath.PaddedEPath requestPath, Consumer dataEncoder) {
        this.serviceCode = serviceCode;
        this.requestPath = requestPath;
        this.dataEncoder = dataEncoder;
    }

    public static void encode(MessageRouterRequest request, ByteBuf buffer) {
        buffer.writeByte(request.serviceCode);
        EPath.encode(request.requestPath, buffer);
        request.dataEncoder.accept(buffer);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy