Skip to content

Commit c759c78

Browse files
authored
Re-implement serialization header (#155)
1 parent 7c4ed0f commit c759c78

File tree

11 files changed

+14
-51
lines changed

11 files changed

+14
-51
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export("%~>%")
4444
export("opt<-")
4545
export(.advance)
4646
export(.context)
47-
export(.header)
4847
export(.interrupt)
4948
export(.keep)
5049
export(.mark)

R/utils.R

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -368,23 +368,11 @@ ip_addr <- function() .Call(rnng_ip_addr)
368368
#'
369369
#' Internal package functions.
370370
#'
371-
#' @param value integer value.
372-
#'
373-
#' @return For `.header()`: the integer `value` supplied.
374-
#'
375-
#' @keywords internal
376-
#' @export
377-
#'
378-
.header <- function(value = 0L) .Call(rnng_header_set, value)
379-
380-
#' Read Serialization Header
381-
#'
382371
#' @param x raw vector.
383372
#'
384373
#' @return For `.read_header()`: integer value.
385374
#'
386375
#' @keywords internal
387-
#' @rdname dot-header
388376
#' @export
389377
#'
390378
.read_header <- function(x) .Call(rnng_header_read, x)
@@ -396,7 +384,7 @@ ip_addr <- function() .Call(rnng_ip_addr)
396384
#' @return For `.mark()`: the logical `bool` supplied.
397385
#'
398386
#' @keywords internal
399-
#' @rdname dot-header
387+
#' @rdname dot-read_header
400388
#' @export
401389
#'
402390
.mark <- function(bool = TRUE) .Call(rnng_marker_set, bool)
@@ -408,7 +396,7 @@ ip_addr <- function() .Call(rnng_ip_addr)
408396
#' @return For `.read_marker()`: logical value `TRUE` or `FALSE`.
409397
#'
410398
#' @keywords internal
411-
#' @rdname dot-header
399+
#' @rdname dot-read_header
412400
#' @export
413401
#'
414402
.read_marker <- function(x) .Call(rnng_marker_read, x)

man/dot-header.Rd renamed to man/dot-read_header.Rd

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/nanonext-package.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/aio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP pipe, SEXP
522522
if (raw) {
523523
nano_encode(&buf, data);
524524
} else {
525-
nano_serialize(&buf, data, NANO_PROT(con));
525+
nano_serialize(&buf, data, NANO_PROT(con), 0);
526526
}
527527
nng_msg *msg = NULL;
528528

src/comms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ SEXP rnng_send(SEXP con, SEXP data, SEXP mode, SEXP block, SEXP pipe) {
344344
if (raw) {
345345
nano_encode(&buf, data);
346346
} else {
347-
nano_serialize(&buf, data, NANO_PROT(con));
347+
nano_serialize(&buf, data, NANO_PROT(con), 0);
348348
}
349349
nng_msg *msgp = NULL;
350350

src/core.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
// internals -------------------------------------------------------------------
66

7-
int special_header = 0;
87
static int special_marker = 0;
98
static nano_serial_bundle nano_bundle;
109
static SEXP nano_eval_res;
@@ -316,16 +315,16 @@ SEXP nano_raw_char(const unsigned char *buf, const size_t sz) {
316315

317316
}
318317

319-
void nano_serialize(nano_buf *buf, SEXP object, SEXP hook) {
318+
void nano_serialize(nano_buf *buf, SEXP object, SEXP hook, int header) {
320319

321320
NANO_ALLOC(buf, NANONEXT_INIT_BUFSIZE);
322321
struct R_outpstream_st output_stream;
323322

324-
if (special_header || special_marker) {
323+
if (header || special_marker) {
325324
buf->buf[0] = 0x7;
326325
buf->buf[3] = (uint8_t) special_marker;
327-
if (special_header)
328-
memcpy(buf->buf + 4, &special_header, sizeof(int));
326+
if (header)
327+
memcpy(buf->buf + 4, &header, sizeof(int));
329328
buf->cur += 8;
330329
}
331330

@@ -616,13 +615,6 @@ SEXP rnng_marker_read(SEXP x) {
616615

617616
}
618617

619-
SEXP rnng_header_set(SEXP x) {
620-
621-
special_header = NANO_INTEGER(x);
622-
return x;
623-
624-
}
625-
626618
SEXP rnng_header_read(SEXP x) {
627619

628620
int res = 0;

src/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ static const R_CallMethodDef callMethods[] = {
129129
{"rnng_fini_priors", (DL_FUNC) &rnng_fini_priors, 0},
130130
{"rnng_get_opt", (DL_FUNC) &rnng_get_opt, 2},
131131
{"rnng_header_read", (DL_FUNC) &rnng_header_read, 1},
132-
{"rnng_header_set", (DL_FUNC) &rnng_header_set, 1},
133132
{"rnng_interrupt_switch", (DL_FUNC) &rnng_interrupt_switch, 1},
134133
{"rnng_ip_addr", (DL_FUNC) &rnng_ip_addr, 0},
135134
{"rnng_is_error_value", (DL_FUNC) &rnng_is_error_value, 1},

src/nanonext.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ typedef struct nano_node_s {
244244
struct nano_node_s *next;
245245
} nano_node;
246246

247-
extern int special_header;
248247
extern void (*eln2)(void (*)(void *), void *, double, int);
249248

250249
extern SEXP nano_AioSymbol;
@@ -297,7 +296,7 @@ int nano_integer(const SEXP);
297296
SEXP mk_error(const int);
298297
SEXP mk_error_data(const int);
299298
SEXP nano_raw_char(const unsigned char *, const size_t);
300-
void nano_serialize(nano_buf *, const SEXP, SEXP);
299+
void nano_serialize(nano_buf *, const SEXP, SEXP, int);
301300
SEXP nano_unserialize(unsigned char *, const size_t, SEXP);
302301
SEXP nano_decode(unsigned char *, const size_t, const uint8_t, SEXP);
303302
void nano_encode(nano_buf *, const SEXP);
@@ -341,7 +340,6 @@ SEXP rnng_fini(void);
341340
SEXP rnng_fini_priors(void);
342341
SEXP rnng_get_opt(SEXP, SEXP);
343342
SEXP rnng_header_read(SEXP);
344-
SEXP rnng_header_set(SEXP);
345343
SEXP rnng_interrupt_switch(SEXP);
346344
SEXP rnng_ip_addr(void);
347345
SEXP rnng_is_error_value(SEXP);

src/sync.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ SEXP rnng_request(SEXP con, SEXP data, SEXP sendmode, SEXP recvmode, SEXP timeou
429429
if (raw) {
430430
nano_encode(&buf, data);
431431
} else {
432-
special_header = id;
433-
nano_serialize(&buf, data, NANO_PROT(con));
432+
nano_serialize(&buf, data, NANO_PROT(con), id);
434433
}
435434

436435
saio = calloc(1, sizeof(nano_saio));

0 commit comments

Comments
 (0)