示例#1
0
 public int getSize() {
   int size = 0;
   for (ArrayList<DACPNode> l : this.nodes.values()) {
     for (DACPNode n : l) {
       size += n.getSize();
     }
   }
   return size;
 }
示例#2
0
 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++;
 }
示例#3
0
 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;
 }
示例#4
0
 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();
 }
示例#5
0
 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;
 }