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

org.yamcs.algo.ReverseBinaryEncoder Maven / Gradle / Ivy

There is a newer version: 5.10.9
Show newest version
package org.yamcs.algo;

import org.yamcs.algorithms.AlgorithmExecutionContext;
import org.yamcs.mdb.AbstractDataEncoder;
import org.yamcs.mdb.TcProcessingContext;
import org.yamcs.parameter.Value;
import org.yamcs.utils.BitBuffer;
import org.yamcs.xtce.CustomAlgorithm;
import org.yamcs.xtce.DataEncoding;

/**
 * A custom data encoder that converts provided binary to encoded binary in the reverse byte order.
 */
public class ReverseBinaryEncoder extends AbstractDataEncoder {

    public ReverseBinaryEncoder(CustomAlgorithm alg, AlgorithmExecutionContext ctx) {
        // Constructor required
    }

    @Override
    public void encodeRaw(DataEncoding de, Value rawValue, BitBuffer buffer, TcProcessingContext ctx) {
        var bytes = rawValue.getBinaryValue();

        var reversedCopy = new byte[bytes.length];
        for (int i = 0, j = bytes.length - 1; i < bytes.length; i++, j--) {
            reversedCopy[i] = bytes[j];
        }

        buffer.put(reversedCopy);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy