Skip to content

Commit

Permalink
Add GOBE_CUSTOM_TYPE Example
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon-mint committed Jan 22, 2023
1 parent 07f4823 commit 0784be4
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 120 deletions.
25 changes: 25 additions & 0 deletions example/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

type GOBE_CUSTOM_TYPE interface {
ZZMarshalGOBE(dst []byte) uint64
ZZUnmarshalGOBE(src []byte) (offset uint64, ok bool)
ZZSizeGOBE() uint64
}

type CustomUint8 uint8

var _ GOBE_CUSTOM_TYPE = (*CustomUint8)(nil)

func (c *CustomUint8) ZZMarshalGOBE(dst []byte) uint64 {
dst[0] = byte(*c)
return 1
}

func (c *CustomUint8) ZZUnmarshalGOBE(src []byte) (offset uint64, ok bool) {
*c = CustomUint8(src[0])
return 1, true
}

func (c *CustomUint8) ZZSizeGOBE() uint64 {
return 1
}
2 changes: 1 addition & 1 deletion example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Weapon struct {

type Player struct {
Name string
Health uint16
Health CustomUint8
Weapons []Weapon

Position
Expand Down
Loading

0 comments on commit 0784be4

Please sign in to comment.