engine.io-server/src/main/java/io/socket/engineio/parser/ServerParser.java
/**
     * Decode a packet received from transport.
     *
     * @param data Data received from transport.
     * @return Packet decoded from data.
     */
Decode a packet received from transport.
@param data Data received from transport.
@return Packet decoded from data.
Decode a packet received from transport . @param data Data received from transport . @return Packet decoded from data .
public static Packet decodePacket(Object data) {
        if(data == null) {
            return err;
        }
        if(data instanceof String) {
            final String stringData = (String) data;
            if(stringData.charAt(0) == 'b') {
                Packet<byte[]> packet = new Packet<>(packetsList.get(
                        Integer.parseInt(String.valueOf(stringData.charAt(1)))));
                packet.data = Base64.getDecoder().decode(stringData.substring(2));
                return packet;
            } else {
                Packet<String> packet = new Packet<>(packetsList.get(
                        Integer.parseInt(String.valueOf(stringData.charAt(0)))));
                packet.data = stringData.substring(1);
                return packet;
            }
        } else if(data instanceof byte[]) {
            final byte[] byteData = (byte[]) data;
            Packet<byte[]> packet = new Packet<>(packetsList.get((int) byteData[0]));
            packet.data = new byte[byteData.length - 1];
            System.arraycopy(byteData, 1, packet.data, 0, packet.data.length);
            return packet;
        } else {
            throw new IllegalArgumentException("Invalid type for data: " + data.getClass().getSimpleName());
        }
    }
public static Packet decodePacket ( Object data ) { if ( data == null ) { return err ; } if ( data instanceof String ) { final String stringData = ( String ) data ; if ( stringData . charAt ( 0 ) == 'b' ) { Packet < byte [ ] > packet = new Packet < > ( packetsList . get ( Integer . parseInt ( String . valueOf ( stringData . charAt ( 1 ) ) ) ) ) ; packet . data = Base64 . getDecoder ( ) . decode ( stringData . substring ( 2 ) ) ; return packet ; } else { Packet < String > packet = new Packet < > ( packetsList . get ( Integer . parseInt ( String . valueOf ( stringData . charAt ( 0 ) ) ) ) ) ; packet . data = stringData . substring ( 1 ) ; return packet ; } } else if ( data instanceof byte [ ] ) { final byte [ ] byteData = ( byte [ ] ) data ; Packet < byte [ ] > packet = new Packet < > ( packetsList . get ( ( int ) byteData [ 0 ] ) ) ; packet . data = new byte [ byteData . length - 1 ] ; System . arraycopy ( byteData , 1 , packet . data , 0 , packet . data . length ) ; return packet ; } else { throw new IllegalArgumentException ( "Invalid type for data: " + data . getClass ( ) . getSimpleName ( ) ) ; } }
Decode a packet received from transport.
Decode a packet received from transport .