Created config.zig and BUFFERSIZE

This commit is contained in:
Adrien Bouvais 2024-10-17 19:38:08 +02:00
parent be9d4cb63d
commit 783697d4df
3 changed files with 13 additions and 8 deletions

1
src/config.zig Normal file
View File

@ -0,0 +1 @@
pub const BUFFER_SIZE = 1024 * 50; // Line limit when parsing file

View File

@ -12,6 +12,8 @@ const SchemaTokenizer = @import("tokenizers/schema.zig").Tokenizer;
const SchemaToken = @import("tokenizers/schema.zig").Token;
const AdditionalData = @import("stuffs/additionalData.zig").AdditionalData;
const BUFFER_SIZE = @import("config.zig").BUFFER_SIZE;
// TODO: Use those errors everywhere in this file
const FileEngineError = error{
SchemaFileNotFound,
@ -35,7 +37,7 @@ pub const FileEngine = struct {
pub fn init(allocator: Allocator, path: []const u8) FileEngine {
const path_to_ZipponDB_dir = path;
var schema_buf = allocator.alloc(u8, 1024 * 50) catch @panic("Cant allocate the schema buffer");
var schema_buf = allocator.alloc(u8, BUFFER_SIZE) catch @panic("Cant allocate the schema buffer");
defer allocator.free(schema_buf);
const len: usize = FileEngine.readSchemaFile(allocator, path_to_ZipponDB_dir, schema_buf) catch 0;
@ -180,7 +182,7 @@ pub const FileEngine = struct {
/// Request a path to a schema file and then create the struct folder
/// TODO: Check if some data already exist and if so ask if the user want to delete it and make a backup
pub fn initDataFolder(self: *FileEngine, path_to_schema_file: []const u8) FileEngineError!void {
var schema_buf = self.allocator.alloc(u8, 1024 * 50) catch @panic("Cant allocate the schema buffer");
var schema_buf = self.allocator.alloc(u8, BUFFER_SIZE) catch @panic("Cant allocate the schema buffer");
defer self.allocator.free(schema_buf);
const file = std.fs.cwd().openFile(path_to_schema_file, .{}) catch return FileEngineError.SchemaFileNotFound;
@ -240,7 +242,7 @@ pub const FileEngine = struct {
};
defer file.close();
var output: [1024 * 50]u8 = undefined; // Maybe need to increase that as it limit the size of a line in a file
var output: [BUFFER_SIZE]u8 = undefined; // Maybe need to increase that as it limit the size of a line in a file
var output_fbs = std.io.fixedBufferStream(&output);
const writer = output_fbs.writer();
@ -362,7 +364,7 @@ pub const FileEngine = struct {
};
defer file.close();
var output: [1024 * 50]u8 = undefined; // Maybe need to increase that as it limit the size of a line in a file
var output: [BUFFER_SIZE]u8 = undefined; // Maybe need to increase that as it limit the size of a line in a file
var output_fbs = std.io.fixedBufferStream(&output);
const writer = output_fbs.writer();
@ -427,7 +429,7 @@ pub const FileEngine = struct {
};
defer file.close();
var output: [1024 * 50]u8 = undefined; // Maybe need to increase that as it limit the size of a line in a file
var output: [BUFFER_SIZE]u8 = undefined; // Maybe need to increase that as it limit the size of a line in a file
var output_fbs = std.io.fixedBufferStream(&output);
const writer = output_fbs.writer();
@ -626,7 +628,7 @@ pub const FileEngine = struct {
};
defer new_file.close();
var output: [1024 * 50]u8 = undefined; // Maybe need to increase that as it limit the size of a line in a file
var output: [BUFFER_SIZE]u8 = undefined; // Maybe need to increase that as it limit the size of a line in a file
var output_fbs = std.io.fixedBufferStream(&output);
const writer = output_fbs.writer();
@ -778,7 +780,7 @@ pub const FileEngine = struct {
};
defer new_file.close();
var output: [1024 * 50]u8 = undefined; // Maybe need to increase that as it limit the size of a line in a file
var output: [BUFFER_SIZE]u8 = undefined; // Maybe need to increase that as it limit the size of a line in a file
var output_fbs = std.io.fixedBufferStream(&output);
const writer = output_fbs.writer();

View File

@ -9,6 +9,8 @@ const ziqlParser = @import("ziqlParser.zig").Parser;
const utils = @import("stuffs/utils.zig");
const send = @import("stuffs/utils.zig").send;
const BUFFER_SIZE = @import("config.zig").BUFFER_SIZE;
const State = enum {
expect_main_command,
expect_query,
@ -53,7 +55,7 @@ pub fn main() !void {
std.debug.print("No ZIPONDB_PATH environment variable found, please use the command:\n db use path/to/db \nor\n db new /path/to/dir\n", .{});
}
const line_buf = try allocator.alloc(u8, 1024 * 50); // TODO: Remove the size limitation
const line_buf = try allocator.alloc(u8, BUFFER_SIZE); // TODO: Remove the size limitation
defer allocator.free(line_buf);
while (true) {