-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Martynas Gurskas <[email protected]>
- Loading branch information
Showing
43 changed files
with
930 additions
and
1,015 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
{{ type_name }} {{ namespace }}::uniffi::{{ ffi_converter_name }}::lift({{ type_name }} val) { | ||
{{ type_name }} {{ ffi_converter_name }}::lift({{ type_name }} val) { | ||
return val; | ||
} | ||
|
||
{{ type_name }} {{ namespace }}::uniffi::{{ ffi_converter_name }}::lower({{ type_name }} val) { | ||
{{ type_name }} {{ ffi_converter_name }}::lower({{ type_name }} val) { | ||
return val; | ||
} | ||
|
||
{{ type_name }} {{ namespace }}::uniffi::{{ ffi_converter_name }}::read({{ namespace }}::uniffi::RustStream &stream) { | ||
{{ type_name }} {{ ffi_converter_name }}::read(RustStream &stream) { | ||
{{ type_name }} ret; | ||
|
||
stream >> ret; | ||
|
||
return ret; | ||
} | ||
|
||
void {{ namespace }}::uniffi::{{ ffi_converter_name }}::write({{ namespace }}::uniffi::RustStream &stream, {{ type_name }} val) { | ||
void {{ ffi_converter_name }}::write(RustStream &stream, {{ type_name }} val) { | ||
stream << val; | ||
} | ||
|
||
int32_t {{ namespace }}::uniffi::{{ ffi_converter_name }}::allocation_size({{ type_name }}) { | ||
int32_t {{ ffi_converter_name }}::allocation_size({{ type_name }}) { | ||
return sizeof({{ type_name }}); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
{% let type_name = typ|type_name %} | ||
|
||
{%- let type_name = typ|type_name %} | ||
struct {{ typ|ffi_converter_name }} { | ||
static {{ type_name }} lift({{ type_name }}); | ||
static {{ type_name }} lower({{ type_name }}); | ||
static {{ type_name }} read(RustStream &); | ||
static void write(RustStream &, {{ type_name }}); | ||
static int32_t allocation_size({{ type_name }}); | ||
}; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
{%- let class_name = ffi_converter_name|class_name %} | ||
bool {{ class_name }}::lift(uint8_t val) { | ||
return !!val; | ||
} | ||
|
||
namespace {{ namespace }} { | ||
bool uniffi::{{ class_name }}::lift(uint8_t val) { | ||
return !!val; | ||
} | ||
|
||
uint8_t uniffi::{{ class_name }}::lower(bool val) { | ||
return val; | ||
} | ||
|
||
{{ type_name }} uniffi::{{ class_name }}::read(uniffi::RustStream &stream) { | ||
uint8_t val; | ||
|
||
stream.get(val); | ||
uint8_t {{ class_name }}::lower(bool val) { | ||
return val; | ||
} | ||
|
||
return val; | ||
} | ||
{{ type_name }} {{ class_name }}::read(RustStream &stream) { | ||
uint8_t val; | ||
stream >> val; | ||
|
||
void uniffi::{{ class_name }}::write(uniffi::RustStream &stream, bool val) { | ||
stream.put(static_cast<uint8_t>(val)); | ||
} | ||
return val; | ||
} | ||
|
||
int32_t uniffi::{{ class_name }}::allocation_size(bool) { | ||
return 1; | ||
} | ||
void {{ class_name }}::write(RustStream &stream, bool val) { | ||
stream << val; | ||
} | ||
|
||
int32_t {{ class_name }}::allocation_size(bool) { | ||
return 1; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
{%- let type_name = typ|type_name %} | ||
|
||
struct {{ typ|ffi_converter_name }} { | ||
static {{ type_name }} lift(uint8_t); | ||
static uint8_t lower({{ type_name }}); | ||
static {{ type_name }} read(::{{ namespace }}::uniffi::RustStream &); | ||
static void write(::{{ namespace }}::uniffi::RustStream &, {{ type_name }}); | ||
static {{ type_name }} read(RustStream &); | ||
static void write(RustStream &, {{ type_name }}); | ||
static int32_t allocation_size({{ type_name }}); | ||
}; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,46 @@ | ||
{%- let ffi_converter_name = typ|ffi_converter_name %} | ||
{%- let class_name = ffi_converter_name|class_name %} | ||
{%- let type_name = typ|type_name %} | ||
{{ type_name }} {{ ffi_converter_name }}::lift(RustBuffer buf) { | ||
auto stream = RustStream(&buf); | ||
auto ret = read(stream); | ||
|
||
namespace {{ namespace }} { | ||
{{ type_name }} uniffi::{{ class_name }}::lift(RustBuffer buf) { | ||
auto stream = RustStream(&buf); | ||
auto ret = read(stream); | ||
rustbuffer_free(buf); | ||
|
||
rustbuffer_free(buf); | ||
|
||
return ret; | ||
} | ||
|
||
RustBuffer uniffi::{{ class_name }}::lower(const {{ type_name }} &val) { | ||
auto buf = uniffi::rustbuffer_alloc(allocation_size(val)); | ||
auto stream = RustStream(&buf); | ||
|
||
write(stream, val); | ||
return ret; | ||
} | ||
|
||
return buf; | ||
} | ||
RustBuffer {{ ffi_converter_name }}::lower(const {{ type_name }} &val) { | ||
auto buf = uniffi::rustbuffer_alloc(allocation_size(val)); | ||
auto stream = RustStream(&buf); | ||
|
||
{{ type_name }} uniffi::{{ class_name }}::read(uniffi::RustStream &stream) { | ||
{{ type_name }} ret; | ||
int32_t count; | ||
write(stream, val); | ||
|
||
stream >> count; | ||
return buf; | ||
} | ||
|
||
ret.reserve(count); | ||
{{ type_name }} {{ ffi_converter_name }}::read(RustStream &stream) { | ||
{{ type_name }} ret; | ||
int32_t count; | ||
stream >> count; | ||
|
||
for (decltype(count) i = 0; i < count; i++) { | ||
uint8_t elem; | ||
stream >> elem; | ||
ret.push_back(elem); | ||
} | ||
ret.reserve(count); | ||
|
||
return ret; | ||
for (decltype(count) i = 0; i < count; i++) { | ||
uint8_t elem; | ||
stream >> elem; | ||
ret.push_back(elem); | ||
} | ||
|
||
void uniffi::{{ class_name }}::write(uniffi::RustStream &stream, const {{ type_name }} &val) { | ||
stream << static_cast<int32_t>(val.size()); | ||
return ret; | ||
} | ||
|
||
for (auto &elem : val) { | ||
stream << elem; | ||
} | ||
} | ||
void {{ ffi_converter_name }}::write(RustStream &stream, const {{ type_name }} &val) { | ||
stream << static_cast<int32_t>(val.size()); | ||
|
||
int32_t uniffi::{{ class_name }}::allocation_size(const {{ type_name }} &val) { | ||
return sizeof(int32_t) + sizeof(uint8_t) * val.size(); | ||
for (auto &elem : val) { | ||
stream << elem; | ||
} | ||
} | ||
|
||
int32_t {{ ffi_converter_name }}::allocation_size(const {{ type_name }} &val) { | ||
return sizeof(int32_t) + sizeof(uint8_t) * val.size(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
{%- let ffi_converter_name = typ|ffi_converter_name %} | ||
{%- let type_name = typ|type_name %} | ||
|
||
struct {{ ffi_converter_name|class_name }} { | ||
static {{ type_name }} lift(RustBuffer); | ||
static RustBuffer lower(const {{ type_name }} &); | ||
static {{ type_name }} read({{ namespace }}::uniffi::RustStream &); | ||
static void write({{ namespace }}::uniffi::RustStream &, const {{ type_name }} &); | ||
|
||
static {{ type_name }} read(RustStream &); | ||
static void write(RustStream &, const {{ type_name }} &); | ||
static int32_t allocation_size(const {{ type_name }} &); | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
{%- let ffi_converter_name = typ|ffi_converter_name %} | ||
{%- let type_name = typ|type_name %} | ||
{%- let class_name = type_name|class_name %} | ||
|
||
struct {{ ffi_converter_name|class_name }} { | ||
static std::shared_ptr<{{ class_name }}> lift(uint64_t); | ||
static uint64_t lower(std::shared_ptr<{{ class_name }}>); | ||
static std::shared_ptr<{{ class_name }}> read(uniffi::RustStream &); | ||
static std::shared_ptr<{{ class_name }}> read(RustStream &); | ||
static void write(RustStream &, uint64_t); | ||
|
||
static int32_t allocation_size(const {{ class_name }} &); | ||
|
||
private: | ||
static int callback_stub(uint64_t, uint32_t, uint8_t *, int32_t, RustBuffer *); | ||
|
||
static std::once_flag once; | ||
static HandleMap<{{ class_name }}> callbacks; | ||
}; | ||
}; |
This file contains 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
Oops, something went wrong.