summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorbt <bt@rctt.net>2026-03-07 20:42:54 +0100
committerbt <bt@rctt.net>2026-03-07 20:42:54 +0100
commit3830a8ad69fd861558f4d8ee7ee67b05c244eb47 (patch)
treecd1f73674ba45744bed250fdd557a6247737eb27 /core
parent236457dfda1e8e79daf86e0d6512f3d186373a65 (diff)
downloadsolec-3830a8ad69fd861558f4d8ee7ee67b05c244eb47.tar.gz
solec-3830a8ad69fd861558f4d8ee7ee67b05c244eb47.zip
Create core package
Diffstat (limited to 'core')
-rw-r--r--core/data.go30
-rw-r--r--core/network.go23
2 files changed, 53 insertions, 0 deletions
diff --git a/core/data.go b/core/data.go
new file mode 100644
index 0000000..a617f17
--- /dev/null
+++ b/core/data.go
@@ -0,0 +1,30 @@
+package core
+
+type Marshaler interface {
+ Marshal() []any
+}
+
+type DataType uint8
+
+const (
+ TypeHandshake DataType = 0x01
+ TypePing = 0x02
+ TypePong = 0x03
+ TypeTest = 0xFF
+)
+
+type Handshake struct {
+ Version uint8
+}
+
+func (h Handshake) Marshal() []any {
+ return []any{h.Version}
+}
+
+type Test struct {
+ Message string
+}
+
+func (h Test) Marshal() []any {
+ return []any{[]byte(h.Message)}
+}
diff --git a/core/network.go b/core/network.go
new file mode 100644
index 0000000..3065f19
--- /dev/null
+++ b/core/network.go
@@ -0,0 +1,23 @@
+package core
+
+import (
+ "encoding/binary"
+ "fmt"
+ "net"
+)
+
+func Send(conn net.Conn, dataType DataType, data Marshaler) error {
+ packet := []any{uint8(dataType)}
+ packet = append(packet, data.Marshal()...)
+
+ fmt.Println(packet)
+
+ for _, v := range packet {
+ err := binary.Write(conn, binary.BigEndian, v)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}