Created
February 24, 2020 10:36
-
-
Save badboy/1dccdb7e008cca53e93f970243e76ebb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
struct UploadTask { | |
uint8_t tag; | |
const char* uuid; | |
const char* url; | |
const char* body; | |
}; | |
struct Wait { | |
uint8_t tag; | |
}; | |
struct Done { | |
uint8_t tag; | |
}; | |
union PingUploadTask { | |
struct UploadTask U; | |
struct Wait W; | |
struct Done D; | |
}; | |
union PingUploadTask union_get(); | |
int main(int argc, char** argv) | |
{ | |
union PingUploadTask task = union_get(); | |
printf("tag: %d\n", task.U.tag); | |
if (task.U.tag == 0) { | |
printf("uuid: %s\n", task.U.uuid); | |
printf("url: %s\n", task.U.url); | |
printf("body: %s\n", task.U.body); | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::os::raw::c_char; | |
use std::ffi::CString; | |
#[repr(u8)] | |
pub enum PingUploadTask { | |
/// A PingRequest popped from the front of the queue. | |
/// See [`PingRequest`](struct.PingRequest.html) for more information. | |
Upload { uuid: *const c_char, url: *const c_char, body: *const c_char }, | |
/// A flag signaling that the pending pings directories are not done being processed, | |
/// thus the requester should wait and come back later. | |
Wait, | |
/// A flag signaling that the pending pings queue is empty and requester is done. | |
Done, | |
} | |
#[no_mangle] | |
extern "C" fn union_get() -> PingUploadTask { | |
let uuid = CString::new("c0ffee").unwrap(); | |
let url = CString::new("https://incoming.telemetry.mozilla.org/").unwrap(); | |
let body = CString::new("{}").unwrap(); | |
PingUploadTask::Upload { | |
uuid: uuid.into_raw(), | |
url: url.into_raw(), | |
body: body.into_raw(), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment