putTerm (BytelistTerm value)
  | len < 65536 = tag 107 >> put16u len >> putL value
  | otherwise = do  -- too big: encode as a list.
      tag 108
      put32u len
      forM_ (B.unpack value) $ \v -> do
        tag 97
        putWord8 v
  where
    len = B.length value
putTerm (BytelistTerm value)
  | len < 65536 = tag 107 >> put16u len >> putL value
  | otherwise = do  -- too big: encode as a list.
      tag 108
      put32u len
      forM_ (B.unpack value) $ \v -> do
        tag 97
        putWord8 v
  where
    len = B.length value
putTerm (BytelistTerm value)
  | len < 65536 = tag 107 >> put16u len >> putL value
  | otherwise = do  -- too big: encode as a list.
      tag 108
      put32u len
      forM_ (B.unpack value) $ \v -> do
        tag 97
        putWord8 v
  where
    len = B.length value