Example usage for io.netty.buffer ByteBufUtil writeAscii

List of usage examples for io.netty.buffer ByteBufUtil writeAscii

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufUtil writeAscii.

Prototype

public static int writeAscii(ByteBuf buf, CharSequence seq) 

Source Link

Document

Encode a CharSequence in <a href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> and write it to a ByteBuf .

Usage

From source file:eu.jangos.realm.network.packet.server.query.SMSG_GUILD_QUERY.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:        
    // 2b - 2b - 4b - ?b - [?b*10] - 4b - 4b - 4b - 4b - 4b
    // Size (Little Endian) - Opcode (Big Endian) - Guild ID - Guild name - [x Ranks name] - emblem style
    // - emblem color - border style - border color - background color

    int strSize = 0;
    strSize += this.name.length();
    for (String rankName : this.listRanks) {
        strSize += rankName.length();/*from w  w  w  . j  a  va  2  s  .co  m*/
    }

    buf.writeShort(this.size + strSize);
    buf.writeShort(this.code.getValue());
    buf.writeInt(this.id);
    ByteBufUtil.writeAscii(buf, this.name);
    buf.writeByte((byte) 0); // End of string

    // We add ranks name.
    for (int i = 0; i < GUILD_RANKS_MAX_COUNT; i++) {
        if (i < this.listRanks.size())
            ByteBufUtil.writeAscii(buf, this.listRanks.get(i));
        buf.writeByte((byte) 0); // End of string
    }

    buf.writeInt(this.emblemStyle);
    buf.writeInt(this.emblemColor);
    buf.writeInt(this.borderlStyle);
    buf.writeInt(this.borderColor);
    buf.writeInt(this.backgroundColor);
}

From source file:eu.jangos.realm.network.packet.server.query.SMSG_ITEM_QUERY_SINGLE.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:        
    // 2b - 2b - 
    // Size (Little Endian) - Opcode (Big Endian) -                 

    ItemService itemService = ItemServiceFactory.getInstance();

    buf.writeShort(this.size + this.item.getName().length() + this.item.getDescription().length());
    buf.writeShort(this.code.getValue());

    buf.writeInt(this.item.getEntry());
    buf.writeInt(this.item.getItemsubclass().getItemclass().getId());
    buf.writeInt(this.item.getItemsubclass().getId().getId());
    // 12/*  w w w  . ja  v  a2 s .  c  o  m*/
    ByteBufUtil.writeAscii(buf, this.item.getName());
    buf.writeByte(0); // End of string
    buf.writeByte(0); // End of string 2
    buf.writeByte(0); // End of string 3
    buf.writeByte(0); // End of string 4
    // 16 + ?
    buf.writeInt(this.item.getDisplayid());
    buf.writeInt(this.item.getItemquality().getId());
    buf.writeInt(this.item.getFlags());
    buf.writeInt(this.item.getBuyprice());
    buf.writeInt(this.item.getSellprice());
    buf.writeInt(this.item.getInventorytype().getId());
    buf.writeInt(this.item.getAllowableclass());
    buf.writeInt(this.item.getAllowablerace());
    buf.writeInt(this.item.getItemlevel());
    buf.writeInt(this.item.getRequiredlevel());
    buf.writeInt(this.item.getRequiredskill());
    buf.writeInt(this.item.getRequiredskillrank());
    buf.writeInt(this.item.getRequiredhonorrank());
    buf.writeInt(this.item.getRequiredcityrank());
    buf.writeInt(this.item.getRequiredreputationfaction());
    buf.writeInt((this.item.getRequiredreputationfaction() > 0 ? this.item.getRequiredreputationrank() : 0));
    buf.writeInt(this.item.getMaxcount());
    buf.writeInt(this.item.getStackable());
    buf.writeInt(this.item.getContainerslots());
    // 92        

    buf.writeInt(this.item.getStatType1());
    buf.writeInt(this.item.getStatValue1());
    buf.writeInt(this.item.getStatType2());
    buf.writeInt(this.item.getStatValue2());
    buf.writeInt(this.item.getStatType3());
    buf.writeInt(this.item.getStatValue3());
    buf.writeInt(this.item.getStatType4());
    buf.writeInt(this.item.getStatValue4());
    buf.writeInt(this.item.getStatType5());
    buf.writeInt(this.item.getStatValue5());
    buf.writeInt(this.item.getStatType6());
    buf.writeInt(this.item.getStatValue6());
    buf.writeInt(this.item.getStatType7());
    buf.writeInt(this.item.getStatValue7());
    buf.writeInt(this.item.getStatType8());
    buf.writeInt(this.item.getStatValue8());
    buf.writeInt(this.item.getStatType9());
    buf.writeInt(this.item.getStatValue9());
    buf.writeInt(this.item.getStatType10());
    buf.writeInt(this.item.getStatValue10());
    // 172

    buf.writeFloat(this.item.getDmgMin1());
    buf.writeFloat(this.item.getDmgMax1());
    buf.writeInt(this.item.getDmgType1());
    buf.writeFloat(this.item.getDmgMin2());
    buf.writeFloat(this.item.getDmgMax2());
    buf.writeInt(this.item.getDmgType2());
    buf.writeFloat(this.item.getDmgMin3());
    buf.writeFloat(this.item.getDmgMax3());
    buf.writeInt(this.item.getDmgType3());
    buf.writeFloat(this.item.getDmgMin4());
    buf.writeFloat(this.item.getDmgMax4());
    buf.writeInt(this.item.getDmgType4());
    buf.writeFloat(this.item.getDmgMin5());
    buf.writeFloat(this.item.getDmgMax5());
    buf.writeInt(this.item.getDmgType5());
    // 232

    // resistances
    buf.writeInt(this.item.getArmor());
    buf.writeInt(this.item.getHolyRes());
    buf.writeInt(this.item.getFireRes());
    buf.writeInt(this.item.getNatureRes());
    buf.writeInt(this.item.getFrostRes());
    buf.writeInt(this.item.getShadowRes());
    buf.writeInt(this.item.getArcaneRes());
    // 260

    buf.writeInt(this.item.getDelay());
    buf.writeInt(this.item.getAmmoType());
    buf.writeFloat(this.item.getRangedModRange());
    // 272

    // spells
    buf.writeInt(this.item.getSpellid1());
    buf.writeInt(this.item.getSpelltrigger1());
    buf.writeInt(this.item.getSpellcharges1());
    buf.writeInt(this.item.getSpellcooldown1());
    buf.writeInt(this.item.getSpellcategory1());
    buf.writeInt(this.item.getSpellcategorycooldown1());
    buf.writeInt(this.item.getSpellid2());
    buf.writeInt(this.item.getSpelltrigger2());
    buf.writeInt(this.item.getSpellcharges2());
    buf.writeInt(this.item.getSpellcooldown2());
    buf.writeInt(this.item.getSpellcategory2());
    buf.writeInt(this.item.getSpellcategorycooldown2());
    buf.writeInt(this.item.getSpellid3());
    buf.writeInt(this.item.getSpelltrigger3());
    buf.writeInt(this.item.getSpellcharges3());
    buf.writeInt(this.item.getSpellcooldown3());
    buf.writeInt(this.item.getSpellcategory3());
    buf.writeInt(this.item.getSpellcategorycooldown3());
    buf.writeInt(this.item.getSpellid4());
    buf.writeInt(this.item.getSpelltrigger4());
    buf.writeInt(this.item.getSpellcharges4());
    buf.writeInt(this.item.getSpellcooldown4());
    buf.writeInt(this.item.getSpellcategory4());
    buf.writeInt(this.item.getSpellcategorycooldown4());
    buf.writeInt(this.item.getSpellid5());
    buf.writeInt(this.item.getSpelltrigger5());
    buf.writeInt(this.item.getSpellcharges5());
    buf.writeInt(this.item.getSpellcooldown5());
    buf.writeInt(this.item.getSpellcategory5());
    buf.writeInt(this.item.getSpellcategorycooldown5());
    // 392

    buf.writeInt(this.item.getBonding());
    // 396
    ByteBufUtil.writeAscii(buf, this.item.getDescription());
    buf.writeByte(0); // end of string
    // 397 + ?                    
    buf.writeInt(this.item.getPagetext().getId());
    buf.writeInt(this.item.getLanguageid());
    buf.writeInt(this.item.getPagematerial());
    buf.writeInt(this.item.getStartquest());
    buf.writeInt(this.item.getLockid());
    buf.writeInt(this.item.getMaterial());
    buf.writeInt(this.item.getSheath());
    buf.writeInt(this.item.getRandomproperty());
    buf.writeInt(this.item.getBlock());
    buf.writeInt(this.item.getItemset());
    buf.writeInt(this.item.getMaxdurability());
    buf.writeInt(this.item.getArea());
    buf.writeInt(this.item.getMap());
    buf.writeInt(this.item.getBagfamily());
    // 453
}

From source file:eu.jangos.realm.network.packet.server.query.SMSG_NAME_QUERY.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // If player exists:
    // 2b - 2b - ?b - ?b - 4b - 4b - 4b
    // Size (Little Endian) - Opcode (Big Endian) - Player name - Realm name - race - gender - class                

    buf.writeShort(this.size + this.name.length() + this.realm.length() + 2);
    buf.writeShort(this.code.getValue());
    ByteBufUtil.writeAscii(buf, this.name);
    buf.writeByte((byte) 0); // End of string
    ByteBufUtil.writeAscii(buf, this.realm);
    buf.writeByte((byte) 0); // End of string
    buf.writeInt(this.race.getValue());
    buf.writeInt(this.gender.getValue());
    buf.writeInt(this.prof.getValue());
}

From source file:eu.jangos.realm.network.packet.server.query.SMSG_PAGE_TEXT_QUERY.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:        
    // 2b - 2b - 4b - ?b
    // Size (Little Endian) - Opcode (Big Endian) - Page ID - Page Text             

    buf.writeShort(this.size + this.text.length());
    buf.writeShort(this.code.getValue());
    buf.writeInt(this.id);
    ByteBufUtil.writeAscii(buf, this.text);
    buf.writeByte((byte) 0); // End of string        
}

From source file:eu.jangos.realm.network.packet.server.query.SMSG_PET_NAME_QUERY.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b - 4b - ?b - 4b
    // Size (Little Endian) - Opcode (Big Endian) - Pet number - Pet name - Pet Field                

    buf.writeShort(this.size + this.name.length() + 1);
    buf.writeShort(this.code.getValue());
    buf.writeInt(this.number);
    ByteBufUtil.writeAscii(buf, this.name);
    buf.writeByte((byte) 0); // End of string
    buf.writeInt(this.field);
}

From source file:example.http2.helloworld.frame.server.HelloWorldHttp2Handler.java

License:Apache License

/**
 * If receive a frame with end-of-stream set, send a pre-canned response.
 *//*from   w  w  w . j a v a2s .  com*/
private static void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) throws Exception {
    if (headers.isEndStream()) {
        ByteBuf content = ctx.alloc().buffer();
        content.writeBytes(RESPONSE_BYTES.duplicate());
        ByteBufUtil.writeAscii(content, " - via HTTP/2");
        sendResponse(ctx, headers.stream(), content);
    }
}

From source file:example.http2.helloworld.multiplex.server.HelloWorldHttp2Handler.java

License:Apache License

/**
 * If receive a frame with end-of-stream set, send a pre-canned response.
 *///from w ww.  java 2 s.com
private static void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) throws Exception {
    if (headers.isEndStream()) {
        ByteBuf content = ctx.alloc().buffer();
        content.writeBytes(RESPONSE_BYTES.duplicate());
        ByteBufUtil.writeAscii(content, " - via HTTP/2");
        sendResponse(ctx, content);
    }
}

From source file:example.http2.helloworld.server.HelloWorldHttp1Handler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
    if (HttpUtil.is100ContinueExpected(req)) {
        ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
    }//from ww  w  .j  a  v a2 s .  c  o  m
    boolean keepAlive = HttpUtil.isKeepAlive(req);

    ByteBuf content = ctx.alloc().buffer();
    content.writeBytes(HelloWorldHttp2Handler.RESPONSE_BYTES.duplicate());
    ByteBufUtil.writeAscii(content, " - via " + req.protocolVersion() + " (" + establishApproach + ")");

    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
    response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
    response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());

    if (!keepAlive) {
        ctx.write(response).addListener(ChannelFutureListener.CLOSE);
    } else {
        response.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE);
        ctx.write(response);
    }
}

From source file:http2.server.HelloWorldHttp1Handler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
    logger.info("HTTP 1.1");
    if (HttpUtil.is100ContinueExpected(req)) {
        ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
    }/* www.  ja v  a  2s . co  m*/
    boolean keepAlive = HttpUtil.isKeepAlive(req);

    ByteBuf content = ctx.alloc().buffer();
    content.writeBytes(HelloWorldHttp2Handler.RESPONSE_BYTES.duplicate());
    ByteBufUtil.writeAscii(content, " - via " + req.protocolVersion() + " (" + establishApproach + ")");

    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
    response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
    response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());

    if (!keepAlive) {
        ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
    } else {
        response.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE);
        ctx.writeAndFlush(response);
    }
}

From source file:http2.server.HelloWorldHttp2Handler.java

License:Apache License

@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding,
        boolean endOfStream) {
    logger.info("onHeaderRead, send hello");
    if (endOfStream) {
        ByteBuf content = ctx.alloc().buffer();
        content.writeBytes(RESPONSE_BYTES.duplicate());
        ByteBufUtil.writeAscii(content, " - via HTTP/2");
        sendResponse(ctx, streamId, content);
    }//from  w ww .  ja v a2  s. c om
}