Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
pluginbase.Helpers.BinaryCodecs.Providers.ExtendedCodecProvider Class Reference
Inheritance diagram for pluginbase.Helpers.BinaryCodecs.Providers.ExtendedCodecProvider:
pluginbase.Helpers.BinaryCodecs.IBinaryCodec

Public Member Functions

TypeCodec GetCodec (Type type)
 

Member Function Documentation

TypeCodec pluginbase.Helpers.BinaryCodecs.Providers.ExtendedCodecProvider.GetCodec ( Type  type)

Implements pluginbase.Helpers.BinaryCodecs.IBinaryCodec.

12  {
13  if (type.IsEnum)
14  {
15  return new TypeCodec
16  {
17  Encode = (w,v) => w.Write(Enum.GetName(type, v)),
18  Decode = r => Enum.Parse(type, r.ReadString())
19  };
20  }
21 
22  if (type == typeof(TimeSpan))
23  {
24  return new TypeCodec
25  {
26  Encode = (w,v) => w.Write(((TimeSpan)v).Ticks),
27  Decode = r => new TimeSpan(r.ReadInt64())
28  };
29  }
30 
31  if (type == typeof(DateTime))
32  {
33  return new TypeCodec
34  {
35  Encode = (w,v) => w.Write(((DateTime)v).ToBinary()),
36  Decode = r => DateTime.FromBinary(r.ReadInt64())
37  };
38  }
39 
40  if (type == typeof(Vector3))
41  {
42  return new TypeCodec
43  {
44  Encode = (w,v) => {
45  Vector3 vec = (Vector3)v;
46  w.Write(vec.X);
47  w.Write(vec.Y);
48  w.Write(vec.Z);
49  },
50  Decode = r => {
51  float x = r.ReadSingle();
52  float y = r.ReadSingle();
53  float z = r.ReadSingle();
54  return new Vector3(x,y,z);
55  }
56  };
57  }
58 
59  if (type == typeof(Vector3d))
60  {
61  return new TypeCodec
62  {
63  Encode = (w,v) => {
64  Vector3d vec = (Vector3d)v;
65  w.Write(vec.X);
66  w.Write(vec.Y);
67  w.Write(vec.Z);
68  },
69  Decode = r => {
70  double x = r.ReadDouble();
71  double y = r.ReadDouble();
72  double z = r.ReadDouble();
73  return new Vector3d(x,y,z);
74  }
75  };
76  }
77 
78  if (type == typeof(Vector3i))
79  {
80  return new TypeCodec
81  {
82  Encode = (w,v) => {
83  Vector3i vec = (Vector3i)v;
84  w.Write(vec.X);
85  w.Write(vec.Y);
86  w.Write(vec.Z);
87  },
88  Decode = r => {
89  int x = r.ReadInt32();
90  int y = r.ReadInt32();
91  int z = r.ReadInt32();
92  return new Vector3i(x,y,z);
93  }
94  };
95  }
96 
97  if (type == typeof(Rotation2))
98  {
99  return new TypeCodec
100  {
101  Encode = (w,v) => {
102  Rotation2 rot = (Rotation2)v;
103  w.Write(rot.X);
104  w.Write(rot.Z);
105  },
106  Decode = r => {
107  float x = r.ReadSingle();
108  float z = r.ReadSingle();
109  return new Rotation2(x,z);
110  }
111  };
112  }
113 
114  if (type == typeof(Rotation2d))
115  {
116  return new TypeCodec
117  {
118  Encode = (w,v) => {
119  Rotation2d rot = (Rotation2d)v;
120  w.Write(rot.X);
121  w.Write(rot.Z);
122  },
123  Decode = r => {
124  double x = r.ReadDouble();
125  double y = r.ReadDouble();
126  return new Rotation2d(x,y);
127  }
128  };
129  }
130 
131  if (type == typeof(Rgba))
132  {
133  return new TypeCodec
134  {
135  Encode = (w,v) => {
136  Rgba color = (Rgba)v;
137  w.Write(color.R);
138  w.Write(color.G);
139  w.Write(color.B);
140  w.Write(color.A);
141  },
142  Decode = r => {
143  float cr = r.ReadSingle();
144  float cg = r.ReadSingle();
145  float cb = r.ReadSingle();
146  float ca = r.ReadSingle();
147  return new Rgba(cr, cg, cb, ca);
148  }
149  };
150  }
151 
152  if (type == typeof(Type))
153  {
154  return new TypeCodec
155  {
156  Encode = (w,v) => w.Write(TypeSerializer.Serialize((Type)v)),
157  Decode = r => TypeSerializer.Deserialize(r.ReadString())
158  };
159  }
160 
161  return null;
162  }
Class the represents a floating-point color of red, green, blue, and alpha
Definition: Rgba.cs:11
static string Serialize(Type type)
Definition: TypeSerializer.cs:122
float A
Alpha component
Definition: Rgba.cs:33
static readonly Vector3i
All directions, including diagnols
Definition: Vector3i.cs:111
Rotation XZ; In radians
Definition: Rotation2.cs:10
double X
Definition: Rotation2d.cs:12
Special type serializer that will work with plugins
Definition: TypeSerializer.cs:11
float R
Red component
Definition: Rgba.cs:18
float X
Definition: Rotation2.cs:12
Rotation XZ; In radians
Definition: Rotation2d.cs:10
static Type Deserialize(string slug)
Definition: TypeSerializer.cs:127
float Z
Definition: Rotation2.cs:12
float G
Green component
Definition: Rgba.cs:23
int Y
The Y coordinate
Definition: Vector3i.cs:23
A class representing a 3D coordinate of integers
Definition: Vector3i.cs:13
int X
The X coordinate
Definition: Vector3i.cs:18
double Z
Definition: Rotation2d.cs:12
int Z
The Z coordinate
Definition: Vector3i.cs:28
float B
Blue component
Definition: Rgba.cs:28

The documentation for this class was generated from the following file: