public static byte[] ReadLengthEncodedByteArray(this Stream self, DeserializerSession session) { var length = self.ReadInt32(session); var buffer = new byte[length]; self.Read(buffer, 0, length); return buffer; }
public static int ReadUInt16(this Stream self, DeserializerSession session) { var buffer = session.GetBuffer(2); self.Read(buffer, 0, 2); var res = BitConverter.ToUInt16(buffer, 0); return res; }
public object Deserialize(Stream stream) { var session = new DeserializerSession(this); var s = GetDeserializerByManifest(stream, session); return(s.ReadValue(stream, session)); }
/// <summary> /// 从指定文件反序列化对象 /// </summary> /// <param name="filePath"></param> /// <param name="session"></param> /// <returns></returns> public object Deserialize([NotNull] string filePath, DeserializerSession session) { using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { return(Deserialize(stream, session)); } }
public T Deserialize <T>([NotNull] Stream stream) { DeserializerSession session = GetDeserializerSession(); var s = GetDeserializerByManifest(stream, session); return((T)s.ReadValue(stream, session)); }
public static object ReadObject(this Stream stream, DeserializerSession session) { var s = session.Serializer.GetDeserializerByManifest(stream, session); var value = s.ReadValue(stream, session); //read the element value return(value); }
public static byte[] ReadLengthEncodedByteArray(this Stream self, DeserializerSession session) { var length = self.ReadInt32(session); var buffer = new byte[length]; self.Read(buffer, 0, length); return(buffer); }
public static int ReadUInt16(this Stream self, DeserializerSession session) { var buffer = session.GetBuffer(2); self.Read(buffer, 0, 2); var res = BitConverter.ToUInt16(buffer, 0); return(res); }
public ValueSerializer GetDeserializerByManifest([NotNull] Stream stream, [NotNull] DeserializerSession session) { var first = stream.ReadByte(); if (first <= 250) { return(_deserializerLookup[first]); } switch (first) { case ConsistentArraySerializer.Manifest: return(ConsistentArraySerializer.Instance); case ObjectReferenceSerializer.Manifest: return(ObjectReferenceSerializer.Instance); case ObjectSerializer.ManifestFull: { var type = TypeEx.GetTypeFromManifestFull(stream, session); return(GetCustomDeserializer(type)); } case ObjectSerializer.ManifestVersion: { var type = TypeEx.GetTypeFromManifestVersion(stream, session); return(GetCustomDeserializer(type)); } case ObjectSerializer.ManifestIndex: { var typeId = (int)stream.ReadUInt16(session); if (typeId < _knownValueSerializers.Length) { return(_knownValueSerializers[typeId]); } var type = TypeEx.GetTypeFromManifestIndex(typeId, session); return(GetCustomDeserializer(type)); } default: throw new NotSupportedException("Unknown manifest value"); } }
public ValueSerializer GetDeserializerByManifest(Stream stream, DeserializerSession session) { //magic byte, a homage to Apache Kafka var magicByte = stream.ReadByte(); if (magicByte <= 250) { return(_deserializerLookup[magicByte]); } switch (magicByte) { case ConsistentArraySerializer.Manifest: return(ConsistentArraySerializer.Instance); case ObjectReferenceSerializer.Manifest: return(ObjectReferenceSerializer.Instance); case ObjectSerializer.ManifestFull: { var type = TypeEx.GetTypeFromManifestFull(stream, session); return(GetCustomDeserializer(type)); } case ObjectSerializer.ManifestIndex: { var typeId = (int)stream.ReadUInt16(session); if (typeId < _knownValueSerializers.Length) { return(_knownValueSerializers[typeId]); } var type = TypeEx.GetTypeFromManifestIndex(typeId, session); return(GetCustomDeserializer(type)); } default: throw new NotSupportedException("Unknown manifest value"); } }
public static object ReadObject(this Stream stream, DeserializerSession session) { var s = session.Serializer.GetDeserializerByManifest(stream, session); var value = s.ReadValue(stream, session); //read the element value return value; }
public ValueSerializer GetDeserializerByManifest(Stream stream, DeserializerSession session) { var first = stream.ReadByte(); switch (first) { case NullSerializer.Manifest: return(NullSerializer.Instance); //TODO: hmm why havent I added 1? case Int64Serializer.Manifest: return(Int64Serializer.Instance); case Int16Serializer.Manifest: return(Int16Serializer.Instance); case ByteSerializer.Manifest: return(ByteSerializer.Instance); case DateTimeSerializer.Manifest: return(DateTimeSerializer.Instance); case BoolSerializer.Manifest: return(BoolSerializer.Instance); case StringSerializer.Manifest: return(StringSerializer.Instance); case Int32Serializer.Manifest: return(Int32Serializer.Instance); case ByteArraySerializer.Manifest: return(ByteArraySerializer.Instance); case GuidSerializer.Manifest: return(GuidSerializer.Instance); case FloatSerializer.Manifest: return(FloatSerializer.Instance); case DoubleSerializer.Manifest: return(DoubleSerializer.Instance); case DecimalSerializer.Manifest: return(DecimalSerializer.Instance); case CharSerializer.Manifest: return(CharSerializer.Instance); case TypeSerializer.Manifest: return(TypeSerializer.Instance); case UInt16Serializer.Manifest: return(UInt16Serializer.Instance); case UInt32Serializer.Manifest: return(UInt32Serializer.Instance); case UInt64Serializer.Manifest: return(UInt64Serializer.Instance); case SByteSerializer.Manifest: return(SByteSerializer.Instance); case ObjectReferenceSerializer.Manifest: return(ObjectReferenceSerializer.Instance); case ConsistentArraySerializer.Manifest: return(ConsistentArraySerializer.Instance); case ObjectSerializer.ManifestFull: { var type = ObjectSerializer.GetTypeFromManifestFull(stream, session); return(GetCustomDeserialzer(type)); } case ObjectSerializer.ManifestIndex: { var type = ObjectSerializer.GetTypeFromManifestIndex(stream, session); return(GetCustomDeserialzer(type)); } default: throw new NotSupportedException("Unknown manifest value"); } }
public object Deserialize([NotNull] Stream stream, DeserializerSession session) { var s = GetDeserializerByManifest(stream, session); return(s.ReadValue(stream, session)); }
/// <summary> /// 从流反序列化到对象 /// </summary> /// <param name="stream"></param> /// <param name="session"></param> /// <returns></returns> public object Deserialize([NotNull] Stream stream, DeserializerSession session) { return(SerializerInstance.Deserialize(stream, session)); }
/// <summary> /// 从指定文件反序列化对象 /// </summary> /// <param name="filePath"></param> /// <param name="session"></param> /// <returns></returns> public static object Deserialize([NotNull] string filePath, DeserializerSession session) { return(SerializerInstance.Deserialize(filePath, session)); }
public T Deserialize <T>(Stream stream, DeserializerSession session) { var s = GetDeserializerByManifest(stream, session); return((T)s.ReadValue(stream, session)); }