diff --git a/cop/collection.go b/cop/collection.go index 861772a..29becee 100644 --- a/cop/collection.go +++ b/cop/collection.go @@ -71,9 +71,10 @@ func GetCOP() *ProtocolCollectionList { return GlobalCOP } +// Read/WriteCache functions to fullfill [impl->dsn~protocol-collection-cache~0>>utest] + // WriteCache updates the cache file of the available protocols func (pcl *ProtocolCollectionList) WriteCache() error { - // [impl->dsn~protocol-collection-cache~0>>utest] cops := []string{} for _, pc := range pcl.PCs { str, err := pc.ToJSON() @@ -89,7 +90,6 @@ func (pcl *ProtocolCollectionList) WriteCache() error { // ReadCache reads the cache for display func (pcl *ProtocolCollectionList) ReadCache() error { - // [impl->dsn~protocol-collection-cache~0>>utest] // TODO: Think about if it makes sense to have this function as a member of PCL, // or if it makes more sense to make this function standalone and return a new PCL? data, err := os.ReadFile(path.Join(globals.CollectionOfProtocolsDir, globals.COPCacheFileName)) diff --git a/cop/collection_test.go b/cop/collection_test.go index 4c615cf..1f7055e 100644 --- a/cop/collection_test.go +++ b/cop/collection_test.go @@ -113,6 +113,7 @@ func TestGlobalCOP(t *testing.T) { } func TestCOPCache(t *testing.T) { + // [utest->impl~protocol-collection-cache~0] td := setupSuite(t) defer td(t) gcop := cop.GlobalCOP diff --git a/cop/cop.go b/cop/cop.go index 40b02a6..a5b793e 100644 --- a/cop/cop.go +++ b/cop/cop.go @@ -16,7 +16,7 @@ type COP struct { // ProtocolCollectionEntry is a single entry in the file database, additionally to the meta data the path is required type ProtocolCollectionEntry struct { Path string - Protocol protocol.ProtocolMeta + Protocol protocol.Meta } // A collection entry has a path, which is meant to be a filesystem path, but doesn't necessarily have to be. diff --git a/globals/globals.go b/globals/globals.go index 4d8d008..a7f9ff9 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -27,8 +27,9 @@ var CollectionOfProtocolsDir string // COPCacheFileName is the filename for the cache var COPCacheFileName string = "cop-cache.json" -// Global Mockings +////////////// Global Mockings +// MockUserCurrent is a variable to be able to mock the function call to `user.Current` var MockUserCurrent = user.Current // Marshaler interface to enrich structs which can be exported/imported even with private fields diff --git a/packet/packet.go b/packet/packet.go index 4a1c6bc..8b285f3 100644 --- a/packet/packet.go +++ b/packet/packet.go @@ -42,7 +42,7 @@ type Layer struct { // Packet contains all layers of a packet and the data in different formats type Packet struct { - MetaData Metadata + MetaData Meta data []byte Hex string B64 string diff --git a/packet/packetmetadata.go b/packet/packetmetadata.go index 576deef..7779839 100644 --- a/packet/packetmetadata.go +++ b/packet/packetmetadata.go @@ -1,7 +1,7 @@ package packet -// Metadata struct is the absolute minimum of metadata -type Metadata struct { +// Meta struct is the absolute minimum of metadata +type Meta struct { Name string Revision int } diff --git a/protocol/defaultfieldvalue.go b/protocol/defaultfieldvalue.go index 2d655e6..bb365e1 100644 --- a/protocol/defaultfieldvalue.go +++ b/protocol/defaultfieldvalue.go @@ -1,5 +1,6 @@ package protocol +// DefaultFieldValue represents a default value for a field identified in a protocol by its name. type DefaultFieldValue struct { FieldRef string Value string diff --git a/protocol/defaultvalue.go b/protocol/defaultvalue.go index a278359..8d629c9 100644 --- a/protocol/defaultvalue.go +++ b/protocol/defaultvalue.go @@ -1,6 +1,7 @@ package protocol -type DefaultValue struct { +// DefaultValues for protocols +type DefaultValues struct { Desc string FieldValues []DefaultFieldValue } diff --git a/protocol/field.go b/protocol/field.go index a8deded..f2cafcd 100644 --- a/protocol/field.go +++ b/protocol/field.go @@ -2,6 +2,7 @@ package protocol import "encoding/json" +// Field holds all necessary data for a field in a protocol type Field struct { Name string // Name of the Field Desc string // Lengthy description @@ -13,12 +14,14 @@ type Field struct { JavaScript string } -type ProtocolFieldReferencer interface { +// FieldReferencer interface +type FieldReferencer interface { GetProtocolField() *Field SetProtocolField(f *Field) } -func (f *Field) ToJson() string { +// ToJSON converts a field to a JSON string +func (f *Field) ToJSON() string { b, err := json.Marshal(*f) if err != nil { return "" @@ -26,11 +29,13 @@ func (f *Field) ToJson() string { return string(b) } +// NewEmptyField just creates a new Field with no data func NewEmptyField() *Field { f := Field{} return &f } +// NewField creates a new Field with all data possible func NewField( name string, desc string, diff --git a/protocol/protocol.go b/protocol/protocol.go index 9fca27f..a446229 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -9,9 +9,9 @@ import ( // Protocol structure type Protocol struct { - Metadata ProtocolMeta + Metadata Meta Structure []*Field - DefaultValues []DefaultValue + DefaultValues []DefaultValues JavaScript string } @@ -95,7 +95,7 @@ func (prot *Protocol) RemoveFieldByElement(field int) { ret := make([]*Field, 0) for i, f := range prot.Structure { if i != field { - fmt.Printf("appending %d, %s\n", i, f.ToJson()) + fmt.Printf("appending %d, %s\n", i, f.ToJSON()) ret = append(ret, f) } } diff --git a/protocol/protocol_test.go b/protocol/protocol_test.go index e2b2e0b..f39c2d5 100644 --- a/protocol/protocol_test.go +++ b/protocol/protocol_test.go @@ -62,7 +62,7 @@ func GenerateStructure() *Protocol { slc := GenerateFields() p.AppendFields(slc...) for i, e := range p.Structure { - fmt.Printf("%d %s\n", i, e.ToJson()) + fmt.Printf("%d %s\n", i, e.ToJSON()) } fmt.Println("Generated Structure.") return p @@ -108,7 +108,7 @@ func TestUpdateFieldByName(t *testing.T) { ) p.UpdateFieldByName("testfield3", f) for i, e := range p.Structure { - fmt.Printf("%d %s\n", i, e.ToJson()) + fmt.Printf("%d %s\n", i, e.ToJSON()) } if p.Structure[3].Desc != "" || p.Structure[3].Size != 42 { t.Log("Update field by Ref failed!") @@ -122,7 +122,7 @@ func TestUpdateFieldByElement(t *testing.T) { ) p.UpdateFieldByElement(5, f) for i, e := range p.Structure { - fmt.Printf("%d %s\n", i, e.ToJson()) + fmt.Printf("%d %s\n", i, e.ToJSON()) } if p.Structure[5].Desc != "" || p.Structure[5].Size != 42 { t.Log("Update field by Ref failed!") @@ -134,7 +134,7 @@ func TestRemoveFieldByName(t *testing.T) { p := GenerateStructure() p.RemoveFieldByName("testfield3") for i, e := range p.Structure { - fmt.Printf("%d %s\n", i, e.ToJson()) + fmt.Printf("%d %s\n", i, e.ToJSON()) } if p.Structure[3].Name != "testfield4" { t.Log("Remove by name failed!") @@ -146,7 +146,7 @@ func TestRemoveFieldByElement(t *testing.T) { p := GenerateStructure() p.RemoveFieldByElement(3) for i, e := range p.Structure { - fmt.Printf("%d %s\n", i, e.ToJson()) + fmt.Printf("%d %s\n", i, e.ToJSON()) } if p.Structure[3].Name != "testfield4" { t.Log("Remove by element failed!") diff --git a/protocol/protocolmeta.go b/protocol/protocolmeta.go index df2a9ae..7b6baa1 100644 --- a/protocol/protocolmeta.go +++ b/protocol/protocolmeta.go @@ -1,6 +1,7 @@ package protocol -type ProtocolMeta struct { +// Meta holds the metadata of a protocol +type Meta struct { Name string Revision uint Version string @@ -11,6 +12,7 @@ type ProtocolMeta struct { LowerLayerIdentification map[string]string } +// UpdateMetaData updates the full metadata of a protocol func UpdateMetaData( prot *Protocol, name string,