diff options
author | insomniac <insomniacslk@users.noreply.github.com> | 2018-08-19 19:58:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-19 19:58:01 +0100 |
commit | c0dc38b656ec84a401a99f2f97f6af79c4e66398 (patch) | |
tree | 11892b32733d2cee916f8236c5afe10f40bcbab2 /dhcpv4/bsdp | |
parent | ececa3f5129cbc0bca341ea87a14bfaa8576156d (diff) |
Added String methods for types (#140)
* Added String methods for types
* Reverted change on bsdp.OptionCode
Diffstat (limited to 'dhcpv4/bsdp')
-rw-r--r-- | dhcpv4/bsdp/bsdp_option_message_type.go | 13 | ||||
-rw-r--r-- | dhcpv4/bsdp/bsdp_option_message_type_test.go | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/dhcpv4/bsdp/bsdp_option_message_type.go b/dhcpv4/bsdp/bsdp_option_message_type.go index d73eff5..c11b56b 100644 --- a/dhcpv4/bsdp/bsdp_option_message_type.go +++ b/dhcpv4/bsdp/bsdp_option_message_type.go @@ -19,6 +19,13 @@ const ( MessageTypeFailed MessageType = 3 ) +func (m MessageType) String() string { + if s, ok := MessageTypeToString[m]; ok { + return s + } + return "Unknown" +} + // MessageTypeToString maps each BSDP message type to a human-readable string. var MessageTypeToString = map[MessageType]string{ MessageTypeList: "LIST", @@ -60,11 +67,7 @@ func (o *OptMessageType) ToBytes() []byte { // String returns a human-readable string for this option. func (o *OptMessageType) String() string { - s, ok := MessageTypeToString[o.Type] - if !ok { - s = "UNKNOWN" - } - return fmt.Sprintf("BSDP Message Type -> %s", s) + return fmt.Sprintf("BSDP Message Type -> %s", o.Type.String()) } // Length returns the length of the data portion of this option. diff --git a/dhcpv4/bsdp/bsdp_option_message_type_test.go b/dhcpv4/bsdp/bsdp_option_message_type_test.go index b853dc9..9b7564f 100644 --- a/dhcpv4/bsdp/bsdp_option_message_type_test.go +++ b/dhcpv4/bsdp/bsdp_option_message_type_test.go @@ -42,5 +42,5 @@ func TestOptMessageTypeString(t *testing.T) { // unknown o = OptMessageType{99} - require.Equal(t, "BSDP Message Type -> UNKNOWN", o.String()) + require.Equal(t, "BSDP Message Type -> Unknown", o.String()) } |