protected function encodeSetOf(SetOfType $setOf)
    {
        if (\count($setOf->getChildren()) === 0) {
            return '';
        }
        $children = [];

        # Encode each child and record the length, we need it later
        foreach ($setOf as $type) {
            $child = ['original' => $this->encode($type)];
            $child['length'] = \strlen($child['original']);
            $children[] = $child;
        }

        # Sort the encoded types by length first to determine the padding needed.
        \usort($children, function ($a, $b) {
            /* @var AbstractType $a
             * @var AbstractType $b */
            return $a['length'] < $b['length'] ? -1 : 1;
        });

        # Get the last child (ie. the longest), and put the array back to normal.
        $child = \end($children);
        $padding = $child ['length'];
        \reset($children);

        # Sort by padding the items and comparing them.
        \usort($children, function($a, $b) use ($padding) {
            return \strcmp(
                \str_pad($a['original'], $padding, "\x00"),
                \str_pad($b['original'], $padding, "\x00")
            );
        });

        # Reconstruct the byte string from the order obtained.
        $bytes = '';
        foreach ($children as $child) {
            $bytes .= $child['original'];
        }

        return $bytes;
    }