io.deephaven.util.codec.StringBooleanMapCodec Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-codec-builtin Show documentation
Show all versions of deephaven-codec-builtin Show documentation
Codec Builtin: Deephaven builtin codec implementations
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.util.codec;
import io.deephaven.util.BooleanUtils;
import org.jetbrains.annotations.Nullable;
import java.nio.ByteBuffer;
/**
* ObjectCodec implementation for Maps of String to Boolean.
*
* Each map is encoded as an integer length, followed by UTF-8 encoded strings for each key and the value.
*
* A null map is represented as an array of zero bytes.
*/
@SuppressWarnings("unused")
public class StringBooleanMapCodec extends StringKeyedMapCodec {
public StringBooleanMapCodec(@Nullable String arguments) {
super(arguments);
}
@Override
int getValueSize() {
return Byte.BYTES;
}
@Override
Boolean decodeValue(ByteBuffer byteBuffer) {
return BooleanUtils.byteAsBoolean(byteBuffer.get());
}
@Override
void encodeValue(ByteBuffer scratch, Boolean value) {
scratch.put(BooleanUtils.booleanAsByte(value));
}
}