Fix ring buffer
This commit is contained in:
parent
e70a04ac16
commit
c9c2b45b2a
17 changed files with 330 additions and 135 deletions
|
@ -1,12 +1,15 @@
|
|||
const std = @import("std");
|
||||
const zap = @import("zap");
|
||||
|
||||
const models = @import("../models/root.zig");
|
||||
const web_models = @import("../models/root.zig");
|
||||
const stores = @import("../stores/root.zig");
|
||||
const models = @import("../../models/root.zig");
|
||||
const msg_queue = @import("../../msg_queue/root.zig");
|
||||
|
||||
const Self = @This();
|
||||
|
||||
const log = std.log.scoped(.block_endpoint);
|
||||
|
||||
pub const default_path = "block";
|
||||
|
||||
allocator: std.mem.Allocator,
|
||||
|
@ -36,16 +39,15 @@ pub fn post(_: *Self, r: zap.Request) !void {
|
|||
pub fn put(self: *Self, r: zap.Request) !void {
|
||||
blk: {
|
||||
if (r.body) |body| {
|
||||
const maybe_block: ?std.json.Parsed(models.Block) = std.json.parseFromSlice(models.Block, self.allocator, body, .{}) catch null;
|
||||
const maybe_block: ?std.json.Parsed(web_models.Block) = std.json.parseFromSlice(web_models.Block, self.allocator, body, .{}) catch null;
|
||||
if (maybe_block) |parsed| {
|
||||
defer parsed.deinit();
|
||||
const block = parsed.value;
|
||||
if (block.material.len > msg_queue.messages.BlockUpdate.material_len_max or !models.Block.materialIsValid(block.material)) {
|
||||
if (block.material.len > models.BlockUpdateMsg.material_max_len or !web_models.Block.materialIsValid(block.material)) {
|
||||
break :blk;
|
||||
}
|
||||
std.log.info("block: {}", .{block});
|
||||
|
||||
var msg = msg_queue.messages.BlockUpdate{
|
||||
var msg = models.BlockUpdateMsg{
|
||||
.dimension = block.dimension,
|
||||
.x = block.x,
|
||||
.y = block.y,
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
const std = @import("std");
|
||||
|
||||
dimension: u8,
|
||||
x: i32,
|
||||
y: i32,
|
||||
z: i32,
|
||||
const models = @import("../../models/root.zig");
|
||||
|
||||
dimension: models.BlockUpdateMsg.Dimension,
|
||||
x: models.BlockUpdateMsg.Coordinate,
|
||||
y: models.BlockUpdateMsg.Coordinate,
|
||||
z: models.BlockUpdateMsg.Coordinate,
|
||||
material: []const u8,
|
||||
|
||||
pub fn materialIsValid(material: []const u8) bool {
|
||||
|
|
|
@ -2,18 +2,29 @@ const std = @import("std");
|
|||
const zap = @import("zap");
|
||||
|
||||
const msg_queue = @import("../msg_queue/root.zig");
|
||||
const models = @import("../models/root.zig");
|
||||
|
||||
const models = @import("models/root.zig");
|
||||
const endpoints = @import("endpoints/root.zig");
|
||||
const stores = @import("stores/root.zig");
|
||||
|
||||
const log = std.log.scoped(.web);
|
||||
|
||||
pub const Config = struct {
|
||||
port: u16,
|
||||
threads: u8,
|
||||
};
|
||||
|
||||
fn onRequest(r: zap.Request) !void {
|
||||
_ = r;
|
||||
}
|
||||
|
||||
pub fn start(allocator: std.mem.Allocator, threads: i16, port: u16, queue: *msg_queue.MsgQueueUnmanaged(msg_queue.messages.BlockUpdate)) !void {
|
||||
pub fn start(
|
||||
allocator: std.mem.Allocator,
|
||||
config: *const Config,
|
||||
queue: *msg_queue.MsgQueueUnmanaged(models.BlockUpdateMsg),
|
||||
) !void {
|
||||
var listener = zap.Endpoint.Listener.init(allocator, .{
|
||||
.port = port,
|
||||
.port = config.port,
|
||||
.on_request = onRequest,
|
||||
.log = true,
|
||||
});
|
||||
|
@ -32,10 +43,10 @@ pub fn start(allocator: std.mem.Allocator, threads: i16, port: u16, queue: *msg_
|
|||
try listener.register(&block_endpoint);
|
||||
|
||||
try listener.listen();
|
||||
std.log.info("Listening on 0.0.0.0:{d}", .{port});
|
||||
log.info("Listening on 0.0.0.0:{d}", .{config.port});
|
||||
|
||||
zap.start(.{
|
||||
.threads = threads,
|
||||
.threads = @intCast(config.threads),
|
||||
.workers = 1,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const msg_queue = @import("../../msg_queue/root.zig");
|
||||
const models = @import("../../models/root.zig");
|
||||
|
||||
queue: *msg_queue.MsgQueueUnmanaged(msg_queue.messages.BlockUpdate),
|
||||
queue: *msg_queue.MsgQueueUnmanaged(models.BlockUpdateMsg),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue