title: Preparing data in TLV8
body: <p>I'm writing a HomeKit (so perhaps Bluetooth) characteristic in TLV8 format. Apple doc says</p>
  
  <blockquote>
    <p>The value is an NSData object containing a set of one or more TLV8's,
    which are packed type-length-value items with an 8-bit type, 8-bit
    length, and N-byte value.</p>
  </blockquote>
  
  <p>According to Wikipeida a type-length value is</p>
  
  <blockquote>
    <p><strong>Type</strong></p>
    
    <p>A binary code, often simply alphanumeric, which indicates the kind of field that this part of the message represents; </p>
    
    <p><strong>Length</strong></p>
    
    <p>The size of the value field (typically in bytes); </p>
    
    <p><strong>Value</strong></p>
    
    <p>Variable-sized series of bytes which contains data for this part of the message.</p>
  </blockquote>
  
  <p>I have no idea how to pack one. I suppose I can write raw bytes to NSData, but what do I write for pad, if I need any padding, etc. So is there an example of how to do that?</p>