Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: 0.16.0-dev.2187+e2338edb4

- uses: actions/github-script@v7
id: parse-version-protobuf
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: 0.16.0-dev.2187+e2338edb4

- name: Run zig fmt
if: matrix.os == 'Linux'
Expand Down
5 changes: 2 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ pub fn build(b: *std.Build) !void {
);

const protoc_step = protobuf.RunProtocStep.create(
b,
protobuf_dep.builder,
target,
.{
.destination_directory = b.path("src/protobuf"),
.source_files = &.{"mmc.proto"},
.include_directories = &.{"protobuf"},
.source_files = &.{b.path("protobuf/mmc.proto")},
.include_directories = &.{b.path("protobuf")},
},
);

Expand Down
6 changes: 3 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
.name = .mmc_api,
.version = "0.0.0",
.fingerprint = 0xdcdffdab47da9a3f,
.minimum_zig_version = "0.15.2",
.minimum_zig_version = "0.16.0-dev.2187+e2338edb4",
.dependencies = .{
.protobuf = .{
.url = "https://github.com/mochalins/protobuf.zig/archive/477466e.tar.gz",
.hash = "protobuf-0.1.0-0e82aqvRAwBo5-ccOGlXywY9X4lkQUx02CwMBE_fq4AI",
.url = "https://github.com/Arwalk/zig-protobuf/archive/c3f8fdc.tar.gz",
.hash = "protobuf-3.0.0-0e82aohXKQDcG92gcsmBaK7hZ9PVbwcCND1hyCEtzgd9",
},
},
.paths = .{""},
Expand Down
14 changes: 10 additions & 4 deletions protobuf/mmc/info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ message Request {
// ID is provided, then request for status of all commands from the server.
//
// Expected response: `mmc.Response.body.info.body.commands`
message Command { optional uint32 id = 1; }
message Command {
optional uint32 id = 1;
}

// Request track state information from server. One or more of the `info_`
// flags must be enabled to select the kind of track information desired.
Expand Down Expand Up @@ -62,7 +64,9 @@ message Request {
}

// List of IDs. At least one ID must be provided.
message Ids { repeated uint32 ids = 1; }
message Ids {
repeated uint32 ids = 1;
}
}

enum Error {
Expand Down Expand Up @@ -94,7 +98,9 @@ message Response {
Request.Error request_error = 3;
}

message Commands { repeated Command items = 1; }
message Commands {
repeated Command items = 1;
}

message Command {
// Command ID. Valid IDs begin from 1, and may be reused after command
Expand Down Expand Up @@ -127,7 +133,7 @@ message Response {
COMMAND_ERROR_INVALID_SYSTEM_STATE = 1;
// Deprecated. Check `COMMAND_REQUEST_ERROR_INVALID_CARRIER` on
// `Command.Request.Error`.
COMMAND_ERROR_INVALID_CARRIER_ID = 2 [ deprecated = true ];
COMMAND_ERROR_INVALID_CARRIER_ID = 2 [deprecated = true];
// Driver connection failed while command progressing.
COMMAND_ERROR_DRIVER_DISCONNECTED = 3;
// Unexpected command execution error. This is likely an implementation
Expand Down
1 change: 1 addition & 0 deletions protobuf/range.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
syntax = "proto3";
package mmc;

message Range {
// Start of range, inclusive.
Expand Down
168 changes: 131 additions & 37 deletions src/protobuf/mmc.pb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,98 @@
///! package mmc
const std = @import("std");

const pb = @import("protobuf");
const fd = pb.fd;
const protobuf = @import("protobuf");
const fd = protobuf.fd;
/// import package mmc.core
pub const core = @import("mmc/core.pb.zig");
const mmc_core = @import("mmc/core.pb.zig");
/// import package mmc.command
pub const command = @import("mmc/command.pb.zig");
const mmc_command = @import("mmc/command.pb.zig");
/// import package mmc.info
pub const info = @import("mmc/info.pb.zig");
const mmc_info = @import("mmc/info.pb.zig");

/// Carrier motor control kind.
pub const Control = enum(i32) {
CONTROL_UNSPECIFIED = 0,
CONTROL_POSITION = 1,
CONTROL_VELOCITY = 2,
_,
};

pub const Range = struct {
start: u32 = 0,
end: u32 = 0,

pub const _desc_table = .{
.start = fd(1, .{ .scalar = .uint32 }),
.end = fd(2, .{ .scalar = .uint32 }),
};

/// Encodes the message to the writer
/// The allocator is used to generate submessages internally.
/// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck.
pub fn encode(
self: @This(),
writer: *std.Io.Writer,
allocator: std.mem.Allocator,
) (std.Io.Writer.Error || std.mem.Allocator.Error)!void {
return protobuf.encode(writer, allocator, self);
}

/// Decodes the message from the bytes read from the reader.
pub fn decode(
reader: *std.Io.Reader,
allocator: std.mem.Allocator,
) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() {
return protobuf.decode(@This(), reader, allocator);
}

/// Deinitializes and frees the memory associated with the message.
pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void {
return protobuf.deinit(allocator, self);
}

/// Duplicates the message.
pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() {
return protobuf.dupe(@This(), self, allocator);
}

/// Decodes the message from the JSON string.
pub fn jsonDecode(
input: []const u8,
options: std.json.ParseOptions,
allocator: std.mem.Allocator,
) !std.json.Parsed(@This()) {
return protobuf.json.decode(@This(), input, options, allocator);
}

/// Encodes the message to a JSON string.
pub fn jsonEncode(
self: @This(),
options: std.json.Stringify.Options,
allocator: std.mem.Allocator,
) ![]const u8 {
return protobuf.json.encode(self, options, allocator);
}

/// This method is used by std.json
/// internally for deserialization. DO NOT RENAME!
pub fn jsonParse(
allocator: std.mem.Allocator,
source: anytype,
options: std.json.ParseOptions,
) !@This() {
return protobuf.json.parse(@This(), allocator, source, options);
}

/// This method is used by std.json
/// internally for serialization. DO NOT RENAME!
pub fn jsonStringify(self: *const @This(), jws: anytype) !void {
return protobuf.json.stringify(@This(), self, jws);
}
};

/// Request message. All client-to-server messages should be of this message
/// type.
pub const Request = struct {
body: ?body_union = null,

Expand All @@ -27,9 +103,9 @@ pub const Request = struct {
info,
};
pub const body_union = union(_body_case) {
core: core.Request,
command: command.Request,
info: info.Request,
core: mmc_core.Request,
command: mmc_command.Request,
info: mmc_info.Request,
pub const _desc_table = .{
.core = fd(1, .submessage),
.command = fd(2, .submessage),
Expand All @@ -47,62 +123,72 @@ pub const Request = struct {
_,
};

/// Encodes the message to the writer
/// The allocator is used to generate submessages internally.
/// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck.
pub fn encode(
self: @This(),
writer: *std.Io.Writer,
allocator: std.mem.Allocator,
) (std.Io.Writer.Error || std.mem.Allocator.Error)!void {
return pb.encode(writer, allocator, self);
return protobuf.encode(writer, allocator, self);
}

/// Decodes the message from the bytes read from the reader.
pub fn decode(
reader: *std.Io.Reader,
allocator: std.mem.Allocator,
) (pb.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() {
return pb.decode(@This(), reader, allocator);
) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() {
return protobuf.decode(@This(), reader, allocator);
}

/// Deinitializes and frees the memory associated with the message.
pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void {
return pb.deinit(allocator, self);
return protobuf.deinit(allocator, self);
}

/// Duplicates the message.
pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() {
return pb.dupe(@This(), self, allocator);
return protobuf.dupe(@This(), self, allocator);
}

/// Decodes the message from the JSON string.
pub fn jsonDecode(
input: []const u8,
options: std.json.ParseOptions,
allocator: std.mem.Allocator,
) !std.json.Parsed(@This()) {
return pb.json.decode(@This(), input, options, allocator);
return protobuf.json.decode(@This(), input, options, allocator);
}

/// Encodes the message to a JSON string.
pub fn jsonEncode(
self: @This(),
options: std.json.Stringify.Options,
allocator: std.mem.Allocator,
) ![]const u8 {
return pb.json.encode(self, options, allocator);
return protobuf.json.encode(self, options, allocator);
}

// This method is used by std.json
// internally for deserialization. DO NOT RENAME!
/// This method is used by std.json
/// internally for deserialization. DO NOT RENAME!
pub fn jsonParse(
allocator: std.mem.Allocator,
source: anytype,
options: std.json.ParseOptions,
) !@This() {
return pb.json.parse(@This(), allocator, source, options);
return protobuf.json.parse(@This(), allocator, source, options);
}

// This method is used by std.json
// internally for serialization. DO NOT RENAME!
/// This method is used by std.json
/// internally for serialization. DO NOT RENAME!
pub fn jsonStringify(self: *const @This(), jws: anytype) !void {
return pb.json.stringify(@This(), self, jws);
return protobuf.json.stringify(@This(), self, jws);
}
};

/// Response message. All server-to-client messages will be of this message
/// type.
pub const Response = struct {
body: ?body_union = null,

Expand All @@ -113,9 +199,9 @@ pub const Response = struct {
request_error,
};
pub const body_union = union(_body_case) {
core: core.Response,
command: command.Response,
info: info.Response,
core: mmc_core.Response,
command: mmc_command.Response,
info: mmc_info.Response,
request_error: Request.Error,
pub const _desc_table = .{
.core = fd(1, .submessage),
Expand All @@ -129,58 +215,66 @@ pub const Response = struct {
.body = fd(null, .{ .oneof = body_union }),
};

/// Encodes the message to the writer
/// The allocator is used to generate submessages internally.
/// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck.
pub fn encode(
self: @This(),
writer: *std.Io.Writer,
allocator: std.mem.Allocator,
) (std.Io.Writer.Error || std.mem.Allocator.Error)!void {
return pb.encode(writer, allocator, self);
return protobuf.encode(writer, allocator, self);
}

/// Decodes the message from the bytes read from the reader.
pub fn decode(
reader: *std.Io.Reader,
allocator: std.mem.Allocator,
) (pb.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() {
return pb.decode(@This(), reader, allocator);
) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() {
return protobuf.decode(@This(), reader, allocator);
}

/// Deinitializes and frees the memory associated with the message.
pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void {
return pb.deinit(allocator, self);
return protobuf.deinit(allocator, self);
}

/// Duplicates the message.
pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() {
return pb.dupe(@This(), self, allocator);
return protobuf.dupe(@This(), self, allocator);
}

/// Decodes the message from the JSON string.
pub fn jsonDecode(
input: []const u8,
options: std.json.ParseOptions,
allocator: std.mem.Allocator,
) !std.json.Parsed(@This()) {
return pb.json.decode(@This(), input, options, allocator);
return protobuf.json.decode(@This(), input, options, allocator);
}

/// Encodes the message to a JSON string.
pub fn jsonEncode(
self: @This(),
options: std.json.Stringify.Options,
allocator: std.mem.Allocator,
) ![]const u8 {
return pb.json.encode(self, options, allocator);
return protobuf.json.encode(self, options, allocator);
}

// This method is used by std.json
// internally for deserialization. DO NOT RENAME!
/// This method is used by std.json
/// internally for deserialization. DO NOT RENAME!
pub fn jsonParse(
allocator: std.mem.Allocator,
source: anytype,
options: std.json.ParseOptions,
) !@This() {
return pb.json.parse(@This(), allocator, source, options);
return protobuf.json.parse(@This(), allocator, source, options);
}

// This method is used by std.json
// internally for serialization. DO NOT RENAME!
/// This method is used by std.json
/// internally for serialization. DO NOT RENAME!
pub fn jsonStringify(self: *const @This(), jws: anytype) !void {
return pb.json.stringify(@This(), self, jws);
return protobuf.json.stringify(@This(), self, jws);
}
};
Loading