Exemple #1
0
        public void Encode(BinaryWriter writer)
        {
            byte[] ascii = ByteValue ?? ExtendedASCIIEncoding.GetBytes(Value);

            // Write length
            writer.Write(ExtendedASCIIEncoding.GetBytes(ascii.Length.ToString(CultureInfo.InvariantCulture)));

            // Write seperator
            writer.Write(':');

            // Write ASCII representation
            writer.Write(ascii);
        }
Exemple #2
0
        public IBencodingType Decode(BinaryReader inputStream, ref int bytesConsumed)
        {
            string numberLength = "";
            char   ch;

            while ((ch = inputStream.ReadChar()) != ':')
            {
                numberLength += ch;
                bytesConsumed++;
            }

            bytesConsumed++;

            byte[] stringData = inputStream.ReadBytes(int.Parse(numberLength));

            bytesConsumed += int.Parse(numberLength);

            Value     = ExtendedASCIIEncoding.GetString(stringData, 0, stringData.Length);
            ByteValue = stringData;

            return(this);
        }