public int getSize() { int size = 0; for (ArrayList<DACPNode> l : this.nodes.values()) { for (DACPNode n : l) { size += n.getSize(); } } return size; }
public void addNode(DACPNode n) { // Supports multiple nodes with the same tag ArrayList<DACPNode> l = this.nodes.get(n.getTag()); if (l == null) { l = new ArrayList<DACPNode>(); this.nodes.put(n.getTag(), l); } l.add(n); this.length++; }
public static DACPPacket create(byte[] source, int offset) { int pos = offset; DACPPacket pkt = new DACPPacket(); while (pos < (source.length - offset)) { DACPNode n = DACPNode.create(source, pos); pos += n.getSize(); pkt.addNode(n); } return pkt; }
public String toString(int depth) { StringBuffer os = new StringBuffer(); for (ArrayList<DACPNode> l : this.nodes.values()) { for (DACPNode n : l) { for (int i = 0; i < depth; i++) { os.append('\t'); } os.append(String.format("%s\n", n.toString())); } } return os.toString(); }
public byte[] serialize() { byte[] buffer; int size = this.getSize(); buffer = new byte[size]; int offset = 0; for (ArrayList<DACPNode> l : this.nodes.values()) { for (DACPNode n : l) { size = n.getSize(); System.arraycopy(n.serialize(), 0, buffer, offset, size); offset += size; } } return buffer; }