예제 #1
0
 public byte[] serialize() {
   if (nodeName.getLocalName() == null) throw new RuntimeException("Local name is null");
   final short id = getBroker().getSymbols().getSymbol(this);
   final byte idSizeType = Signatures.getSizeType(id);
   int prefixLen = 0;
   if (nodeName.needsNamespaceDecl()) {
     if (nodeName.getPrefix() != null && nodeName.getPrefix().length() > 0)
       prefixLen = UTF8.encoded(nodeName.getPrefix());
   }
   final int nodeIdLen = nodeId.size();
   final byte[] data =
       ByteArrayPool.getByteArray(
           LENGTH_SIGNATURE_LENGTH
               + NodeId.LENGTH_NODE_ID_UNITS
               + nodeIdLen
               + Signatures.getLength(idSizeType)
               + (nodeName.needsNamespaceDecl()
                   ? LENGTH_NS_ID + LENGTH_PREFIX_LENGTH + prefixLen
                   : 0)
               + value.UTF8Size());
   int pos = 0;
   data[pos] = (byte) (Signatures.Attr << 0x5);
   data[pos] |= idSizeType;
   data[pos] |= (byte) (attributeType << 0x2);
   if (nodeName.needsNamespaceDecl()) data[pos] |= 0x10;
   pos += StoredNode.LENGTH_SIGNATURE_LENGTH;
   ByteConversion.shortToByte((short) nodeId.units(), data, pos);
   pos += NodeId.LENGTH_NODE_ID_UNITS;
   nodeId.serialize(data, pos);
   pos += nodeIdLen;
   Signatures.write(idSizeType, id, data, pos);
   pos += Signatures.getLength(idSizeType);
   if (nodeName.needsNamespaceDecl()) {
     final short nsId = getBroker().getSymbols().getNSSymbol(nodeName.getNamespaceURI());
     ByteConversion.shortToByte(nsId, data, pos);
     pos += LENGTH_NS_ID;
     ByteConversion.shortToByte((short) prefixLen, data, pos);
     pos += LENGTH_PREFIX_LENGTH;
     if (nodeName.getPrefix() != null && nodeName.getPrefix().length() > 0)
       UTF8.encode(nodeName.getPrefix(), data, pos);
     pos += prefixLen;
   }
   value.UTF8Encode(data, pos);
   return data;
 }
예제 #2
0
 public byte[] serialize() {
   final int nodeIdLen = nodeId.size();
   byte[] data =
       ByteArrayPool.getByteArray(
           LENGTH_SIGNATURE_LENGTH + nodeIdLen + NodeId.LENGTH_NODE_ID_UNITS + cdata.UTF8Size());
   int pos = 0;
   data[pos] = (byte) (Signatures.Char << 0x5);
   pos += LENGTH_SIGNATURE_LENGTH;
   ByteConversion.shortToByte((short) nodeId.units(), data, pos);
   pos += NodeId.LENGTH_NODE_ID_UNITS;
   nodeId.serialize(data, pos);
   pos += nodeIdLen;
   cdata.UTF8Encode(data, pos);
   return data;
 }