cjyyyza / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

String cannot be deserialized correctly when using protobuf-net #359

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
email: lzsoft.aegis@gmail.com

What steps will reproduce the problem?
1. Write a unit test like :

    var sb = new StringBuilder(65535);

    for (var i = 0; i < 65536; i++)
    {
        sb.Append((char)i);
    }

    string str = sb.ToString();
    string str2 = null; 

    using (var ms = new System.IO.MemoryStream())
    {
        ProtoBuf.Serializer.NonGeneric.Serialize(ms, str);
        ms.Position = 0;
        str2 = ProtoBuf.Serializer.Deserialize<string>(ms);
    }

    for (int i = 0; i < str2.Length; i++)
    {
        char c = str2[i];

        Assert.True((int)c == i, "Fail at " + i);
    }
2. Run this Test.

What is the expected output? What do you see instead?
The test should pass but instead it fail and output "Fail at 55296"

What version of the product are you using? On what operating system?
I am using protobuf-net.2.0.0.621(.net) via NuGet,my OS is windows7 x64 Chinese 
(Simplified),and .net framework 4.5

Original issue reported on code.google.com by lzsoft.a...@gmail.com on 28 Feb 2013 at 3:05

GoogleCodeExporter commented 9 years ago
Sorry,it's my falut... "It's just that 55296 (which is D800 in hex) and above 
are "surrogate" characters in Unicode and can't be used alone. "

Original comment by lzsoft.a...@gmail.com on 28 Feb 2013 at 5:43