mirror of
https://github.com/pikami/cosmium.git
synced 2026-06-11 23:07:11 +01:00
Initial RNTBD server implementation
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/pikami/cosmium/internal/rntbd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
input := flag.String("input", "", "Input hex string")
|
||||
isResponse := flag.Bool("response", false, "Is response")
|
||||
flag.Parse()
|
||||
|
||||
data, err := hex.DecodeString(*input)
|
||||
if err != nil {
|
||||
fmt.Printf("Error decoding hex string: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
frame, err := rntbd.ParseFrame(data, *isResponse)
|
||||
if err != nil {
|
||||
fmt.Printf("Error parsing frame: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Activity ID: %s\n", hex.EncodeToString(frame.ActivityId))
|
||||
fmt.Printf("Resource Type: %s\n", frame.ResourceType.String())
|
||||
fmt.Printf("Operation Type: %s\n", frame.OperationType.String())
|
||||
|
||||
if len(frame.RequestHeaders) > 0 {
|
||||
fmt.Printf("=== Request Headers ===\n")
|
||||
for header, value := range frame.RequestHeaders {
|
||||
fmt.Printf("%s: %v\n", header.String(), value)
|
||||
}
|
||||
}
|
||||
|
||||
if len(frame.ResponseHeaders) > 0 {
|
||||
fmt.Printf("=== Response Headers ===\n")
|
||||
for header, value := range frame.ResponseHeaders {
|
||||
fmt.Printf("%s: %v\n", header.String(), value)
|
||||
}
|
||||
}
|
||||
|
||||
if len(frame.ContextHeaders) > 0 {
|
||||
fmt.Printf("=== Context Headers ===\n")
|
||||
for header, value := range frame.ContextHeaders {
|
||||
fmt.Printf("%s: %v\n", header.String(), value)
|
||||
}
|
||||
}
|
||||
|
||||
if len(frame.Payload) > 0 {
|
||||
var jsonObj any
|
||||
err := json.Unmarshal(frame.Payload, &jsonObj)
|
||||
if err != nil {
|
||||
fmt.Printf("Payload: %s\n", hex.EncodeToString(frame.Payload))
|
||||
} else {
|
||||
fmt.Printf("Payload: %+v\n", jsonObj)
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -11,6 +11,7 @@ import (
|
||||
badgerdatastore "github.com/pikami/cosmium/internal/datastore/badger_datastore"
|
||||
jsondatastore "github.com/pikami/cosmium/internal/datastore/json_datastore"
|
||||
"github.com/pikami/cosmium/internal/logger"
|
||||
"github.com/pikami/cosmium/internal/rntbd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -38,6 +39,15 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if configuration.EnableRntbd {
|
||||
rntbdServer := rntbd.NewRntbdServer(configuration.RntbdPort, server)
|
||||
err = rntbdServer.Start()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer rntbdServer.Stop()
|
||||
}
|
||||
|
||||
waitForExit(server, dataStore)
|
||||
}
|
||||
|
||||
@@ -50,6 +60,5 @@ func waitForExit(server *api.ApiServer, dataStore datastore.DataStore) {
|
||||
|
||||
// Stop the server
|
||||
server.Stop()
|
||||
|
||||
dataStore.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user