Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor publication result to enum #3

Merged
merged 2 commits into from
Nov 6, 2024
Merged
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 build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.{
.name = "aeron",
.version = "1.46.6+x86",
.version = "1.46.6+enum",
.minimum_zig_version = "0.13.0",
.paths = .{
"build.zig",
Expand Down
27 changes: 17 additions & 10 deletions src/aeron.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ pub const DataHeader = aeronC.aeron_data_header_t;
pub const CncConstants = aeronC.aeron_cnc_constants_t;
pub const CounterReaderForeachFunc = aeronC.aeron_counters_reader_foreach_counter_func_t;

pub const PUBLICATION_NOT_CONNECTED = aeronC.AERON_PUBLICATION_NOT_CONNECTED;
pub const PUBLICATION_BACK_PRESSURED = aeronC.AERON_PUBLICATION_BACK_PRESSURED;
pub const PUBLICATION_ADMIN_ACTION = aeronC.AERON_PUBLICATION_ADMIN_ACTION;
pub const PUBLICATION_CLOSED = aeronC.AERON_PUBLICATION_CLOSED;
pub const PUBLICATION_MAX_POSITION_EXCEEDED = aeronC.AERON_PUBLICATION_MAX_POSITION_EXCEEDED;
pub const PUBLICATION_ERROR = aeronC.AERON_PUBLICATION_ERROR;
pub const PublicationResult = enum(c_long) {
not_connected = aeronC.AERON_PUBLICATION_NOT_CONNECTED,
back_pressured = aeronC.AERON_PUBLICATION_BACK_PRESSURED,
admin_action = aeronC.AERON_PUBLICATION_ADMIN_ACTION,
closed = aeronC.AERON_PUBLICATION_CLOSED,
max_position_exceeded = aeronC.AERON_PUBLICATION_MAX_POSITION_EXCEEDED,
other_error = aeronC.AERON_PUBLICATION_ERROR,
_,

pub fn isError(self: PublicationResult) bool {
return @intFromEnum(self) < 0;
}
};

fn err(e: c_int) !void {
if (e < 0) {
Expand Down Expand Up @@ -174,8 +181,8 @@ pub const Subscription = struct {
pub const Publication = extern struct {
publication: *aeronC.aeron_publication_t,

pub fn tryClaim(self: Publication, length: usize, claim: *BufferClaim) i64 {
return aeronC.aeron_publication_try_claim(self.publication, length, &claim.claim);
pub fn tryClaim(self: Publication, length: usize, claim: *BufferClaim) PublicationResult {
return @enumFromInt(aeronC.aeron_publication_try_claim(self.publication, length, &claim.claim));
}

pub fn deinit(self: Publication) !void {
Expand All @@ -186,8 +193,8 @@ pub const Publication = extern struct {
pub const ExclusivePublication = struct {
publication: *aeronC.aeron_exclusive_publication_t,

pub fn tryClaim(self: ExclusivePublication, length: usize, claim: *BufferClaim) i64 {
return aeronC.aeron_exclusive_publication_try_claim(self.publication, length, &claim.claim);
pub fn tryClaim(self: ExclusivePublication, length: usize, claim: *BufferClaim) PublicationResult {
return @enumFromInt(aeronC.aeron_exclusive_publication_try_claim(self.publication, length, &claim.claim));
}

pub fn deinit(self: ExclusivePublication) !void {
Expand Down