-
Notifications
You must be signed in to change notification settings - Fork 4
/
Marshal.cs
48 lines (42 loc) · 1.48 KB
/
Marshal.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
using System;
using System.Collections.Generic;
using System.IO;
namespace eveMarshal
{
public static class Marshal
{
public static byte[] Process(PyObject obj)
{
var ret = new MemoryStream(100);
ret.WriteByte(Unmarshal.HeaderByte);
// we have no support for save lists right now
ret.WriteByte(0x00);
ret.WriteByte(0x00);
ret.WriteByte(0x00);
ret.WriteByte(0x00);
obj.Encode(new BinaryWriter(ret));
return ret.ToArray();
}
public static PyTuple Tuple(params PyObject[] objs)
{
return new PyTuple(new List<PyObject>(objs));
}
public static PyDict Dict(params object[] objs)
{
if (objs.Length % 2 == 1)
throw new ArgumentException("Expected pair arguments");
var ret = new PyDict(new Dictionary<PyObject, PyObject>(objs.Length / 2));
for (int i = 0; i < (objs.Length/2); i++)
{
var key = objs[i];
var val = objs[i + 1];
if (!(key is string))
throw new ArgumentException("Expected string");
if (!(val is PyObject))
throw new ArgumentException("Expected PyObject");
ret.Dictionary.Add(new PyString(key as string), val as PyObject);
}
return ret;
}
}
}