| | 1 | | using System; |
| | 2 | | using System.IO; |
| | 3 | |
|
| | 4 | | namespace Itinero.IO; |
| | 5 | |
|
| | 6 | | internal static class StreamExtensions |
| | 7 | | { |
| | 8 | | internal static long WriteWithSize(this Stream stream, string value) |
| 23 | 9 | | { |
| 23 | 10 | | var bytes = System.Text.Encoding.Unicode.GetBytes(value); |
| 23 | 11 | | return stream.WriteWithSize(bytes); |
| 23 | 12 | | } |
| | 13 | |
|
| | 14 | | internal static long WriteWithSize(this Stream stream, byte[] value) |
| 23 | 15 | | { |
| 23 | 16 | | stream.Write(BitConverter.GetBytes((long)value.Length), 0, 8); |
| 23 | 17 | | stream.Write(value, 0, value.Length); |
| 23 | 18 | | return value.Length + 8; |
| 23 | 19 | | } |
| | 20 | |
|
| | 21 | | internal static string ReadWithSizeString(this Stream stream) |
| 23 | 22 | | { |
| 23 | 23 | | var size = stream.ReadInt64(); |
| 23 | 24 | | var data = new byte[size]; |
| 23 | 25 | | stream.Read(data, 0, (int)size); |
| | 26 | |
|
| 23 | 27 | | return System.Text.Encoding.Unicode.GetString(data, 0, data.Length); |
| 23 | 28 | | } |
| | 29 | | } |