IStore.cs
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Linq;
using System.Collections.Generic;
namespace UniJSON
{
public interface IStore
{
void Clear();
ArraySegment<Byte> Bytes { get; }
void Write(Byte value);
void Write(SByte value);
// network
void WriteBigEndian(UInt16 value);
void WriteBigEndian(UInt32 value);
void WriteBigEndian(UInt64 value);
void WriteBigEndian(Int16 value);
void WriteBigEndian(Int32 value);
void WriteBigEndian(Int64 value);
void WriteBigEndian(Single value);
void WriteBigEndian(Double value);
// intel cpu
void WriteLittleEndian(UInt16 value);
void WriteLittleEndian(UInt32 value);
void WriteLittleEndian(UInt64 value);
void WriteLittleEndian(Int16 value);
void WriteLittleEndian(Int32 value);
void WriteLittleEndian(Int64 value);
void WriteLittleEndian(Single value);
void WriteLittleEndian(Double value);
void Write(ArraySegment<Byte> bytes);
void Write(string src);
void Write(char c);
}
public static class IStoreExtensions
{
public static void WriteValues(this IStore s, params Byte[] bytes)
{
s.Write(new ArraySegment<Byte>(bytes));
}
public static void Write(this IStore s, Byte[] bytes)
{
s.Write(new ArraySegment<Byte>(bytes));
}
public static void Write(this IStore s, IEnumerable<Byte> bytes)
{
s.Write(new ArraySegment<Byte>(bytes.ToArray()));
}
public static Utf8String ToUtf8String(this IStore s)
{
return new Utf8String(s.Bytes);
}
}
}