Documentation
¶
Overview ¶
Package morse implements morse encoding and decoding with streaming support. It provides morse encoding following the International Morse Code standard (ITU-R M.1677-1). Morse code represents text as standardized sequences of dots and dashes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var StdAlphabet = map[string]string{
"a": ".-", "b": "-...", "c": "-.-.", "d": "-..", "e": ".", "f": "..-.",
"g": "--.", "h": "....", "i": "..", "j": ".---", "k": "-.-", "l": ".-..",
"m": "--", "n": "-.", "o": "---", "p": ".--.", "q": "--.-", "r": ".-.",
"s": "...", "t": "-", "u": "..-", "v": "...-", "w": ".--", "x": "-..-",
"y": "-.--", "z": "--..", "0": "-----", "1": ".----", "2": "..---",
"3": "...--", "4": "....-", "5": ".....", "6": "-....", "7": "--...",
"8": "---..", "9": "----.", ".": ".-.-.-", ",": "--..--", "?": "..--..",
"!": "-.-.--", "=": "-...-", "+": ".-.-.", "-": "-....-", "/": "-..-.",
}
StdAlphabet is the standard morse code alphabet following international standards. It includes letters a-z, numbers 0-9, and common punctuation marks.
var StdSeparator = " "
Functions ¶
func NewStreamDecoder ¶
NewStreamDecoder creates a new streaming morse decoder that reads encoded data from the provided io.Reader. The decoder uses the standard morse alphabet.
func NewStreamEncoder ¶
func NewStreamEncoder(w io.Writer) io.WriteCloser
NewStreamEncoder creates a new streaming morse encoder that writes encoded data to the provided io.Writer. The encoder uses the standard morse alphabet.
Types ¶
type InvalidCharacterError ¶
type InvalidCharacterError struct {
Char string // The invalid morse character that was found
}
InvalidCharacterError represents an error when an invalid morse character is found during decoding. This error occurs when a morse code sequence is not recognized.
func (InvalidCharacterError) Error ¶
func (e InvalidCharacterError) Error() string
Error returns a formatted error message describing the invalid character.
type InvalidInputError ¶
type InvalidInputError struct {
}
InvalidInputError represents an error when the morse input is invalid. This error occurs when the input contains spaces or other invalid characters.
func (InvalidInputError) Error ¶
func (e InvalidInputError) Error() string
Error returns a formatted error message describing the invalid input.
type StdDecoder ¶
type StdDecoder struct {
Error error // Error field for storing decoding errors
// contains filtered or unexported fields
}
StdDecoder represents a morse decoder for standard decoding operations. It implements morse decoding following the International Morse Code standard.
func NewStdDecoder ¶
func NewStdDecoder() *StdDecoder
NewStdDecoder creates a new morse decoder using the standard alphabet.
func (*StdDecoder) Decode ¶
func (d *StdDecoder) Decode(src []byte) (dst []byte, err error)
Decode decodes the given morse-encoded byte slice back to text. Converts morse code (dots and dashes) back to readable text. Uses space as the default separator between morse characters.
type StdEncoder ¶
type StdEncoder struct {
Error error // Error field for storing encoding errors
// contains filtered or unexported fields
}
StdEncoder represents a morse encoder for standard encoding operations. It implements morse encoding following the International Morse Code standard.
func NewStdEncoder ¶
func NewStdEncoder() *StdEncoder
NewStdEncoder creates a new morse encoder using the standard alphabet.
func (*StdEncoder) Encode ¶
func (e *StdEncoder) Encode(src []byte) (dst []byte)
Encode encodes the given byte slice using morse encoding. Converts text to morse code using dots (.) and dashes (-) separated by the specified separator. Input text is converted to lowercase before encoding.
type StreamDecoder ¶
type StreamDecoder struct {
Error error // Error field for storing decoding errors
// contains filtered or unexported fields
}
StreamDecoder represents a streaming morse decoder that implements io.Reader. It provides efficient decoding for large data streams by processing data in chunks and maintaining an internal buffer for partial reads.
func (*StreamDecoder) Read ¶
func (d *StreamDecoder) Read(p []byte) (n int, err error)
Read implements the io.Reader interface for streaming morse decoding. Reads and decodes morse data from the underlying reader in chunks. Maintains an internal buffer to handle partial reads efficiently.
type StreamEncoder ¶
type StreamEncoder struct {
Error error // Error field for storing encoding errors
// contains filtered or unexported fields
}
StreamEncoder represents a streaming morse encoder that implements io.WriteCloser. It provides efficient encoding for large data streams by buffering data and encoding it when Close() is called.
func (*StreamEncoder) Close ¶
func (e *StreamEncoder) Close() error
Close implements the io.Closer interface for streaming morse encoding. Encodes all buffered data and writes it to the underlying writer. This method must be called to complete the encoding process.
func (*StreamEncoder) Write ¶
func (e *StreamEncoder) Write(p []byte) (n int, err error)
Write implements the io.Writer interface for streaming morse encoding. Accumulates data in the internal buffer without immediate encoding. The actual encoding occurs when Close() is called.
Source Files
¶
- errors.go
- morse.go