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

Public Member Functions

TypeCodec GetCodec (Type type)
 

Member Function Documentation

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

Attribute: length

;

Attribute: i

= x.ReadByte();

Attribute: i

);

Attribute: length

;

Attribute: i

= x.ReadSByte();

Attribute: i

);

Attribute: length

;

Attribute: i

= x.ReadInt32();

Attribute: i

);

Attribute: length

;

Attribute: i

= x.ReadInt64();

Attribute: i

);

Attribute: length

;

Attribute: i

= x.ReadInt16();

Attribute: i

);

Attribute: length

;

Attribute: i

= x.ReadUInt32();

Attribute: i

);

Attribute: length

;

Attribute: i

= x.ReadUInt16();

Attribute: i

);

Attribute: length

;

Attribute: i

= x.ReadSingle();

Attribute: i

);

Attribute: length

;

Attribute: i

= x.ReadDouble();

Attribute: i

);

Attribute: length

;

Attribute: i

= x.ReadBoolean();

Attribute: i

);

Attribute: length

;

Attribute: i

= x.ReadString();

Attribute: i

);

Implements pluginbase.Helpers.BinaryCodecs.IBinaryCodec.

10  {
11  if (type == typeof(byte))
12  {
13  return new TypeCodec{
14  Decode = x => x.ReadByte(),
15  Encode = (x,y) => x.Write((byte)y)
16  };
17  }
18  if (type == typeof(byte[]))
19  {
20  return new TypeCodec {
21  Decode = x => {
22  ushort length = x.ReadUInt16();
23  var data = new byte[length];
24  for (int i=0; i<length; ++i)
25  data[i] = x.ReadByte();
26  return data;
27  },
28  Encode = (x,y) => {
29  var data = (byte[])y;
30  x.Write((ushort)data.Length);
31  for (int i=0; i<data.Length; ++i)
32  x.Write(data[i]);
33  }
34  };
35  }
36  if (type == typeof(sbyte))
37  {
38  return new TypeCodec{
39  Decode = x => x.ReadSByte(),
40  Encode = (x,y) => x.Write((sbyte)y)
41  };
42  }
43  if (type == typeof(sbyte[]))
44  {
45  return new TypeCodec {
46  Decode = x => {
47  ushort length = x.ReadUInt16();
48  var data = new sbyte[length];
49  for (int i=0; i<length; ++i)
50  data[i] = x.ReadSByte();
51  return data;
52  },
53  Encode = (x,y) => {
54  var data = (sbyte[])y;
55  x.Write((ushort)data.Length);
56  for (int i=0; i<data.Length; ++i)
57  x.Write(data[i]);
58  }
59  };
60  }
61  if (type == typeof(int))
62  {
63  return new TypeCodec{
64  Decode = x => x.ReadInt32(),
65  Encode = (x,y) => x.Write((int)y)
66  };
67  }
68  if (type == typeof(int[]))
69  {
70  return new TypeCodec {
71  Decode = x => {
72  ushort length = x.ReadUInt16();
73  var data = new int[length];
74  for (int i=0; i<length; ++i)
75  data[i] = x.ReadInt32();
76  return data;
77  },
78  Encode = (x,y) => {
79  var data = (int[])y;
80  x.Write((ushort)data.Length);
81  for (int i=0; i<data.Length; ++i)
82  x.Write(data[i]);
83  }
84  };
85  }
86  if (type == typeof(long))
87  {
88  return new TypeCodec{
89  Decode = x => x.ReadInt64(),
90  Encode = (x,y) => x.Write((long)y)
91  };
92  }
93  if (type == typeof(long[]))
94  {
95  return new TypeCodec {
96  Decode = x => {
97  ushort length = x.ReadUInt16();
98  var data = new long[length];
99  for (int i=0; i<length; ++i)
100  data[i] = x.ReadInt64();
101  return data;
102  },
103  Encode = (x,y) => {
104  var data = (long[])y;
105  x.Write((ushort)data.Length);
106  for (int i=0; i<data.Length; ++i)
107  x.Write(data[i]);
108  }
109  };
110  }
111  if (type == typeof(short))
112  {
113  return new TypeCodec{
114  Decode = x => x.ReadInt16(),
115  Encode = (x,y) => x.Write((short)y)
116  };
117  }
118  if (type == typeof(short[]))
119  {
120  return new TypeCodec {
121  Decode = x => {
122  ushort length = x.ReadUInt16();
123  var data = new short[length];
124  for (int i=0; i<length; ++i)
125  data[i] = x.ReadInt16();
126  return data;
127  },
128  Encode = (x,y) => {
129  var data = (short[])y;
130  x.Write((ushort)data.Length);
131  for (int i=0; i<data.Length; ++i)
132  x.Write(data[i]);
133  }
134  };
135  }
136  if (type == typeof(uint))
137  {
138  return new TypeCodec{
139  Decode = x => x.ReadUInt32(),
140  Encode = (x,y) => x.Write((uint)y)
141  };
142  }
143  if (type == typeof(uint[]))
144  {
145  return new TypeCodec {
146  Decode = x => {
147  ushort length = x.ReadUInt16();
148  var data = new uint[length];
149  for (int i=0; i<length; ++i)
150  data[i] = x.ReadUInt32();
151  return data;
152  },
153  Encode = (x,y) => {
154  var data = (uint[])y;
155  x.Write((ushort)data.Length);
156  for (int i=0; i<data.Length; ++i)
157  x.Write(data[i]);
158  }
159  };
160  }
161  if (type == typeof(ushort))
162  {
163  return new TypeCodec{
164  Decode = x => x.ReadUInt16(),
165  Encode = (x,y) => x.Write((ushort)y)
166  };
167  }
168  if (type == typeof(ushort[]))
169  {
170  return new TypeCodec {
171  Decode = x => {
172  ushort length = x.ReadUInt16();
173  var data = new ushort[length];
174  for (int i=0; i<length; ++i)
175  data[i] = x.ReadUInt16();
176  return data;
177  },
178  Encode = (x,y) => {
179  var data = (ushort[])y;
180  x.Write((ushort)data.Length);
181  for (int i=0; i<data.Length; ++i)
182  x.Write(data[i]);
183  }
184  };
185  }
186  if (type == typeof(float))
187  {
188  return new TypeCodec{
189  Decode = x => x.ReadSingle(),
190  Encode = (x,y) => x.Write((float)y)
191  };
192  }
193  if (type == typeof(float[]))
194  {
195  return new TypeCodec {
196  Decode = x => {
197  ushort length = x.ReadUInt16();
198  var data = new float[length];
199  for (int i=0; i<length; ++i)
200  data[i] = x.ReadSingle();
201  return data;
202  },
203  Encode = (x,y) => {
204  var data = (float[])y;
205  x.Write((ushort)data.Length);
206  for (int i=0; i<data.Length; ++i)
207  x.Write(data[i]);
208  }
209  };
210  }
211  if (type == typeof(double))
212  {
213  return new TypeCodec{
214  Decode = x => x.ReadDouble(),
215  Encode = (x,y) => x.Write((double)y)
216  };
217  }
218  if (type == typeof(double[]))
219  {
220  return new TypeCodec {
221  Decode = x => {
222  ushort length = x.ReadUInt16();
223  var data = new double[length];
224  for (int i=0; i<length; ++i)
225  data[i] = x.ReadDouble();
226  return data;
227  },
228  Encode = (x,y) => {
229  var data = (double[])y;
230  x.Write((ushort)data.Length);
231  for (int i=0; i<data.Length; ++i)
232  x.Write(data[i]);
233  }
234  };
235  }
236  if (type == typeof(bool))
237  {
238  return new TypeCodec{
239  Decode = x => x.ReadBoolean(),
240  Encode = (x,y) => x.Write((bool)y)
241  };
242  }
243  if (type == typeof(bool[]))
244  {
245  return new TypeCodec {
246  Decode = x => {
247  ushort length = x.ReadUInt16();
248  var data = new bool[length];
249  for (int i=0; i<length; ++i)
250  data[i] = x.ReadBoolean();
251  return data;
252  },
253  Encode = (x,y) => {
254  var data = (bool[])y;
255  x.Write((ushort)data.Length);
256  for (int i=0; i<data.Length; ++i)
257  x.Write(data[i]);
258  }
259  };
260  }
261  if (type == typeof(string))
262  {
263  return new TypeCodec{
264  Decode = x => x.ReadString(),
265  Encode = (x,y) => x.Write((string)y)
266  };
267  }
268  if (type == typeof(string[]))
269  {
270  return new TypeCodec {
271  Decode = x => {
272  ushort length = x.ReadUInt16();
273  var data = new string[length];
274  for (int i=0; i<length; ++i)
275  data[i] = x.ReadString();
276  return data;
277  },
278  Encode = (x,y) => {
279  var data = (string[])y;
280  x.Write((ushort)data.Length);
281  for (int i=0; i<data.Length; ++i)
282  x.Write(data[i]);
283  }
284  };
285  }
286  return null;
287  }

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