-
Notifications
You must be signed in to change notification settings - Fork 3
/
PyBuffer.cs
49 lines (39 loc) · 1.12 KB
/
PyBuffer.cs
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;
using System.IO;
using System.Text;
namespace eveMarshal
{
public class PyBuffer : PyObject
{
public byte[] Data { get; private set; }
public PyBuffer()
: base(PyObjectType.Buffer)
{
}
public PyBuffer(byte[] data)
: base(PyObjectType.Buffer)
{
Data = data;
}
public PyBuffer(string data)
: base(PyObjectType.Buffer)
{
Data = Encoding.ASCII.GetBytes(data);
}
public override void Decode(Unmarshal context, MarshalOpcode op, BinaryReader source)
{
var size = source.ReadSizeEx();
Data = source.ReadBytes((int)size);
}
protected override void EncodeInternal(BinaryWriter output)
{
output.WriteOpcode(MarshalOpcode.Buffer);
output.WriteSizeEx(Data.Length);
output.Write(Data);
}
public override string ToString()
{
return "<" + BitConverter.ToString(Data) + ">";
}
}
}