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

io.deephaven.engine.table.impl.sources.regioned.decoder.EncodedStringDecoder Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.engine.table.impl.sources.regioned.decoder;

import io.deephaven.base.string.EncodingInfo;
import io.deephaven.base.string.cache.StringCache;
import io.deephaven.engine.util.string.StringUtils;
import io.deephaven.util.codec.ObjectDecoder;
import org.jetbrains.annotations.NotNull;

public class EncodedStringDecoder implements ObjectDecoder {
    private final StringCache cache;
    private final EncodingInfo encodingInfo;

    public EncodedStringDecoder(Class dataType, EncodingInfo encodingInfo) {
        this.cache = StringUtils.getStringCache(dataType);
        this.encodingInfo = encodingInfo;
    }

    public EncodedStringDecoder(StringCache cache, EncodingInfo encodingInfo) {
        this.cache = cache;
        this.encodingInfo = encodingInfo;
    }

    @Override
    public final int expectedObjectWidth() {
        return VARIABLE_WIDTH_SENTINEL;
    }

    @Override
    public final STRING_LIKE_TYPE decode(@NotNull final byte[] data, final int offset, final int length) {
        if (length == 0) {
            return null;
        }
        if (length == 1 && data[0] == 0) {
            return cache.getEmptyString();
        }
        return cache.getCachedString(new String(data, offset, length, encodingInfo.getCharset()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy