https://github.com/soheil-01/dmidecode
dmidecode parser in zig
https://github.com/soheil-01/dmidecode
dmidecode zig
Last synced: about 1 year ago
JSON representation
dmidecode parser in zig
- Host: GitHub
- URL: https://github.com/soheil-01/dmidecode
- Owner: soheil-01
- Created: 2024-03-04T11:49:21.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-04T12:46:26.000Z (about 2 years ago)
- Last Synced: 2025-01-07T10:24:53.209Z (about 1 year ago)
- Topics: dmidecode, zig
- Language: Zig
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DMIDecode
My first project while learning Zig. This is a Zig implementation for parsing the output of the `dmidecode` command. This is a port of [dmidecode-nim](https://github.com/xmonader/nim-dmidecode).
## Quick Start
```zig
const std = @import("std");
const DMIDecode = @import("dmidecode.zig").DMIDecode;
pub fn main() !void {
var parser = DMIDecode.init(std.heap.page_allocator);
defer parser.deinit();
const sections = try parser.parse(
\\Handle 0x0036, DMI type 43, 31 bytes
\\TPM Device
\\ Vendor ID: INTC
\\ Specification Version: 2.0
\\ Firmware Revision: 500.5
\\ Strings:
\\ Insyde_ASF_001
\\ Insyde_ASF_002
\\
);
const section: DMIDecode.Section = sections.get("TPM Device").?;
std.debug.print("Handle: {s}, Title: {s}\n", .{ section.handleLine, section.title });
const vendorID = section.props.get("Vendor ID").?.val;
std.debug.print("Vendor ID: {s}\n", .{vendorID});
const strings = section.props.get("Strings").?.items;
std.debug.print("Strings: {s}, {s}\n", .{ strings.items[0], strings.items[0] });
}
```
## Installation
1. Declare dmidecode as a project dependency with `zig fetch`:
```bash
zig fetch --save git+https://github.com/soheil-01/dmidecode.git#main
```
2. Expose dmidecode as a module in your project's `build.zig`:
```zig
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const opts = .{ .target = target, .optimize = optimize }; // 👈
const dmidecode_mod = b.dependency("dmidecode", opts).module("dmidecode"); // 👈
const exe = b.addExecutable(.{
.name = "my-project",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("dmidecode", dmidecode_mod); // 👈
// ...
}
```
3. Import dmidecode into your code:
```zig
const dmidecode = @import("dmidecode");
```