use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project quarkus by quarkusio.
the class VertxRequestHandler method handle.
@Override
public void handle(RoutingContext routingContext) {
String path = routingContext.request().path();
if (path == null) {
routingContext.fail(404);
return;
}
// expects rootPath to end with '/'
if (!path.startsWith(rootPath)) {
routingContext.fail(404);
return;
}
path = path.substring(rootPath.length());
FunctionInvoker invoker = FunctionRecorder.registry.matchInvoker(path);
if (invoker == null) {
routingContext.fail(404);
return;
}
if (routingContext.request().method() == HttpMethod.GET) {
Object input = null;
if (invoker.hasInput()) {
QueryReader reader = (QueryReader) invoker.getBindingContext().get(QueryReader.class.getName());
try {
input = reader.readValue(routingContext.request().params().iterator());
} catch (Exception e) {
log.error("Failed to unmarshal input", e);
routingContext.fail(400);
return;
}
}
Object finalInput = input;
executor.execute(() -> {
dispatch(routingContext, invoker, finalInput);
});
} else if (routingContext.request().method() == HttpMethod.POST) {
routingContext.request().bodyHandler(buff -> {
Object input = null;
if (buff.length() > 0) {
ByteBufInputStream in = new ByteBufInputStream(buff.getByteBuf());
ObjectReader reader = (ObjectReader) invoker.getBindingContext().get(ObjectReader.class.getName());
try {
input = reader.readValue((InputStream) in);
} catch (Exception e) {
log.error("Failed to unmarshal input", e);
routingContext.fail(400);
return;
}
}
Object finalInput = input;
executor.execute(() -> {
dispatch(routingContext, invoker, finalInput);
});
});
} else {
routingContext.fail(405);
log.error("Must be POST or GET for: " + invoker.getName());
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project Protocol by CloudburstMC.
the class BedrockPacketHelper_v332 method readItem.
@Override
public ItemData readItem(ByteBuf buffer, BedrockSession session) {
int id = VarInts.readInt(buffer);
if (id == 0) {
// We don't need to read anything extra.
return ItemData.AIR;
}
int aux = VarInts.readInt(buffer);
int damage = (short) (aux >> 8);
if (damage == Short.MAX_VALUE)
damage = -1;
int count = aux & 0xff;
int nbtSize = buffer.readShortLE();
NbtMap compoundTag = null;
if (nbtSize > 0) {
try (NBTInputStream reader = NbtUtils.createReaderLE(new ByteBufInputStream(buffer.readSlice(nbtSize)))) {
compoundTag = (NbtMap) reader.readTag();
} catch (IOException e) {
throw new IllegalStateException("Unable to load NBT data", e);
}
} else if (nbtSize == -1) {
int tagCount = buffer.readUnsignedByte();
if (tagCount != 1)
throw new IllegalArgumentException("Expected 1 tag but got " + tagCount);
try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
compoundTag = (NbtMap) reader.readTag();
} catch (IOException e) {
throw new IllegalStateException("Unable to load NBT data", e);
}
}
String[] canPlace = new String[VarInts.readInt(buffer)];
for (int i = 0; i < canPlace.length; i++) {
canPlace[i] = this.readString(buffer);
}
String[] canBreak = new String[VarInts.readInt(buffer)];
for (int i = 0; i < canBreak.length; i++) {
canBreak[i] = this.readString(buffer);
}
return ItemData.builder().id(id).damage(damage).count(count).tag(compoundTag).canPlace(canPlace).canBreak(canBreak).build();
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project Protocol by CloudburstMC.
the class BedrockPacketHelper_v340 method readItem.
@Override
public ItemData readItem(ByteBuf buffer, BedrockSession session) {
int id = VarInts.readInt(buffer);
if (id == 0) {
// We don't need to read anything extra.
return ItemData.AIR;
}
int aux = VarInts.readInt(buffer);
int damage = (short) (aux >> 8);
if (damage == Short.MAX_VALUE)
damage = -1;
int count = aux & 0xff;
int nbtSize = buffer.readShortLE();
NbtMap compoundTag = null;
if (nbtSize > 0) {
try (NBTInputStream reader = NbtUtils.createReaderLE(new ByteBufInputStream(buffer.readSlice(nbtSize)))) {
compoundTag = (NbtMap) reader.readTag();
} catch (IOException e) {
throw new IllegalStateException("Unable to load NBT data", e);
}
} else if (nbtSize == -1) {
int tagCount = buffer.readUnsignedByte();
if (tagCount != 1)
throw new IllegalArgumentException("Expected 1 tag but got " + tagCount);
try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
compoundTag = (NbtMap) reader.readTag();
} catch (IOException e) {
throw new IllegalStateException("Unable to load NBT data", e);
}
}
String[] canPlace = new String[VarInts.readInt(buffer)];
for (int i = 0; i < canPlace.length; i++) {
canPlace[i] = this.readString(buffer);
}
String[] canBreak = new String[VarInts.readInt(buffer)];
for (int i = 0; i < canBreak.length; i++) {
canBreak[i] = this.readString(buffer);
}
long blockingTicks = 0;
if (this.isBlockingItem(id, session)) {
blockingTicks = VarInts.readLong(buffer);
}
return ItemData.builder().id(id).damage(damage).count(count).tag(compoundTag).canPlace(canPlace).canBreak(canBreak).blockingTicks(blockingTicks).build();
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project Protocol by CloudburstMC.
the class BedrockPacketHelper_v291 method readItem.
@Override
public ItemData readItem(ByteBuf buffer, BedrockSession session) {
Preconditions.checkNotNull(buffer, "buffer");
int id = VarInts.readInt(buffer);
if (id == 0) {
// We don't need to read anything extra.
return ItemData.AIR;
}
int aux = VarInts.readInt(buffer);
int damage = (short) (aux >> 8);
if (damage == Short.MAX_VALUE)
damage = -1;
int count = aux & 0xff;
short nbtSize = buffer.readShortLE();
NbtMap compoundTag = null;
if (nbtSize > 0) {
try (NBTInputStream reader = NbtUtils.createReaderLE(new ByteBufInputStream(buffer.readSlice(nbtSize)))) {
Object tag = reader.readTag();
if (tag instanceof NbtMap) {
compoundTag = (NbtMap) tag;
}
} catch (IOException e) {
throw new IllegalStateException("Unable to load NBT data", e);
}
}
String[] canPlace = readArray(buffer, new String[0], this::readString);
String[] canBreak = readArray(buffer, new String[0], this::readString);
return ItemData.builder().id(id).damage(damage).count(count).tag(compoundTag).canPlace(canPlace).canBreak(canBreak).build();
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project yamcs by yamcs.
the class WebSocketFrameHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext nettyContext, WebSocketFrame frame) throws Exception {
ClientMessage message;
if (protobuf) {
try (InputStream in = new ByteBufInputStream(frame.content())) {
message = ClientMessage.newBuilder().mergeFrom(in).build();
}
} else {
String json = frame.content().toString(StandardCharsets.UTF_8);
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
String messageType = obj.get("type").getAsString();
switch(messageType) {
case "state":
message = jsonToClientMessage(obj, null);
break;
case "cancel":
message = jsonToClientMessage(obj, CancelOptions.getDescriptor());
break;
default:
Topic topic = matchTopic(messageType);
if (topic == null) {
message = jsonToClientMessage(obj, null);
break;
}
message = jsonToClientMessage(obj, topic.getRequestPrototype().getDescriptorForType());
}
}
try {
switch(message.getType()) {
case "state":
dumpState(nettyContext);
break;
case "cancel":
cancelCall(nettyContext, message);
break;
default:
Topic topic = matchTopic(message.getType());
if (topic == null) {
throw new NotFoundException("No topic '" + message.getType() + "'");
}
if (message.getCall() > 0) {
streamToExistingCall(nettyContext, message, topic);
} else {
startNewContext(nettyContext, message, topic);
}
}
} catch (HttpException e) {
Reply reply = Reply.newBuilder().setReplyTo(message.getId()).setException(e.toMessage()).build();
writeMessage(nettyContext, ServerMessage.newBuilder().setType("reply").setData(Any.pack(reply, HttpServer.TYPE_URL_PREFIX)).build());
}
}
Aggregations