Skip to content

Commit

Permalink
issue #3 introduce fix 41 from thriftpy2
Browse files Browse the repository at this point in the history
  • Loading branch information
marekjagielski committed Mar 3, 2019
1 parent 89d1559 commit c57498c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: thriftr
Type: Package
Title: Apache Thrift Client Server
Version: 1.0.3
Date: 2018-09-16
Date: 2019-03-03
Authors@R: c(person("Marek", "Jagielski",
role = c("aut", "cre", "cph"),
email = "[email protected]"),
Expand Down
17 changes: 13 additions & 4 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ fill_incomplete_ttype <- function(tmodule, definition) {
if (type == "list") {
# fill const value
if (definition[[1]] == 'UNKNOWN_CONST') {
ttype <- get_definition(tmodule, incomplete_type$dict[[as.character(definition[[2]])]][[1]], definition[[4]])
ttype <- get_definition(
tmodule, incomplete_type$dict[[as.character(definition[[2]])]][[1]], definition[[4]])
return(Parser$new()$cast(ttype)(definition[[3]]))
}
# fill an incomplete alias ttype
Expand All @@ -75,6 +76,7 @@ fill_incomplete_ttype <- function(tmodule, definition) {
length(clazz) > 1 &&
clazz[[2]] == "thrift") {
for (name in names(definition)) {
# skip inner attribute
if (name %in% c(
"thrift_meta",
"thrift_file",
Expand All @@ -84,7 +86,7 @@ fill_incomplete_ttype <- function(tmodule, definition) {
next
}
attr <- definition[[name]]
definition[[name]] <- fill_incomplete_ttype(tmodule, attr)
definition[[name]] <- fill_incomplete_ttype(definition, attr)
}
}
# handle struct ttype
Expand All @@ -111,11 +113,18 @@ fill_incomplete_ttype <- function(tmodule, definition) {
}
}
# if the ttype which field's ttype contains is incomplete
else if (typeof(value[[3]]) == "list") {
else if (typeof(value[[3]]) == "integer" && as.character(value[[3]]) %in% names(incomplete_type$dict)) {
it <- incomplete_type$dict[[as.character(value[[3]])]]
definition$thrift_spec[[index]] <- list(
value[[1]],
value[[2]],
fill_incomplete_ttype(tmodule, value[[3]]),
fill_incomplete_ttype(
tmodule,
get_definition(
tmodule,
it[[1]],
it[[2]])
),
value[[4]])
}
}
Expand Down
9 changes: 4 additions & 5 deletions tests/testthat/container.thrift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
struct ListStruct {
1: optional list<ListItem> list_items,
}

struct ListItem {
1: optional list<string> list_string,
2: optional list<list<string>> list_list_string,
Expand All @@ -12,8 +16,3 @@ struct MixItem {
1: optional list<map<string, string>> list_map,
2: optional map<string, list<string>> map_list,
}


struct ListStruct {
1: optional list<ListItem> list_items,
}

0 comments on commit c57498c

Please sign in to comment.