public void Pack(Packer stream, object obj) { var e = obj as System.Enum; var type = e.GetType().GetEnumUnderlyingType(); if (type == typeof(int)) { stream.WriteByte((byte)TypeValue.Int32); var ser = new Int32Serializer(); ser.Pack(stream, obj); } else if (type == typeof(short)) { stream.WriteByte((byte)TypeValue.Int16); var ser = new Int16Serializer(); ser.Pack(stream, obj); } else if (type == typeof(long)) { stream.WriteByte((byte)TypeValue.Int64); var ser = new Int64Serializer(); ser.Pack(stream, obj); } else if (type == typeof(uint)) { stream.WriteByte((byte)TypeValue.UInt32); var ser = new UInt32Serializer(); ser.Pack(stream, obj); } else if (type == typeof(ushort)) { stream.WriteByte((byte)TypeValue.UInt16); var ser = new UInt16Serializer(); ser.Pack(stream, obj); } else if (type == typeof(ulong)) { stream.WriteByte((byte)TypeValue.UInt64); var ser = new UInt64Serializer(); ser.Pack(stream, obj); } else if (type == typeof(byte)) { stream.WriteByte((byte)TypeValue.Byte); var ser = new ByteSerializer(); ser.Pack(stream, obj); } else if (type == typeof(sbyte)) { stream.WriteByte((byte)TypeValue.SByte); var ser = new SByteSerializer(); ser.Pack(stream, obj); } else { stream.WriteByte((byte)TypeValue.String); var ser = new StringSerializer(); ser.Pack(stream, obj); } }
public object Unpack(Packer stream) { object res = null; var enumType = (TypeValue)stream.ReadByte(); if (enumType == TypeValue.Int32) { var ser = new Int32Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.Int16) { var ser = new Int16Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.Int64) { var ser = new Int64Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.UInt16) { var ser = new UInt16Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.UInt32) { var ser = new UInt32Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.UInt64) { var ser = new UInt64Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.Byte) { var ser = new ByteSerializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.SByte) { var ser = new SByteSerializer(); res = ser.Unpack(stream); } else { var ser = new StringSerializer(); var str = (string)ser.Unpack(stream); res = System.Enum.Parse(typeof(System.Enum), str); } return(res); }
public object Unpack(Packer packer) { return(Int16Serializer.UnpackDirect(packer)); }
public void Pack(Packer packer, object obj) { Int16Serializer.PackDirect(packer, (short)obj); }