Skip to content

Instantly share code, notes, and snippets.

@spytheman
Created August 1, 2020 10:28
Show Gist options
  • Select an option

  • Save spytheman/ab7a7c7eef78080a8006b7db8a28f7ed to your computer and use it in GitHub Desktop.

Select an option

Save spytheman/ab7a7c7eef78080a8006b7db8a28f7ed to your computer and use it in GitHub Desktop.
import json
struct User { name string age int }
fn main(){
mut len := 0
C.read(0, &len, 4)
if len > 1024 { panic('input too large') }
mut buf := malloc(len)
C.read(0, buf, len)
s := string(buf, len)
println('received s: $s')
u := json.decode(User, s)?
println('received user: $u')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment