Example usage for io.vertx.core.buffer Buffer getShort

List of usage examples for io.vertx.core.buffer Buffer getShort

Introduction

In this page you can find the example usage for io.vertx.core.buffer Buffer getShort.

Prototype

short getShort(int pos);

Source Link

Document

Returns the short at position pos in the Buffer.

Usage

From source file:io.advantageous.qbit.vertx.BufferUtils.java

License:Apache License

public static String readString(final Buffer buffer, final int[] location) {

    final short size = buffer.getShort(location[0]);

    int start = location[0] + 2;
    int end = start + size;

    final String utf_8 = buffer.getString(start, end, StandardCharsets.UTF_8.displayName());

    location[0] = end;//w  w  w . j av a2 s  . c  o m

    return utf_8;
}

From source file:io.advantageous.qbit.vertx.BufferUtils.java

License:Apache License

public static MultiMap<String, String> readMap(Buffer buffer, int[] locationHolder) {

    int location = locationHolder[0];

    final short size = buffer.getShort(location);

    MultiMap<String, String> map = size > 0 ? new MultiMapImpl<>() : MultiMap.EMPTY;

    location += 2;/*from   w  w w . j  av a2 s . co m*/

    locationHolder[0] = location;

    for (int index = 0; index < size; index++) {

        String key = readString(buffer, locationHolder);
        location = locationHolder[0];

        short valuesSize = buffer.getShort(location);
        location += 2;

        locationHolder[0] = location;

        for (int valueIndex = 0; valueIndex < valuesSize; valueIndex++) {

            String value = readString(buffer, locationHolder);
            map.add(key, value);

        }

    }
    return map;
}