Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose packager and transporter structs for use with NewClient2 #59

Closed
wants to merge 2 commits into from

Conversation

andig
Copy link
Contributor

@andig andig commented Nov 6, 2022

Fix #56

This PR exposes packers and transporters. It does not modify existing api:

  • make packager/transporter fields public members of client handlers
  • add New*Transporter methods

Notes on implementation:

  • Use of public fields in the exposed client requires exposing the package/transporter types. With private members, the types returned by the New*Transporter methods would be "annoying" for the linter.
  • There is one open inconsistency with the current approach: while serial transports hide the serial port as implementation detail, the *TCP transports expose the underlying TCP transport. That can be changed, if desired consistently for both cases.
  • exposing TCPTransporter (which is an implementation detail) as part of the ASCII/RTUOverTCP transporters is unfortunate but required to keep the public fields visible.
  • serial transporters Printf() method was removed- it seems unused (will split into separete PR)

TODO

  • pointer receiver for serial transport is necessary to avoid copying of lock in serial port
  • consistently make all transports pointer receivers
  • decide if same is desired for packagers
  • decide future of rtu/ascii Printf() public api. With making serialTransport public, the transport's logger should be used instead. Proposal: remove Printf() (potential though minor BC break).

Alternatives:

Add a Clone() method that clones the entire client handler, sharing the underlying transport #70.

Maybe think about something like:

// WithPackager returns a new TCPClientHandler with given packager.
func (h *TCPClientHandler) WithPackager(p TCPPackager) {
	h.TCPPackager = p
}

@andig andig marked this pull request as draft November 6, 2022 14:31
@andig andig changed the title Feature/split packager transporter Expose packager and transporter structs for use with NewClient2 Apr 10, 2023
@andig andig force-pushed the feature/split-packager-transporter branch from 477bca7 to 4691150 Compare April 10, 2023 17:12
@andig andig force-pushed the feature/split-packager-transporter branch from 4691150 to 2ed010f Compare April 10, 2023 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: improve api by exposing packager and transporter
1 participant