Skip to content

Commit

Permalink
Re-use message writing and formatting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jul 13, 2024
1 parent 168485c commit 946a0cc
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions singer_sdk/_singerlib/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dataclasses import asdict, dataclass, field
from datetime import datetime, timezone

from singer_sdk._singerlib.json import serialize_json
from singer_sdk._singerlib.encoding import SingerWriter

if sys.version_info < (3, 11):
from backports.datetime_fromisoformat import MonkeyPatch
Expand Down Expand Up @@ -205,23 +205,6 @@ def __post_init__(self) -> None:
self.type = SingerMessageType.ACTIVATE_VERSION


def format_message(message: Message) -> str:
"""Format a message as a JSON string.
Args:
message: The message to format.
Returns:
The formatted message.
"""
return serialize_json(message.to_dict())


def write_message(message: Message) -> None:
"""Write a message to stdout.
Args:
message: The message to write.
"""
sys.stdout.write(format_message(message) + "\n")
sys.stdout.flush()
WRITER = SingerWriter()
format_message = WRITER.format_message
write_message = WRITER.write_message

0 comments on commit 946a0cc

Please sign in to comment.