code: public static byte[] encodeToBinary(SecretShare share) {
          if (share.getN() < 0 || share.getN() > 255) {
              throw new IllegalArgumentException("Invalid share number, must be between 0 and 255");
          }
  
          byte[] shareData = share.getShare().toByteArray();
          byte[] primeData = share.getPrime().toByteArray();
          byte n = new Integer(share.getN()).byteValue();
  
          int len = 9 + SIGNATURE.length + shareData.length + primeData.length;
  
          ByteBuffer bb = ByteBuffer.allocate(len);
          bb.put(SIGNATURE);
          bb.put(n);
          bb.putInt(shareData.length);
          bb.put(shareData);
          bb.putInt(primeData.length);
          bb.put(primeData);
  
          assert bb.position() == bb.capacity();
          assert bb.hasArray();
  
          return bb.array();
      }
docs: Serialize secret share to binary message format. The message consists of the following fields:
  <ul>
  <li>header (ASCII string "SS")</li>
  <li>single byte indicating the ordinal number of this specific share in the series</li>
  <li>single integer (four bytes) indicating the length of the share data</li>
  <li>variable number of bytes (see previous item) representing share data</li>
  <li>single integer (four bytes) indicating the length of the prime data</li>
  <li>variable number of bytes (see previous item) representing prime data</li>
  </ul>
  
  @param share secret share to serialize
  @return byte array representing serialized secret share