public void TestString() { var stream = new MsgPackStream(); var testString = "Test string"; var length = Encoding.UTF8.GetByteCount(testString); stream.WriteString(testString); Assert.AreEqual(stream.Position, length); stream.Position = 0; Assert.AreEqual(testString, stream.ReadString(unchecked ((uint)length))); }
public static string ReadString(MsgPackStream stream) { var code = stream.ReadUInt8(); if (FormatMask.Match(code) == FormatMask.FixString) { return(stream.ReadString(code & 0x1Fu)); } switch (code) { case FormatCode.Str8: return(stream.ReadString(stream.ReadUInt8())); case FormatCode.Str16: return(stream.ReadString(stream.ReadUInt16())); case FormatCode.Str32: return(stream.ReadString(stream.ReadUInt32())); case FormatCode.Nil: return(null); default: throw new MsgPackCodeException(code); } }