Initial Dever 0.0.1

This commit is contained in:
Codex committed 2026-11-03 03:32:07 +00:00
commit 81233d098c
1479 files changed
+163782

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
"time"
)
type input struct {
Source json.RawMessage `json:"source"`
Update bool `json:"update"`
Ticks string `json:"ticks"`
}
type sample struct {
Elapsed int64 `json:"elapsed_ns"`
Checksum int `json:"checksum"`
Output string `json:"output"`
}
func transform(source []byte, update bool) []byte {
decoder := json.NewDecoder(bytes.NewReader(source))
decoder.UseNumber()
var object map[string]any
if err := decoder.Decode(&object); err != nil {
panic(err)
}
var selected any = object["data"]
if update {
object["active"] = true
selected = object
}
output, err := json.Marshal(selected)
if err != nil {
panic(err)
}
return output
}
func main() {
var arguments input
if len(os.Args) != 2 {
panic("expected one JSON input")
}
if err := json.Unmarshal([]byte(os.Args[1]), &arguments); err != nil {
panic(err)
}
if !json.Valid(arguments.Source) {
panic("invalid source")
}
output := transform(arguments.Source, arguments.Update)
checksum := 0
begin := time.Now()
for range []byte(arguments.Ticks) {
checksum += len(transform(arguments.Source, arguments.Update))
}
result := sample{time.Since(begin).Nanoseconds(), checksum, string(output)}
encoded, err := json.Marshal(result)
if err != nil {
panic(err)
}
fmt.Println(string(encoded))
}