示例#1
0
    //public static bool DecodeUTF8String(BinaryDecoder decoder, out string value)
    //{
    //    try
    //    {
    //        int size = decoder.DecodeInt32();
    //        value = System.Text.Encoding.UTF8.GetString(decoder.DecodeBytes(size));
    //    }
    //    catch (System.Exception)
    //    {
    //        value = string.Empty;
    //        return false;
    //    }

    //    return true;
    //}

    public static bool DecodeUnicodeString(BinaryDecoder decoder, out string value)
    {
        try
        {
            ushort length = decoder.DecodeUInt16();
            value = System.Text.Encoding.Unicode.GetString(decoder.DecodeBytes(length * 2));
        }
        catch (System.Exception)
        {
            value = string.Empty;
            return(false);
        }

        return(true);
    }
示例#2
0
    public static bool Decode(BinaryDecoder decoder, out string value)
    {
        value = "";
        try
        {
            ushort size  = decoder.DecodeUInt16();
            byte[] bytes = decoder.DecodeBytes(size);
            char[] array = new char[size];
            for (int i = 0; i < size; ++i)
            {
                array[i] = (char)bytes[i];
            }
            value = new string(array);
        }
        catch (System.Exception)
        {
            return(false);
        }

        return(true);
    }