<commit_before>package im.actor.server.mtproto.codecs

import scodec._
import scodec.bits._

object StringCodec extends Codec[String] {
  def sizeBound = SizeBound.unknown

  def encode(str: String) = {
    val strBytes = str.getBytes
    for { length <- varint.encode(strBytes.length.toLong) }
    yield length ++ BitVector(strBytes)
  }

  def decode(buf: BitVector) = {
    for { t <- varint.decode(buf) }
    yield {
      val length = t.value * byteSize
      DecodeResult(new String(t.remainder.take(length).toByteArray), t.remainder.drop(length))
    }
  }
}<commit_msg>fix(codecs): utf-8 strings<commit_after>package im.actor.server.mtproto.codecs

import scodec._
import scodec.bits._

object StringCodec extends Codec[String] {
  def sizeBound = SizeBound.unknown

  def encode(str: String) = {
    val strBytes = str.getBytes
    for { length <- varint.encode(strBytes.length.toLong) }
    yield length ++ BitVector(strBytes)
  }

  def decode(buf: BitVector) = {
    for { t <- varint.decode(buf) }
    yield {
      val length = t.value * byteSize
      DecodeResult(new String(t.remainder.take(length).toByteArray, "UTF-8"), t.remainder.drop(length))
    }
  }
}
{'fraction_non_alphanumeric': 0.12414965986394558, 'fraction_numerical': 0.0017006802721088435, 'mean_word_length': 3.424812030075188, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '19364', 'n_tokens_mistral': 410, 'n_tokens_neox': 400, 'n_words': 81}