title: Writing directly to buffer of a bits field
body: <p>I am working on bits fields structure from ctypes in Python and I have a question.
  Is it possible to write directly to the buffer of the Packet Union below defined ?</p>
  
  <pre><code>from ctypes import c_uint8
  
  class PacketBits(ctypes.LittleEndianStructure):
    _fields_ = [
        # First byte
        ("a", ctypes.c_uint8, 4),
        ("b", ctypes.c_uint8, 3),
        ("c", ctypes.c_uint8, 1),
        # Second byte
        ("d", ctypes.c_uint8, 5),
        ("e", ctypes.c_uint8, 3),
        # Third byte
        ("f", ctypes.c_uint8, 4),
        ("g", ctypes.c_uint8, 4),
        # Fourth byte
        ("h", ctypes.c_uint8, 2),
        ("i", ctypes.c_uint8, 6),
        # Fifth byte
        ("j", ctypes.c_uint8, 4),
        ("k", ctypes.c_uint8, 3),
        ("l", ctypes.c_uint8, 1),
        # Sixth byte
        ("m", ctypes.c_uint8, 5),
        ("n", ctypes.c_uint8, 3),
        # Seventh byte
        ("o", ctypes.c_uint8, 4),
        ("p", ctypes.c_uint8, 4),
        # Eighth byte
        ("q", ctypes.c_uint8, 2),
        ("r", ctypes.c_uint8, 6),
    ]
  
  class Packet(ctypes.Union):
      _fields_ = [("bits", PacketBits),
                  ("binary_data", 8 * c_uint8)]
  </code></pre>
  
  <p>I ask this question because I need to parse a stream of 65 bytes with some bits definitions inside.</p>
  
  <p>I have tried to set it directly, with a bitarray, ... and all methods that I tried was unsuccesfull.</p>
  
  <p>Anyone have an idea ?</p>
  
  <p>Best regards.</p>
  
  <p>Johan</p>