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

The following examples show how to use io.vertx.core.buffer.Buffer#getString() . 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: PojoEventBusCodec.java    From raml-module-builder with Apache License 2.0 6 votes vote down vote up
@Override
public Object decodeFromWire(int position, Buffer buffer) {

  int _pos = position;

  // Length
  int clazzNameLength = buffer.getInt(_pos);
  String clazz = buffer.getString(_pos+=4, _pos+=clazzNameLength);

  // Jump 4 because getInt() == 4 bytes
  int dataLength = buffer.getInt(_pos+=4);

  String data = buffer.getString(_pos+=4, _pos+=dataLength);

  Object obj = null;
  try {
    obj = MAPPER.readValue(data, Class.forName(clazz));
  } catch (Exception e) {
    log.error(e.getMessage(), e);
  }

  // We can finally create custom message object
  return obj;
}
 
Example 2
Source File: JacksonCodec.java    From kyoko with MIT License 5 votes vote down vote up
@Override
public T decodeFromWire(final int pos, final Buffer buffer) {
    try {
        final int length = buffer.getInt(pos);
        final String rawJson = buffer.getString(pos + 4, pos + 4 + length);
        return JsonUtil.fromJSON(rawJson, type);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 3
Source File: CustomMessageCodec.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
public CustomMessage decodeFromWire(int position, Buffer buffer) {
    int length = buffer.getInt(position);
    JsonObject jsonMessage = new JsonObject(buffer.getString(position += 4, position + length));
    return new CustomMessage(jsonMessage.getString("message"));
}