Created
February 12, 2022 17:36
-
-
Save likern/760631d8c363c31330ef0076145baf87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const Allocator = std.mem.Allocator; | |
const expect = std.testing.expect; | |
pub const DatabaseVersion = packed struct { | |
major: u16, | |
minor: u16, | |
patch: u16, | |
}; | |
pub const FileLayoutVersion = packed struct { | |
major: u16, | |
minor: u16, | |
patch: u16, | |
}; | |
pub const DatabaseSettings = packed struct { | |
const Self = @This(); | |
name: [8]u8, | |
version: DatabaseVersion, | |
layout: FileLayoutVersion, | |
}; | |
pub const database_settings = DatabaseSettings{ | |
.name = [8]u8{ 0x7a, 0x65, 0x6e, 0x64, 0x79, 0x20, 0x20, 0x20 }, | |
.version = .{ .major = 0, .minor = 0, .patch = 1 }, | |
.layout = .{ .major = 0, .minor = 0, .patch = 1 }, | |
}; | |
pub const MetaBlock = packed struct { | |
const Self = @This(); | |
info: DatabaseSettings, | |
pub fn createNoHash() Self { | |
return Self{ | |
.info = database_settings, | |
}; | |
} | |
}; | |
test "create default metadata block" { | |
try expect(database_settings.version.major == 0); | |
var source_meta_block = MetaBlock.createNoHash(); | |
std.debug.print("major: {}\n", .{source_meta_block.info.version.major}); | |
try expect(source_meta_block.info.version.major == 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment