Skip to content

Commit

Permalink
Replaced local 'dump' implementation with cleaned up 'core' implement…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
twystd committed Jun 24, 2024
1 parent 1023f79 commit 2c95fc2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
17 changes: 6 additions & 11 deletions commands/run.go
Original file line number Diff line number Diff line change
@@ -1,18 1,17 @@
package commands

import (
"encoding/hex"
"fmt"
"net"
"net/netip"
"os"
"os/signal"
"reflect"
"regexp"
"time"

codec "github.com/uhppoted/uhppote-core/encoding/UTO311-L0x"
"github.com/uhppoted/uhppote-core/messages"

"github.com/uhppoted/uhppote-simulator/log"
"github.com/uhppoted/uhppote-simulator/rest"
"github.com/uhppoted/uhppote-simulator/simulator"
Expand Down Expand Up @@ -141,7 140,7 @@ func udpListenAndServe(ctx *simulator.Context, udp *net.UDPConn) error {
} else {
infof("udp", "sent %v bytes to %v", N, addr)
if debug {
infof("udp", "packet\n%s", dump(msg[0:N], " ... "))
infof("udp", "packet\n%s", codec.Dump(msg[0:N], " ... "))
}
}
}
Expand All @@ -158,7 157,7 @@ func udpListenAndServe(ctx *simulator.Context, udp *net.UDPConn) error {
return err
} else {
if debug {
debugf("udp", "received %v bytes from %v\n%s", N, raddr, dump(request[0:N], " ... "))
debugf("udp", "received %v bytes from %v\n%s", N, raddr, codec.Dump(request[0:N], " ... "))
}

handle(raddr, request[:N])
Expand All @@ -178,7 177,7 @@ func tcpListenAndServe(ctx *simulator.Context, c *net.TCPListener) error {
errorf("tcp", "%v", err)
} else {
if debug {
debugf("tcp", "received %v bytes from %v\n%s", N, addr, dump(packet[0:N], " ... "))
debugf("tcp", "received %v bytes from %v\n%s", N, addr, codec.Dump(packet[0:N], " ... "))
}

if request, err := messages.UnmarshalRequest(packet[0:N]); err != nil {
Expand All @@ -195,7 194,7 @@ func tcpListenAndServe(ctx *simulator.Context, c *net.TCPListener) error {
} else {
infof("tcp", "sent %v bytes to %v", N, addr)
if debug {
infof("tcp", "packet\n%s", dump(msg[0:N], " ... "))
infof("tcp", "packet\n%s", codec.Dump(msg[0:N], " ... "))
}
}
}
Expand Down Expand Up @@ -251,7 250,7 @@ func sendto(bind *net.UDPAddr, dest *net.UDPAddr, message any) {
if err != nil {
errorf("udp", "failed to write to UDP socket [%v]", err)
} else if debug {
infof("udp", "sent %v bytes to %v\n%s", N, dest, dump(msg[0:N], " ... "))
infof("udp", "sent %v bytes to %v\n%s", N, dest, codec.Dump(msg[0:N], " ... "))
}
}
}
Expand Down Expand Up @@ -297,10 296,6 @@ func isNil(v any) bool {
return false
}

func dump(m []byte, prefix string) string {
return regexp.MustCompile("(?m)^(.*)").ReplaceAllString(hex.Dump(m), prefix "$1")
}

func tag(rq any) string {
switch rq.(type) {
case *messages.ActivateAccessKeypadsRequest:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,6 @@ module github.com/uhppoted/uhppote-simulator
go 1.22

require (
github.com/uhppoted/uhppote-core v0.8.9-0.20240621163845-0f2c4816e848
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240621164457-8103bdf55831
github.com/uhppoted/uhppote-core v0.8.9-0.20240624170631-6e4dc3a26486
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240624171129-71bfbf7969b5
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 76,8 @@ github.com/uhppoted/uhppote-core v0.8.9-0.20240619162030-61ff4822cff5 h1:pQjiZP/
github.com/uhppoted/uhppote-core v0.8.9-0.20240619162030-61ff4822cff5/go.mod h1:Q DHtT8s74efLs2b0eF20DRBUL9yBkySwaTQ 0lsEVM=
github.com/uhppoted/uhppote-core v0.8.9-0.20240621163845-0f2c4816e848 h1:BXgPJVSLFwlITSxz9s/4Vaqczo/t7ybt0KLBp/4T1Tg=
github.com/uhppoted/uhppote-core v0.8.9-0.20240621163845-0f2c4816e848/go.mod h1:Q DHtT8s74efLs2b0eF20DRBUL9yBkySwaTQ 0lsEVM=
github.com/uhppoted/uhppote-core v0.8.9-0.20240624170631-6e4dc3a26486 h1:mUSkpgClFvkWJ84L1S1066cjd2RRUjksmXO7HSHTZDY=
github.com/uhppoted/uhppote-core v0.8.9-0.20240624170631-6e4dc3a26486/go.mod h1:Q DHtT8s74efLs2b0eF20DRBUL9yBkySwaTQ 0lsEVM=
github.com/uhppoted/uhppoted-lib v0.8.5 h1:X5RarX5QMRGJvOwPk8ceowrH8k6Ow3t TraWmhYO950=
github.com/uhppoted/uhppoted-lib v0.8.5/go.mod h1:euK2cLO934w0GDgvvnWMjYNtZ29K1xSMrMse6THOzDQ=
github.com/uhppoted/uhppoted-lib v0.8.6-0.20230714155133-57e68f2d1360 h1:XaVqmMmjwskTrX6iCdUl2I4ezrvuoA/yhLzf/455E10=
Expand Down Expand Up @@ -154,3 156,5 @@ github.com/uhppoted/uhppoted-lib v0.8.9-0.20240620174921-fbe5bac73e5a h1:vJYI3Ym
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240620174921-fbe5bac73e5a/go.mod h1:924 CVltuckyTszvCqeuU/k8nBZ tlkTuyPOspuAiuU=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240621164457-8103bdf55831 h1:Y67K5dBdnnEC83p4Y2OJU58Iah5rNjAe6hIli2eg77g=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240621164457-8103bdf55831/go.mod h1:Pj 5dhzmwQiLJK9aMQBMoaLU00Loeyv/UdGspDozReQ=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240624171129-71bfbf7969b5 h1:Vo0V3T/VMFaZlqTDre3ht9DGxEceuUXmDlAZeKeEx g=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240624171129-71bfbf7969b5/go.mod h1:Rrms8n4z4xoLAcpmeMmXdXG9kakovAbw 7/zSmjzY2s=

0 comments on commit 2c95fc2

Please sign in to comment.