code: func (d *dataEncoder) encode(data []byte) (*bitset.Bitset, error) {
  	d.data = data
  	d.actual = nil
  	d.optimised = nil
  
  	if len(data) == 0 {
  		return nil, errors.New("no data to encode")
  	}
  
  	// Classify data into unoptimised segments.
  	d.classifyDataModes()
  
  	// Optimise segments.
  	err := d.optimiseDataModes()
  	if err != nil {
  		return nil, err
  	}
  
  	// Encode data.
  	encoded := bitset.New()
  	for _, s := range d.optimised {
  		d.encodeDataRaw(s.data, s.dataMode, encoded)
  	}
  
  	return encoded, nil
  }
docs: // encode data as one or more segments and return the encoded data.
  //
  // The returned data does not include the terminator bit sequence.