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

org.jetlinks.rule.engine.defaults.codec.FloatCodec Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package org.jetlinks.rule.engine.defaults.codec;

import io.netty.buffer.Unpooled;
import org.jetlinks.core.utils.BytesUtils;
import org.jetlinks.rule.engine.api.Payload;
import org.jetlinks.rule.engine.api.codec.Codec;

import javax.annotation.Nonnull;

public class FloatCodec implements Codec {

    public static FloatCodec INSTANCE = new FloatCodec();

    private FloatCodec() {

    }

    @Override
    public Float decode(@Nonnull Payload payload) {
        return BytesUtils.beToFloat(payload.bodyAsBytes());
    }

    @Override
    public Payload encode(Float body) {
        return () -> Unpooled.wrappedBuffer(BytesUtils.floatToBe(body));
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy