暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Deserializer.cs 955B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. using System.IO;
  6. using System.Text;
  7. namespace Microsoft.Unity.VisualStudio.Editor.Messaging
  8. {
  9. internal class Deserializer
  10. {
  11. private readonly BinaryReader _reader;
  12. public Deserializer(byte[] buffer)
  13. {
  14. _reader = new BinaryReader(new MemoryStream(buffer));
  15. }
  16. public int ReadInt32()
  17. {
  18. return _reader.ReadInt32();
  19. }
  20. public string ReadString()
  21. {
  22. var length = ReadInt32();
  23. return length > 0
  24. ? Encoding.UTF8.GetString(_reader.ReadBytes(length))
  25. : "";
  26. }
  27. public bool CanReadMore()
  28. {
  29. return _reader.BaseStream.Position < _reader.BaseStream.Length;
  30. }
  31. }
  32. }