Java Code Examples for io.vertx.core.buffer.Buffer#getLong()

The following examples show how to use io.vertx.core.buffer.Buffer#getLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UUIDAccessor.java    From vertx-jooq with MIT License 5 votes vote down vote up
public static UUID getUUID(Row row, String field) {
    Buffer buffer = row.getBuffer(field);
    if (buffer == null) {
        return null;
    }
    return new UUID(buffer.getLong(0), buffer.getLong(8));
}
 
Example 2
Source File: ExtendedSessionImpl.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Override
public int readFromBuffer(int pos, Buffer buffer) {
    createdAt = buffer.getLong(pos);
    return ((ClusterSerializable) delegate).readFromBuffer(pos + 8, buffer);
}
 
Example 3
Source File: ExtendedSessionImpl.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Override
public int readFromBuffer(int pos, Buffer buffer) {
    createdAt = buffer.getLong(pos);
    return ((ClusterSerializable) delegate).readFromBuffer(pos + 8, buffer);
}
 
Example 4
Source File: SharedDataSessionImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
private int readDataFromBuffer(int pos, Buffer buffer) {
  try {
    int entries = buffer.getInt(pos);
    pos += 4;
    if (entries > 0) {
      final Map<String, Object> data = new ConcurrentHashMap<>(entries);

      for (int i = 0; i < entries; i++) {
        int keylen = buffer.getInt(pos);
        pos += 4;
        byte[] keyBytes = buffer.getBytes(pos, pos + keylen);
        pos += keylen;
        String key = new String(keyBytes, UTF8);
        byte type = buffer.getByte(pos++);
        Object val;
        switch (type) {
          case TYPE_LONG:
            val = buffer.getLong(pos);
            pos += 8;
            break;
          case TYPE_INT:
            val = buffer.getInt(pos);
            pos += 4;
            break;
          case TYPE_SHORT:
            val = buffer.getShort(pos);
            pos += 2;
            break;
          case TYPE_BYTE:
            val = buffer.getByte(pos);
            pos++;
            break;
          case TYPE_FLOAT:
            val = buffer.getFloat(pos);
            pos += 4;
            break;
          case TYPE_DOUBLE:
            val = buffer.getDouble(pos);
            pos += 8;
            break;
          case TYPE_CHAR:
            short s = buffer.getShort(pos);
            pos += 2;
            val = (char) s;
            break;
          case TYPE_BOOLEAN:
            byte b = buffer.getByte(pos);
            pos++;
            val = b == 1;
            break;
          case TYPE_STRING:
            int len = buffer.getInt(pos);
            pos += 4;
            byte[] bytes = buffer.getBytes(pos, pos + len);
            val = new String(bytes, UTF8);
            pos += len;
            break;
          case TYPE_BUFFER:
            len = buffer.getInt(pos);
            pos += 4;
            bytes = buffer.getBytes(pos, pos + len);
            val = Buffer.buffer(bytes);
            pos += len;
            break;
          case TYPE_BYTES:
            len = buffer.getInt(pos);
            pos += 4;
            val = buffer.getBytes(pos, pos + len);
            pos += len;
            break;
          case TYPE_CLUSTER_SERIALIZABLE:
            int classNameLen = buffer.getInt(pos);
            pos += 4;
            byte[] classNameBytes = buffer.getBytes(pos, pos + classNameLen);
            pos += classNameLen;
            String className = new String(classNameBytes, UTF8);
            Class<?> clazz = Utils.getClassLoader().loadClass(className);
            if (!ClusterSerializable.class.isAssignableFrom(clazz)) {
              throw new ClassCastException(new String(classNameBytes) + " is not assignable from ClusterSerializable");
            }
            ClusterSerializable obj = (ClusterSerializable) clazz.getDeclaredConstructor().newInstance();
            pos = obj.readFromBuffer(pos, buffer);
            val = obj;
            break;
          default:
            throw new IllegalStateException("Invalid serialized type: " + type);
        }
        data.put(key, val);
      }
      setData(data);
    }
    return pos;
  } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
    throw new VertxException(e);
  }
}