Example #1
0
        public static Data From_Bytes(byte[] buffer, int totalLenght)
        {
            var data = new Data
            {
                Key = BitConverter.ToInt32(buffer, 0),
                Timestamp = DateTime.FromBinary(BitConverter.ToInt64(buffer, 4)),
                Version = BitConverter.ToInt32(buffer, 12),
                Payload = new byte[totalLenght - 20]
            };

            Array.Copy(buffer, 16, data.Payload, 0, totalLenght - 20);

            return data;
        }
        protected void Write_Data(byte[] value, int key, int version)
        {
            var data = new Data
            {
                Key = key,
                Version = version,
                Payload= value,
                Timestamp = DateTime.Now
            };

            var address = Data_Pointer();
            Data_Stream.Seek(address, SeekOrigin.Begin);

            var bytes = data.To_Bytes();
            Data_Stream.Write(bytes, 0, bytes.Length);

            _data_Pointer += bytes.Length;
        }