com.dingwang.netty.decoder.TimeDecoder.java Source code

Java tutorial

Introduction

Here is the source code for com.dingwang.netty.decoder.TimeDecoder.java

Source

/*
 * Copyright 2016 Zhongan.com All right reserved. This software is the
 * confidential and proprietary information of Zhongan.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Zhongan.com.
 */
package com.dingwang.netty.decoder;

import java.util.List;

import com.dingwang.netty.pojo.UnixTime;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

/**
 * TimeDecoder.java??TODO ??
 * 
 * @author wangding_91@163.com 2016218 ?5:18:20
 */
public class TimeDecoder extends ByteToMessageDecoder {

    static {
        System.out.println("11111");
    }

    /*
     * (non-Javadoc)
     * @see io.netty.handler.codec.ByteToMessageDecoder#decode(io.netty.channel.
     * ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
     */
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

        System.out.println("==========decode");

        if (in.readableBytes() < 4) {
            return;
        }

        out.add(new UnixTime(in.readInt()));
    }

}