private void serializeProperty(
     NFBuildGraphNode node,
     NFPropertySpec propertySpec,
     int connectionModelIndex,
     ByteArrayBuffer toBuffer) {
   if (propertySpec.isMultiple()) {
     serializeMultipleProperty(node, propertySpec, connectionModelIndex, toBuffer);
   } else {
     int connection = node.getConnection(connectionModelIndex, propertySpec);
     if (connection == -1) {
       toBuffer.writeByte((byte) 0x80);
     } else {
       toBuffer.writeVInt(connection);
     }
   }
 }
  private void serializeMultipleProperty(
      NFBuildGraphNode node,
      NFPropertySpec propertySpec,
      int connectionModelIndex,
      ByteArrayBuffer toBuffer) {
    OrdinalSet connections = node.getConnectionSet(connectionModelIndex, propertySpec);

    int numBitsInBitSet = buildGraphNodeCache.numNodes(propertySpec.getToNodeType());
    int bitSetSize = ((numBitsInBitSet - 1) / 8) + 1;

    if (connections.size() < bitSetSize) {
      if (propertySpec.isHashed()) {
        hashedPropertyBuilder.buildProperty(connections);
        if (fieldBuffer.length() < bitSetSize) {
          int log2BytesUsed = 32 - Integer.numberOfLeadingZeros((int) fieldBuffer.length());
          toBuffer.writeByte((byte) log2BytesUsed);
          toBuffer.write(fieldBuffer);
          fieldBuffer.reset();
          return;
        }
      } else {
        compactPropertyBuilder.buildProperty(connections);
        if (fieldBuffer.length() < bitSetSize) {
          toBuffer.writeVInt((int) fieldBuffer.length());
          toBuffer.write(fieldBuffer);
          fieldBuffer.reset();
          return;
        }
      }

      fieldBuffer.reset();
    }

    bitSetPropertyBuilder.buildProperty(connections, numBitsInBitSet);
    toBuffer.writeByte((byte) 0x80);
    toBuffer.write(fieldBuffer);
    fieldBuffer.reset();
  }