-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add serialization and deserialization for impors, interfaces, modules
- Loading branch information
Showing
30 changed files
with
1,060 additions
and
175 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions
39
...hema/bind/src/bindings/golang/wasm-go/templates/imported/enum-type/Enum%type%-go.mustache
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} | ||
|
||
type {{#toUpper}}{{type}}{{/toUpper}} int32 | ||
|
||
const ( | ||
{{#constants}} | ||
{{#toUpper}}{{type}}{{/toUpper}}{{.}} = iota | ||
{{/constants}} | ||
{{#toFirstLower}}{{type}}{{/toFirstLower}}Max = iota | ||
) | ||
|
||
func Sanitize{{#toUpper}}{{type}}{{/toUpper}}Value(value int32) { | ||
if !(value >= 0 && value < int32({{#toFirstLower}}{{type}}{{/toFirstLower}}Max)) { | ||
panic("Invalid value for enum '{{#toUpper}}{{type}}{{/toUpper}}'") | ||
} | ||
} | ||
|
||
func Get{{#toUpper}}{{type}}{{/toUpper}}Value(key string) {{#toUpper}}{{type}}{{/toUpper}} { | ||
switch key { | ||
{{#constants}} | ||
case "{{.}}": | ||
return {{#toUpper}}{{type}}{{/toUpper}}{{.}} | ||
{{/constants}} | ||
default: | ||
panic("Invalid key for enum '{{#toUpper}}{{type}}{{/toUpper}}'") | ||
} | ||
} | ||
|
||
func Get{{#toUpper}}{{type}}{{/toUpper}}Key(value {{#toUpper}}{{type}}{{/toUpper}}) string { | ||
Sanitize{{#toUpper}}{{type}}{{/toUpper}}Value(int32(value)) | ||
switch value { | ||
{{#constants}} | ||
case {{#toUpper}}{{type}}{{/toUpper}}{{.}}: | ||
return "{{.}}" | ||
{{/constants}} | ||
default: | ||
panic("Invalid value for enum '{{#toUpper}}{{type}}{{/toUpper}}'") | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...schema/bind/src/bindings/golang/wasm-go/templates/imported/env-type/Env%type%-go.mustache
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} | ||
|
||
import ( | ||
"github.com/consideritdone/polywrap-go/polywrap/msgpack" | ||
"github.com/consideritdone/polywrap-go/polywrap/msgpack/big" | ||
"github.com/consideritdone/polywrap-go/polywrap/msgpack/container" | ||
"github.com/valyala/fastjson" | ||
) | ||
|
||
type {{#toUpper}}{{type}}{{/toUpper}} struct { | ||
{{#properties}} | ||
{{#toUpper}}{{#handleKeywords}}{{name}}{{/handleKeywords}}{{/toUpper}} {{#toWasm}}{{toGraphQLType}}{{/toWasm}} | ||
{{/properties}} | ||
} | ||
|
||
func {{#toUpper}}{{type}}{{/toUpper}}ToBuffer(value *{{#toUpper}}{{type}}{{/toUpper}}) []byte { | ||
return serialize{{#toUpper}}{{type}}{{/toUpper}}(value) | ||
} | ||
|
||
func {{#toUpper}}{{type}}{{/toUpper}}FromBuffer(data []byte) *{{#toUpper}}{{type}}{{/toUpper}} { | ||
return deserialize{{#toUpper}}{{type}}{{/toUpper}}(data) | ||
} | ||
|
||
func {{#toUpper}}{{type}}{{/toUpper}}Write(writer msgpack.Write, value *{{#toUpper}}{{type}}{{/toUpper}}) { | ||
write{{#toUpper}}{{type}}{{/toUpper}}(writer, value) | ||
} | ||
|
||
func {{#toUpper}}{{type}}{{/toUpper}}Read(reader msgpack.Read) *{{#toUpper}}{{type}}{{/toUpper}} { | ||
return read{{#toUpper}}{{type}}{{/toUpper}}(reader) | ||
} | ||
|
Oops, something went wrong.