Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode encoding with StringTerminator #126

Closed
dakilgvait opened this issue Apr 12, 2019 · 0 comments
Closed

Unicode encoding with StringTerminator #126

dakilgvait opened this issue Apr 12, 2019 · 0 comments
Assignees
Labels

Comments

@dakilgvait
Copy link

unicode encoding has 2 bytes for each character but StringTerminator is only one byte. So when we serialize a string like "sdf" it will be in hex "730064006600" and if we add null terminator we need to get "730064006600"+"0000" but for now it is "730064006600"+"00"
ValueValueNode.cs line ~230
all code bellow only for demonstrating direction, it is not solution
for the test i change it to

var stringTerminatorData = GetFieldEncoding()
               .GetBytes(new char[] { (char)TypeNode.StringTerminator });

And little about deserialize: hex "730064006600" will be deserialized like 3 different string with one letter
ValueValueNode.cs line ~891
for the test i changed the method to

private static byte[] ReadTerminated(BinaryReader reader, FieldLength maxLength, 
          byte terminator, Encoding enc)
        {
            var buffer = new MemoryStream();
            var byteLength = maxLength.ByteCount;
            char b;
            while (byteLength-- > 0 && (b = reader.ReadChar()) != (char)terminator)
            {
                byte[] arr = enc.GetBytes(new char[] { b });
                buffer.Write(arr, 0, arr.Length);
            }
            return buffer.ToArray();
        }

and do not forget pass Encoding
Sorry for my english and writing style.

@jefffhaynes jefffhaynes self-assigned this Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants