RuneHive-Game
Loading...
Searching...
No Matches
ServiceResponseEncoder.java
Go to the documentation of this file.
1package dev.advo.fs.net.service;
2
3import org.jboss.netty.buffer.ChannelBuffer;
4import org.jboss.netty.buffer.ChannelBuffers;
5import org.jboss.netty.channel.Channel;
6import org.jboss.netty.channel.ChannelHandlerContext;
7import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
8
9import dev.advo.fs.fs.IndexedFileSystem;
10
11public final class ServiceResponseEncoder extends OneToOneEncoder {
12
13 @Override
14 protected Object encode(ChannelHandlerContext ctx, Channel c, Object msg) throws Exception {
15 if (msg instanceof ServiceResponse) {
16 byte[] bytes = IndexedFileSystem.bytes;
17 ChannelBuffer buf = ChannelBuffers.buffer(bytes.length+4);
18 buf.writeInt(bytes.length);
19 buf.writeBytes(bytes);
20
21 System.out.println("Responding with packet to client with size " + bytes.length);
22 return buf;
23 }
24 return msg;
25 }
26}
A file system based on top of the operating system's file system.
Object encode(ChannelHandlerContext ctx, Channel c, Object msg)