internal static string ReadInternedString(this BinaryReader reader, IAtomize atomize) { var sid = reader.ReadLength(); var rv = atomize.GetString(sid, reader.ReadStringInternal); return(rv); }
internal static Type ReadType(this BinaryReader reader, IAtomize atomize, SerializationBinder binder) { var assembly = reader.ReadInternedString(atomize); var typename = reader.ReadInternedString(atomize); return(binder.BindToType(assembly, typename)); }
internal static void WriteInterned(this BinaryWriter writer, IAtomize atomize, string str) { int sid; if (atomize.AtomizeString(str, out sid)) { writer.WriteLength(sid); return; } writer.WriteLength(sid); var bytes = Encoding.UTF8.GetBytes(str); writer.WriteLength(bytes.Length); writer.Write(bytes); }
internal static void Write(this BinaryWriter writer, IAtomize atomize, SerializationBinder binder, Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } EnsureTypeIsSerializable(type); string name; string assembly; binder.BindToName(type, out assembly, out name); if (assembly == null) { assembly = type.Assembly.FullName; } if (name == null) { name = type.FullName; } writer.WriteInterned(atomize, assembly); writer.WriteInterned(atomize, name); }