From 47eeaa4255cc977a51abfdaaf3d9bb1b8e8e701c Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Thu, 12 Jun 2025 09:41:46 +0200 Subject: [PATCH] Add debug utils --- fmp/fmp_chunk.go | 5 ----- fmp/fmp_debug.go | 26 ++++++++++++++++++++++++++ fmp/fmp_test.go | 2 ++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 fmp/fmp_debug.go diff --git a/fmp/fmp_chunk.go b/fmp/fmp_chunk.go index 3d53956..fb13298 100644 --- a/fmp/fmp_chunk.go +++ b/fmp/fmp_chunk.go @@ -2,7 +2,6 @@ package fmp import ( "encoding/binary" - "fmt" ) type FmpChunk struct { @@ -13,10 +12,6 @@ type FmpChunk struct { Value []byte } -func (c *FmpChunk) String() string { - return fmt.Sprintf("<%v(%v)>", c.Type, c.Length) -} - func (ctx *FmpFile) readChunk(payload []byte) (*FmpChunk, error) { // Simple data diff --git a/fmp/fmp_debug.go b/fmp/fmp_debug.go new file mode 100644 index 0000000..ed4f3cd --- /dev/null +++ b/fmp/fmp_debug.go @@ -0,0 +1,26 @@ +package fmp + +import ( + "fmt" + "os" +) + +func (f *FmpFile) ToDebugFile(fname string) { + fo, err := os.Create(fname) + if err != nil { + panic(err) + } + defer func() { + if err := fo.Close(); err != nil { + panic(err) + } + }() + + for _, chunk := range f.Chunks { + fmt.Fprintf(fo, "%s, %s\n", chunk.String(), string(chunk.Value)) + } +} + +func (c *FmpChunk) String() string { + return fmt.Sprintf("<%v(%v)>", c.Type, c.Length) +} diff --git a/fmp/fmp_test.go b/fmp/fmp_test.go index b48b73f..191457a 100644 --- a/fmp/fmp_test.go +++ b/fmp/fmp_test.go @@ -19,4 +19,6 @@ func TestOpenFile(t *testing.T) { if f.VersionDate.Format("2006-01-02") != "2025-01-11" { t.Errorf("expected version date to be '2025-01-11', got '%s'", f.VersionDate.Format("2006-01-02")) } + + f.ToDebugFile("../private/output.txt") }