Skip to content

Commit

Permalink
Merge pull request #5 from lun-4/streaming-api
Browse files Browse the repository at this point in the history
add streaming API
  • Loading branch information
lun-4 authored Feb 9, 2023
2 parents e568708 + aba3883 commit 166bd8c
Show file tree
Hide file tree
Showing 11 changed files with 1,279 additions and 386 deletions.
44 changes: 26 additions & 18 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Builder = std.build.Builder;
const std = @import("std");
pub fn build(b: *Builder) void {
const native_opt = b.option(bool, "native", "if many cpu, turn this on");
const native_opt = b.option(bool, "native", "if other people exist, turn this off");
const option_libc = (b.option(bool, "libc", "build with libc?")) orelse false;
const is_native = native_opt orelse true;

Expand All @@ -17,21 +17,32 @@ pub fn build(b: *Builder) void {
});
}

const mode = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{});

// this exports both a library and a binary

const exe = b.addExecutable("zigdig", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
const exe = b.addExecutable(.{
.name = "zigdig",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
if (option_libc) exe.linkLibC();
exe.install();

const exe_tinyhost = b.addExecutable(.{
.name = "zigdig-tiny",
.root_source_file = .{ .path = "src/main_tinyhost.zig" },
.target = target,
.optimize = optimize,
});
if (option_libc) exe.linkLibC();
exe_tinyhost.install();

const lib = b.addStaticLibrary("zigdig", "src/lib.zig");
lib.setTarget(target);
lib.setBuildMode(mode);

var lib_tests = b.addTest("src/main.zig");
lib_tests.setBuildMode(mode);
var lib_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.optimize = optimize,
});

const test_step = b.step("test", "Run library tests");
test_step.dependOn(&lib_tests.step);
Expand All @@ -40,12 +51,9 @@ pub fn build(b: *Builder) void {
const run_step = b.step("run", "Run example binary");
run_step.dependOn(&run_cmd.step);

b.default_step.dependOn(&lib.step);
b.default_step.dependOn(&exe.step);

lib.addPackagePath("dns", "src/lib.zig");
exe.addPackagePath("dns", "src/lib.zig");

b.installArtifact(lib);
b.addModule(.{
.name = "dns",
.source_file = .{ .path = "src/lib.zig" },
});
b.installArtifact(exe);
}
11 changes: 11 additions & 0 deletions src/enums.zig
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ pub const ResourceClass = enum(u16) {
HS = 4,
WILDCARD = 255,

pub fn readFrom(reader: anytype) !@This() {
const resource_class_int = try reader.readIntBig(u16);
return std.meta.intToEnum(@This(), resource_class_int) catch |err| {
logger.err(
"unknown resource class {d}, got {s}",
.{ resource_class_int, @errorName(err) },
);
return err;
};
}

pub fn writeTo(self: @This(), writer: anytype) !usize {
try writer.writeIntBig(u16, @enumToInt(self));
return 16 / 8;
Expand Down
Loading

0 comments on commit 166bd8c

Please sign in to comment.