morse

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 4 Imported by: 0

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

View Source
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": "----.",

	".": ".-.-.-", ",": "--..--", "?": "..--..", "'": ".----.", "!": "-.-.--",
	"(": "-.--.", ")": "-.--.-", "&": ".-...", ":": "---...",
	";": "-.-.-.", "=": "-...-", "+": ".-.-.", "-": "-....-", "_": "..--.-",
	"\"": ".-..-.", "$": "...-..-", "@": ".--.-.",

	"[": "-.--.--", "]": "--.--.--", "{": "-.--.---", "}": "--.--.---",
	"|": "-.-..-", "\\": "-.-..-.", "~": ".--.--..", "`": ".-..--.",
	"^": ".-.--.-", "%": "..---.", "#": "..-..-", "*": ".-..-",
	"<": ".--.-", ">": "--.-.", "§": ".--..-..",
	"/": "-..-.",

	" ":  "/",
	"\n": ".-..-.-", "\r": ".-..-.-", "\t": "-...-..",
}

StdAlphabet is the standard morse code alphabet following international standards. Extended to include letters a-z, numbers 0-9, punctuation marks, and special characters. Added support for space character and more comprehensive punctuation.

View Source
var StdSeparator = " "

Functions

func NewStreamDecoder

func NewStreamDecoder(r io.Reader) io.Reader

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 {
	Char string // The invalid character that was found
}

InvalidInputError represents an error when the morse input is invalid. This error is now rarely used since most characters are supported.

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. Supports all extended characters including punctuation and symbols.

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. Supports all printable characters including spaces, punctuation, and symbols. Input text is converted to lowercase before encoding to ensure compatibility.

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 processing data in chunks and writing encoded output immediately.

func (*StreamEncoder) Close

func (e *StreamEncoder) Close() error

Close implements the io.Closer interface for streaming morse encoding. Processes any remaining buffered bytes from the last Write call. Supports all printable characters including spaces, punctuation, and symbols.

func (*StreamEncoder) Write

func (e *StreamEncoder) Write(p []byte) (n int, err error)

Write implements the io.Writer interface for streaming morse encoding. Processes data character by character for true streaming. Each character is immediately encoded and output, maintaining minimal state. Supports all printable characters including spaces, punctuation, and symbols.

Source Files

  • errors.go
  • morse.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL