title: Java ByteBuffer equivalent in Swift 4
body: <p>I'm trying to convert my underneath Java (Android) code to Swift.
  I'm stuck at the part of the ByteBuffer.</p>
  
  <pre><code>private MqttMessage createMqttMessage(boolean encrypted, byte[] message) {
      /* add a zero-byte at the end just to be sure it's terminated although the payload is zero-padded */
      int padding = 16 - ((message.length) % 16);
  
      /* a zero-byte at the end of the JSON is required for determining the string's end */
      padding = padding == 0 ? 16 : padding;
  
      byte[] payload = new byte[message.length+padding];
  
      System.arraycopy(message, 0, payload, 0, message.length);
  
      /* FRAME_HEADER + JSON-payload + zero-byte + FRAME_TAIL_SIZE */
      int bufferSize = Constants.FRAME_HEADER_SIZE + payload.length + 1 + Constants.FRAME_TAIL_SIZE;
  
      ByteBuffer frame = ByteBuffer.allocate(bufferSize);
  
      /* The CC3220 is an ARM device, thus little-endian */
      frame.order(ByteOrder.LITTLE_ENDIAN);
  
      // message flags (uint8_t)
      byte flags = (byte) (encrypted ? Constants.FRAME_FLAG_ENCRYPTED : 0x0);
      // always use authentication
      flags |= Constants.FRAME_FLAG_AUTHENTICATED;
  
      frame.put(flags);
  
      // User token   (uint32_t)
      frame.putInt((int)this.mUserToken);
  </code></pre>
  
  <p>What's the equivalent of a ByteBuffer in Swift?</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>private func createMqttMessage(encrypted: Bool, message: [Int8]) {
  
      var padding:Int = 16 - ((message.count) % 16)
  
      padding = padding == 0 ? 16 : padding
  
      var payload:[Int8]
  
      payload = Array(message[0..&lt;0+message.count])
  
      let bufferSize = Constants.FRAME_HEADER_SIZE + payload.count + 1 + Constants.FRAME_TAIL_SIZE
  </code></pre>