Skip to content

Commit f63398e

Browse files
committed
minor update
1 parent 06c7232 commit f63398e

24 files changed

Lines changed: 721 additions & 49 deletions

cppcon2025/cppcon_2025_slides.md

Lines changed: 266 additions & 49 deletions
Large diffs are not rendered by default.

cppcon2025/cppcon_2025_slides.pdf

561 KB
Binary file not shown.

cppcon2025/go/json.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"log"
7+
)
8+
9+
// Player represents a player with their attributes
10+
type Player struct {
11+
Username string `json:"username"` // Player's username
12+
Level int `json:"level"` // Player's level
13+
Health float64 `json:"health"` // Player's health points
14+
Inventory []string `json:"inventory"` // Player's inventory
15+
}
16+
17+
func main() {
18+
// Example of serialization (struct to JSON)
19+
player := Player{
20+
Username: "hero123",
21+
Level: 42,
22+
Health: 95.5,
23+
Inventory: []string{"sword", "shield", "potion"},
24+
}
25+
26+
// Serialize to JSON
27+
jsonData, err := json.MarshalIndent(player, "", " ")
28+
if err != nil {
29+
log.Fatalf("Error during serialization: %v", err)
30+
}
31+
fmt.Println("Serialized JSON:")
32+
fmt.Println(string(jsonData))
33+
34+
// Example of deserialization (JSON to struct)
35+
jsonStr := `{
36+
"username": "hero123",
37+
"level": 42,
38+
"health": 95.5,
39+
"inventory": ["sword", "shield", "potion"]
40+
}`
41+
42+
var deserializedPlayer Player
43+
err = json.Unmarshal([]byte(jsonStr), &deserializedPlayer)
44+
if err != nil {
45+
log.Fatalf("Error during deserialization: %v", err)
46+
}
47+
48+
fmt.Println("\nDeserialized Player:")
49+
fmt.Printf("Username: %s\n", deserializedPlayer.Username)
50+
fmt.Printf("Level: %d\n", deserializedPlayer.Level)
51+
fmt.Printf("Health: %.1f\n", deserializedPlayer.Health)
52+
fmt.Printf("Inventory: %v\n", deserializedPlayer.Inventory)
53+
}

cppcon2025/go/reflect.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"reflect"
6+
)
7+
8+
// Player struct, equivalent to the C++ struct
9+
type Player struct {
10+
Username string
11+
Level int
12+
Health float64
13+
Inventory []string
14+
}
15+
16+
// Function to enumerate fields of a struct using reflection
17+
func enumerateFields(obj interface{}) {
18+
// Get the value and type of the object
19+
val := reflect.ValueOf(obj)
20+
typ := reflect.TypeOf(obj)
21+
22+
// Check if the object is a struct
23+
if val.Kind() == reflect.Struct {
24+
fmt.Println("Fields of the struct:")
25+
for i := 0; i < typ.NumField(); i++ {
26+
field := typ.Field(i)
27+
value := val.Field(i)
28+
fmt.Printf(" Name: %s, Type: %s, Value: %v\n", field.Name, field.Type, value)
29+
}
30+
} else {
31+
fmt.Println("The object is not a struct")
32+
}
33+
}
34+
35+
func main() {
36+
// Create an instance of Player
37+
player := Player{
38+
Username: "Hero123",
39+
Level: 10,
40+
Health: 85.5,
41+
Inventory: []string{"Sword", "Shield", "Potion"},
42+
}
43+
44+
// Enumerate the fields using reflection
45+
enumerateFields(player)
46+
}

cppcon2025/images/csharp.png

15.8 KB
Loading

cppcon2025/images/csharp.svg

Lines changed: 8 additions & 0 deletions
Loading

cppcon2025/images/fastdisk.png

91.8 KB
Loading

cppcon2025/images/go.svg

Lines changed: 6 additions & 0 deletions
Loading

cppcon2025/images/java.png

57.8 KB
Loading

cppcon2025/images/java.svg

Lines changed: 18 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)