Example usage for io.netty.buffer ByteBuf getCharSequence

List of usage examples for io.netty.buffer ByteBuf getCharSequence

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf getCharSequence.

Prototype

public abstract CharSequence getCharSequence(int index, int length, Charset charset);

Source Link

Document

Gets a CharSequence with the given length at the given index.

Usage

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static Float textDecodeFLOAT4(int index, int len, ByteBuf buff) {
    // Todo optimize that
    CharSequence cs = buff.getCharSequence(index, len, StandardCharsets.UTF_8);
    return Float.parseFloat(cs.toString());
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static double textDecodeFLOAT8(int index, int len, ByteBuf buff) {
    // Todo optimize that
    CharSequence cs = buff.getCharSequence(index, len, StandardCharsets.UTF_8);
    return Double.parseDouble(cs.toString());
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static Number textDecodeNUMERIC(int index, int len, ByteBuf buff) {
    // Todo optimize that
    CharSequence cs = buff.getCharSequence(index, len, StandardCharsets.UTF_8);
    return Numeric.parse(cs.toString());
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static Interval textDecodeINTERVAL(int index, int len, ByteBuf buff) {
    CharSequence cs = buff.getCharSequence(index, len, StandardCharsets.UTF_8);
    String value = cs.toString();
    int years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0, microseconds = 0;
    final List<String> chunks = new ArrayList<>(7);
    int idx = 0;/*from  ww  w.  j  ava2 s  . co  m*/
    for (;;) {
        int newIdx = value.indexOf(' ', idx);
        if (newIdx == -1) {
            chunks.add(value.substring(idx));
            break;
        }
        chunks.add(value.substring(idx, newIdx));
        idx = newIdx + 1;
    }
    boolean hasTime = chunks.size() % 2 == 1;
    int dateChunkMax = hasTime ? chunks.size() - 1 : chunks.size();
    for (int i = 0; i < dateChunkMax; i += 2) {
        int val = Integer.parseInt(chunks.get(i));
        switch (chunks.get(i + 1)) {
        case "year":
        case "years":
            years = val;
            break;
        case "mon":
        case "mons":
            months = val;
            break;
        case "day":
        case "days":
            days = val;
            break;
        }
    }
    if (hasTime) {
        String timeChunk = chunks.get(chunks.size() - 1);
        boolean isNeg = timeChunk.charAt(0) == '-';
        if (isNeg)
            timeChunk = timeChunk.substring(1);
        int sidx = 0;
        for (;;) {
            int newIdx = timeChunk.indexOf(':', sidx);
            if (newIdx == -1) {
                int m = timeChunk.substring(sidx).indexOf('.');
                if (m == -1) {
                    // seconds without microseconds
                    seconds = isNeg ? -Integer.parseInt(timeChunk.substring(sidx))
                            : Integer.parseInt(timeChunk.substring(sidx));
                } else {
                    // seconds with microseconds
                    seconds = isNeg ? -Integer.parseInt(timeChunk.substring(sidx).substring(0, m))
                            : Integer.parseInt(timeChunk.substring(sidx).substring(0, m));
                    microseconds = isNeg ? -Integer.parseInt(timeChunk.substring(sidx).substring(m + 1))
                            : Integer.parseInt(timeChunk.substring(sidx).substring(m + 1));
                }
                break;
            }
            // hours
            if (sidx == 0) {
                hours = isNeg ? -Integer.parseInt(timeChunk.substring(sidx, newIdx))
                        : Integer.parseInt(timeChunk.substring(sidx, newIdx));
            } else {
                // minutes
                minutes = isNeg ? -Integer.parseInt(timeChunk.substring(sidx, newIdx))
                        : Integer.parseInt(timeChunk.substring(sidx, newIdx));
            }
            sidx = newIdx + 1;
        }
    }
    return new Interval(years, months, days, hours, minutes, seconds, microseconds);
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static String textDecodeCHAR(int index, int len, ByteBuf buff) {
    return buff.getCharSequence(index, len, StandardCharsets.UTF_8).toString();
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static String textDecodeVARCHAR(int index, int len, ByteBuf buff) {
    return buff.getCharSequence(index, len, StandardCharsets.UTF_8).toString();
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static String binaryDecodeVARCHAR(int index, int len, ByteBuf buff) {
    return buff.getCharSequence(index, len, StandardCharsets.UTF_8).toString();
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static String textDecodeBPCHAR(int index, int len, ByteBuf buff) {
    return buff.getCharSequence(index, len, StandardCharsets.UTF_8).toString();
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static String binaryDecodeBPCHAR(int index, int len, ByteBuf buff) {
    return buff.getCharSequence(index, len, StandardCharsets.UTF_8).toString();
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static String textdecodeTEXT(int index, int len, ByteBuf buff) {
    return buff.getCharSequence(index, len, StandardCharsets.UTF_8).toString();
}