public override object Deserialize(System.IO.BinaryReader binaryReader) { bool hasValue = binaryReader.ReadBoolean (); if (!hasValue) return null; int typeID = binaryReader.ReadByte (); switch (typeID) { case 1: return binaryReader.ReadBoolean (); case 2: return binaryReader.ReadByte (); case 128: return binaryReader.ReadSByte (); case 3: return binaryReader.ReadInt16 (); case 129: return binaryReader.ReadUInt16 (); case 4: return binaryReader.ReadInt32 (); case 130: return binaryReader.ReadUInt32 (); case 5: return binaryReader.ReadInt64 (); case 131: return binaryReader.ReadUInt64 (); case 9: return binaryReader.ReadDouble (); case 16: return binaryReader.ReadString (); case 144: return binaryReader.ReadChar (); case 24: return new DateTime (binaryReader.ReadInt64 ()); case 32: return new Guid (binaryReader.ReadBytes (16)); case 36: return binaryReader.ReadBytes (binaryReader.ReadInt32 ()); case 37: { int count = binaryReader.ReadInt32 (); string[] r = new string[count]; for (int n = 0; n != count; n++) r [n] = binaryReader.ReadString (); return r; } case 38: { int count = binaryReader.ReadInt32 (); long[] r = new long[count]; for (int n = 0; n != count; n++) r [n] = binaryReader.ReadInt64 (); return r; } default: throw new Exception (string.Format ("Serialization for type <{0}> is not supported", typeID)); } }
public static string Read(System.IO.BinaryReader reader) { string str = string.Empty; int length = reader.ReadInt32(); for (int i = 0; i < length; ++i) str += reader.ReadChar(); return str; }
public Boolean FindPrivileges(Byte[] APrivileges, Char APrivilege, System.IO.BinaryReader r, out Int32 ALength) { System.IO.Stream s = r.BaseStream; ALength = 0; while(s.Position < s.Length) { Char LPrivilege = r.ReadChar(); ALength = Pub.Read7BitEncodedInt(r); if(LPrivilege == APrivilege) return true; s.Seek(ALength, System.IO.SeekOrigin.Current); } return false; }
public void Read(System.IO.BinaryReader r) { Init(); Char LType; Int32 LLength; while(r.BaseStream.Position < r.BaseStream.Length) { System.IO.MemoryStream s = new System.IO.MemoryStream(); System.IO.BinaryWriter w = new System.IO.BinaryWriter(s); LType = r.ReadChar(); LLength = Pub.Read7BitEncodedInt(r); w.Write(r.ReadBytes(LLength)); OResult.Add(LType, w); } }
private static string ReadString(System.IO.BinaryReader reader) { int i = 0; var cbuffer = new char[16]; do { cbuffer[i] = reader.ReadChar(); } while (cbuffer[i] != '\0' && ++i < cbuffer.Length); return new string(cbuffer).TrimEnd(new char[] { '\0' }); }