Esempio n. 1
0
        public static void ReadFromFile(IndexPage indexPage, BinaryReader reader)
        {
            // Seek the stream to the first byte on page
            long initPos = reader.SetReadPos(Header.FILE_START_HEADER_SIZE + (indexPage.PageID * BasePage.PAGE_SIZE));

            if (reader.ReadByte() != (byte)PageType.Index)
                throw new FileDBException("PageID {0} is not a Index Page", indexPage.PageID);

            indexPage.NextPageID = reader.ReadUInt32();
            indexPage.SetUsedNodeCount(reader.ReadByte());
            // Seek the stream to end of header data page
            reader.SetReadPos(initPos + IndexPage.INDEX_HEADER_SIZE);

            //in this version 
            //each node uses buffer= 16+1+1+4+1+4+4+8+4+2+36 =81 
            //IndexPage.NODES_PER_PAGE = 50;
            //so it use 81*50 = 4050
            //IndexPage.INDEX_HEADER_SIZE =46
            //so => 4050 +46 = 4096 
            //and each page has BasePage.PAGE_SIZE = 4096 => matched

            for (int i = 0; i <= indexPage.UsedNodeCount; i++)
            {
                var node = indexPage.Nodes[i];

                node.ID = reader.ReadGuid(); //16

                node.IsDeleted = reader.ReadBoolean(); //1 

                node.Right.Index = reader.ReadByte(); //1 
                node.Right.PageID = reader.ReadUInt32(); //4
                node.Left.Index = reader.ReadByte(); //1 
                node.Left.PageID = reader.ReadUInt32();//4

                node.DataPageID = reader.ReadUInt32();//4

                node.FileMetaDataLength = reader.ReadUInt16();//2
                node.FileLength = reader.ReadUInt32();//4

                int filenameCount = reader.ReadByte(); //1
                if (filenameCount > IndexNode.FILENAME_SIZE)
                {
                    node.FileUrl = reader.ReadUtf8String(IndexNode.FILENAME_SIZE);
                }
                else
                {
                    string filename = reader.ReadUtf8String(IndexNode.FILENAME_SIZE);
                    node.FileUrl = filename.Substring(0, filenameCount);
                }
            }
        }
Esempio n. 2
0
		/// <summary>
		/// Deserializes a new instance of the ServerMessage1 class from the
		/// specified buffer of bytes.
		/// </summary>
		/// <param name="buffer">The byte buffer to deserialize the ServerMessage1
		/// instance from.</param>
		/// <returns>An instance of the ServerMessage1 class deserialized from the
		/// specified byte array.</returns>
		/// <exception cref="FormatException">Thrown if the byte buffer does not
		/// contain valid data.</exception>
		public static ServerMessage1 Deserialize(byte[] buffer) {
			using (var ms = new MemoryStream(buffer)) {
				using (var r = new BinaryReader(ms)) {
					uint bufferLength = r.ReadUInt32(true);
					// We don't support re-using previous sessions.
					byte reuse = r.ReadByte();
					if (reuse != 0) {
						throw new FormatException("Unexpected re-use parameter value: " +
							reuse);
					}
					Mpi N = r.ReadMpi();
					Mpi g = r.ReadMpi();
					OctetSequence salt = r.ReadOs();
					Mpi B = r.ReadMpi();
					Utf8String L = r.ReadUtf8String();
					return new ServerMessage1() {
						Generator = g,
						PublicKey = B,
						Salt = salt.Value,
						SafePrimeModulus = N,
						Options = ParseOptions(L.Value),
						RawOptions = L.Value
					};
				}
			}
		}
Esempio n. 3
0
        public static ServerMessage1 Deserialize(byte[] buffer)
        {
            using (var ms = new MemoryStream(buffer))
            {
                using (var r = new BinaryReader(ms))
                {
                    byte reuse = r.ReadByte();
                    if (reuse != 0)
                    {
                        throw new FormatException("Unexpected re-use parameter value: " + reuse);
                    }

                    Mpi n = r.ReadMpi();
                    Mpi g = r.ReadMpi();
                    OctetSequence salt = r.ReadOs();
                    Mpi b = r.ReadMpi();
                    Utf8String l = r.ReadUtf8String();
                    return new ServerMessage1()
                    {
                        Generator = g,
                        PublicKey = b,
                        Salt = salt.Value,
                        SafePrimeModulus = n,
                        Options = ParseOptions(l.Value),
                        RawOptions = l.Value
                    };
                }
            }
        }
Esempio n. 4
0
		/// <summary>
		/// Deserializes a new instance of the ServerMessage2 class from the
		/// specified buffer of bytes.
		/// </summary>
		/// <param name="buffer">The byte buffer to deserialize the ServerMessage2
		/// instance from.</param>
		/// <returns>An instance of the ServerMessage2 class deserialized from the
		/// specified byte array.</returns>
		/// <exception cref="FormatException">Thrown if the byte buffer does not
		/// contain valid data.</exception>
		public static ServerMessage2 Deserialize(byte[] buffer) {
			using (var ms = new MemoryStream(buffer)) {
				using (var r = new BinaryReader(ms)) {
					uint bufferLength = r.ReadUInt32(true);
					OctetSequence M2 = r.ReadOs(),
						sIV = r.ReadOs();
					Utf8String sid = r.ReadUtf8String();
					uint ttl = r.ReadUInt32(true);
					return new ServerMessage2() {
						Proof = M2.Value,
						InitialVector = sIV.Value,
						SessionId = sid.Value,
						Ttl = ttl
					};
				}
			}
		}
Esempio n. 5
0
        public static void ReadFromFile(Header header, BinaryReader reader)
        {
            // Seek the stream on 0 position to read header
            reader.BaseStream.Seek(0, SeekOrigin.Begin);

            // Make same validation on header file
            if (reader.ReadUtf8String(Header.FileID.Length) != Header.FileID)
                throw new FileDBException("The file is not a valid storage archive");

            if (reader.ReadInt16() != Header.FileVersion)
                throw new FileDBException("The archive version is not valid");

            header.IndexRootPageID = reader.ReadUInt32();
            header.FreeIndexPageID = reader.ReadUInt32();
            header.FreeDataPageID = reader.ReadUInt32();
            header.LastFreeDataPageID = reader.ReadUInt32();
            header.LastPageID = reader.ReadUInt32();
            header.IsDirty = false;
        }
Esempio n. 6
0
 ///<exclude/>
 public void Deserialize(BinaryReader br)
 {
     seq = br.ReadUInt32();
     stamp = br.ReadDateTime();
     frame_id = br.ReadUtf8String();
 }
Esempio n. 7
0
 ///<exclude/>
 public void Deserialize(BinaryReader br)
 {
     header = new Header(br);
     ns = br.ReadUtf8String();
     id = br.ReadInt32();
     type = br.ReadInt32();
     action = br.ReadInt32();
     pose = new Pose(br);
     scale = new Vector3(br);
     color = new ColorRGBA(br);
     lifetime = br.ReadTimeSpan();
     frame_locked = br.ReadBoolean();
     points = new List<Point>(br.ReadInt32()); for(int i=0; i<points.Capacity; i++) { var x = new Point(br);points.Add(x);}
     colors = new List<ColorRGBA>(br.ReadInt32()); for(int i=0; i<colors.Capacity; i++) { var x = new ColorRGBA(br);colors.Add(x);}
     text = br.ReadUtf8String();
     mesh_resource = br.ReadUtf8String();
     mesh_use_embedded_materials = br.ReadBoolean();
 }
 ///<exclude/>
 public void Deserialize(BinaryReader br)
 {
     header = new Header(br);
     child_frame_id = br.ReadUtf8String();
     transform = new Transform(br);
 }
Esempio n. 9
0
 ///<exclude/>
 public void Deserialize(BinaryReader br)
 {
     header = new Header(br);
     level = br.ReadByte();
     name = br.ReadUtf8String();
     msg = br.ReadUtf8String();
     file = br.ReadUtf8String();
     function = br.ReadUtf8String();
     line = br.ReadUInt32();
     topics = new List<string>(br.ReadInt32()); for(int i=0; i<topics.Capacity; i++) { var x = br.ReadUtf8String();topics.Add(x);}
 }
Esempio n. 10
0
 ///<exclude/>
 public void Deserialize(BinaryReader br)
 {
     label = br.ReadUtf8String();
     size = br.ReadUInt32();
     stride = br.ReadUInt32();
 }
Esempio n. 11
0
 ///<exclude/>
 public void Deserialize(BinaryReader br)
 {
     data = br.ReadUtf8String();
 }
Esempio n. 12
0
 ///<exclude/>
 public void Deserialize(BinaryReader br)
 {
     name = br.ReadUtf8String();
     level = br.ReadUtf8String();
 }