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

org.jetlinks.rule.engine.defaults.codec.BooleanCodec 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.rule.engine.api.Payload;
import org.jetlinks.rule.engine.api.codec.Codec;

import javax.annotation.Nonnull;

public class BooleanCodec implements Codec {

    public static BooleanCodec INSTANCE = new BooleanCodec();

    private BooleanCodec() {

    }

    @Override
    public Boolean decode(@Nonnull Payload payload) {
        byte[] data = payload.bodyAsBytes();

        return data.length > 0 && data[0] > 0;
    }

    @Override
    public Payload encode(Boolean body) {
        return () -> Unpooled.wrappedBuffer(new byte[]{body ? (byte) 1 : 0});
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy