1
0
mirror of https://github.com/garraflavatra/go-fmp.git synced 2025-06-28 12:35:12 +00:00

Add debug utils

This commit is contained in:
2025-06-12 09:41:46 +02:00
parent 564e1c4ce6
commit 47eeaa4255
3 changed files with 28 additions and 5 deletions

View File

@ -2,7 +2,6 @@ package fmp
import ( import (
"encoding/binary" "encoding/binary"
"fmt"
) )
type FmpChunk struct { type FmpChunk struct {
@ -13,10 +12,6 @@ type FmpChunk struct {
Value []byte Value []byte
} }
func (c *FmpChunk) String() string {
return fmt.Sprintf("<%v(%v)>", c.Type, c.Length)
}
func (ctx *FmpFile) readChunk(payload []byte) (*FmpChunk, error) { func (ctx *FmpFile) readChunk(payload []byte) (*FmpChunk, error) {
// Simple data // Simple data

26
fmp/fmp_debug.go Normal file
View File

@ -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)
}

View File

@ -19,4 +19,6 @@ func TestOpenFile(t *testing.T) {
if f.VersionDate.Format("2006-01-02") != "2025-01-11" { 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")) t.Errorf("expected version date to be '2025-01-11', got '%s'", f.VersionDate.Format("2006-01-02"))
} }
f.ToDebugFile("../private/output.txt")
} }