mirror of
https://github.com/garraflavatra/go-fmp.git
synced 2025-06-28 04:25:11 +00:00
Add debug utils
This commit is contained in:
@ -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
26
fmp/fmp_debug.go
Normal 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)
|
||||||
|
}
|
@ -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")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user