-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPyToken.cs
More file actions
49 lines (41 loc) · 1.29 KB
/
PyToken.cs
File metadata and controls
49 lines (41 loc) · 1.29 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
using System.IO;
using System.Text;
namespace eveMarshal
{
public class PyToken : PyObject
{
public byte[] RawToken { get; set; }
public string Token { get; set; }
public PyToken()
: base(PyObjectType.Token)
{
}
public PyToken(string token)
: base(PyObjectType.Token)
{
Token = token;
}
public override void Decode(Unmarshal context, MarshalOpcode op, BinaryReader source)
{
byte len = source.ReadByte();
RawToken = source.ReadBytes(len);
Token = Encoding.ASCII.GetString(RawToken);
}
protected override void EncodeInternal(BinaryWriter output)
{
output.WriteOpcode(MarshalOpcode.Token);
if (RawToken != null)
{
output.Write((byte)RawToken.Length);
output.Write(RawToken);
}
else if (Token != null)
{
output.Write((byte)Token.Length);
output.Write(Encoding.ASCII.GetBytes(Token));
}
else
throw new InvalidDataException("Fill either RawToken or Token with data for encoding");
}
}
}