DBC User <(E-Mail Removed)> wrote:
> I have a binary writer and when I write a unsigned int I was expecting
> it to write 4 bytes but it is writing 5 bytes and last last byte being
> 0B.
Could you post a short but complete program which demonstrates the
problem?
See
http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
> Also when I write string it is adding byte 01 at the, here is the
> one liner I am using
>
> writer.Write(field.Substring(0, length)) //where field is string
>
> Any idea why I am getting OB in the unsigned int field and 01 between
> two string writes??
Look at the documentation for BinaryWriter.Write(string) for an
explanation of this. (It won't always be 1 - it will be the length in
bytes.)
Admittedly the documentation is incorrect - it claims that it writes
the length in characters as a four byte integer; in fact it writes a
7-bit-encoded integer being the length of the encoded string in
*bytes*.
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too