-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore!: change Centrifugo subscription contract
- Loading branch information
1 parent
a8208b8
commit f785280
Showing
7 changed files
with
62 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package opcua | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
const channelPrefix = "opcua:" | ||
|
||
type sentinelError string | ||
|
||
func (e sentinelError) Error() string { | ||
return string(e) | ||
} | ||
|
||
// ErrNotOpcUaChannel is issued when the channel is not suitable for OPC-UA. | ||
const ErrNotOpcUaChannel = sentinelError("not an OPC-UA suitable channel") | ||
|
||
// PublishingInterval represents a publishing interval. | ||
type PublishingInterval time.Duration | ||
|
||
// ParseChannel parses a Centrifugo channel into a publishing interval. | ||
// | ||
// See "Specifications" section in README.md for the format of the channel. | ||
func ParseChannel(s string) (PublishingInterval, error) { | ||
if !strings.HasPrefix(s, channelPrefix) { | ||
return 0, ErrNotOpcUaChannel | ||
} | ||
|
||
cn := strings.TrimPrefix(s, channelPrefix) | ||
|
||
ms, err := strconv.ParseUint(cn, 10, 64) | ||
switch { | ||
case err != nil: | ||
return 0, fmt.Errorf("error parsing interval: %w", err) | ||
case ms > uint64(time.Duration(1<<63-1).Milliseconds()): | ||
return 0, fmt.Errorf("interval too big: %d", ms) | ||
} | ||
|
||
return PublishingInterval(time.Duration(ms) * time.Millisecond), nil | ||
} | ||
|
||
// Channel returns the Centrifugo channel name for this monitored node. | ||
func (p PublishingInterval) Channel() string { | ||
return fmt.Sprint(channelPrefix, time.Duration(p).Milliseconds()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package opcua | ||
|
||
import "time" | ||
|
||
func (m *Monitor) AddSubscription(interval time.Duration, sub Subscription) { | ||
func (m *Monitor) AddSubscription(interval PublishingInterval, sub Subscription) { | ||
m.subs[interval] = sub | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.