Morse
Morse is an encoding method that converts text to sequences of dots and dashes, following the International Morse Code standard (ITU-R M.1677-1). dongle
supports standard Morse
encoding, converting letters, numbers, and punctuation marks to standardized sequences of dots and dashes.
The default separator is
space
, You can customize the separator by settingmorse.StdSeparator
Encoding Data
Input Data (cannot contain spaces)
go
// Input string
encoder := dongle.Encode.FromString("hello").ByMorse()
// Input byte slice
encoder := dongle.Encode.FromBytes([]byte("hello")).ByMorse()
// Input file stream
file, _ := os.Open("test.txt")
encoder := dongle.Encode.FromFile(file).ByMorse()
// Check encoding error
if encoder.Error != nil {
fmt.Printf("Encoding error: %v\n", encoder.Error)
return
}
Output Data
go
// Output string
encoder.ToString() // .... . .-.. .-.. ---
// Output byte slice
encoder.ToBytes() // []byte(".... . .-.. .-.. ---")
Decoding Data
Input Data
go
// Input string
decoder := dongle.Decode.FromString(".... . .-.. .-.. ---").ByMorse()
// Input byte slice
decoder := dongle.Decode.FromBytes([]byte(".... . .-.. .-.. ---")).ByMorse()
// Input file stream
file, _ := os.Open("test.txt")
decoder := dongle.Decode.FromFile(file).ByMorse()
// Check decoding error
if decoder.Error != nil {
fmt.Printf("Decoding error: %v\n", decoder.Error)
return
}
Output Data
go
// Output string
decoder.ToString() // hello
// Output byte slice
decoder.ToBytes() // []byte("hello")