All pastes #402843 Raw Edit

Anonymous

public java v1 · immutable
·published 2007-03-20 00:59 UTC
rendered paste body
public void _OLDparse(byte[] b) {        int pos = 0; //Current byte position        byte[] cur; //Current byte chunk        int len = b.length;        this.length = b.length;                //Get the ID if not a section        if (!(this instanceof PacketPart)) {            byte[] idbytes = new byte[2];            System.arraycopy(b, 0, idbytes, 0, 2);            int idd = new _Word(null).decode(idbytes).intValue();            pos += 2;        }                /** If the packet isn't dynamic, parsing it is pretty simple. */        if (!dynamic) {            for (Type t: struct) {                cur = new byte[t.size()];                System.out.println("Parsing: " + t.toString());                System.arraycopy(b, pos, cur, 0, t.size());                t.decode(cur);                pos += t.size();            }        } else {            DynamicSection ds = null;            Packet dinst = null;            try {                dinst = (Packet) dynamicClass.newInstance();            } catch (InstantiationException ex) {                ex.printStackTrace();            } catch (IllegalAccessException ex) {                ex.printStackTrace();            }                        try {                ds = new DynamicSection(this, (Packet) dynamicClass.newInstance());            } catch (InstantiationException ex) {                ex.printStackTrace();            } catch (IllegalAccessException ex) {                ex.printStackTrace();            }            int dlen = ds.size();                        //Parse as normal, until we run into a dynamic part            for (Type t: struct) {                if (!(t instanceof DynamicSection)) {                    cur = new byte[t.size()];                    System.arraycopy(b, pos, cur, 0, t.size());                    t.decode(cur);                    pos += t.size();                } else {                    //Sometimes, a dynamic packet will have no dynamic part!                    if (pos + dlen > len) {                        //No more room for any dynamic parts.                        break;                    } else {                        try {                            //We're good, so we parse it.                            while (true) {                                DynamicSection nds = new DynamicSection(this, (Packet) dynamicClass.newInstance());                                cur = new byte[t.size()];                                System.arraycopy(b, pos, cur, 0, t.size());                                nds.decode(cur);                                dynamicParts.add(nds);                                pos += t.size();                                                                //Okay, now we have our first part.                                //Are there any more?                                if (pos + dlen > len) {                                    //Nope                                    break;                                } else {                                    continue;                                }                            }                            //Get the next [dynamic size] bytes                        /*    while (true) {                                byte[] dcur = new byte[dlen];                                System.arraycopy(b, pos, dcur, 0, t.size());                                DynamicSection nnds = new DynamicSection(this, (Packet) dynamicClass.newInstance());                                nds.decode(dcur);                                pos += dlen;                                                         if (pos + dlen > len) {                                    break; //No more parts                                } else {                                    continue; //More parts                                }                            }                        } */                        } catch (IllegalAccessException ex) {                            ex.printStackTrace();                        } catch (InstantiationException ex) {                            ex.printStackTrace();                        }                                            }                }            }        }    }