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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reserve tag [0xF000, 0xFFFF] #803

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ai/function_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// ReducerTag is the observed tag of the reducer
var ReducerTag uint32 = 0x61
var ReducerTag uint32 = 0xE000

// FunctionCall describes the data structure when invoking the sfn function
type FunctionCall struct {
Expand Down
14 changes: 12 additions & 2 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,18 @@ func (c *Client) SetDataFrameObserver(fn func(*frame.DataFrame)) {
}

// SetObserveDataTags set the data tag list that will be observed.
func (c *Client) SetObserveDataTags(tag ...frame.Tag) {
c.opts.observeDataTags = tag
func (c *Client) SetObserveDataTags(tags ...frame.Tag) {
for _, tag := range tags {
if isReservedTag(tag) {
panic("[0xF000, 0xFFFF] is reserved for Yomo; please do not observe within this range")
woorui marked this conversation as resolved.
Show resolved Hide resolved
}
}

c.opts.observeDataTags = tags
}

func isReservedTag(tag frame.Tag) bool {
return tag >= 0xF000 && tag <= 0xFFFF
}

// SetErrorHandler set error handler
Expand Down
10 changes: 10 additions & 0 deletions core/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
const (
testaddr = "127.0.0.1:19999"
redirectAddr = "127.0.0.1:19998"
testaddr1 = "127.0.0.1:19997"
)

var discardingLogger = ylog.NewFromConfig(ylog.Config{Output: "/dev/null", ErrorOutput: "/dev/null"})
Expand All @@ -38,6 +39,15 @@ func TestClientDialNothing(t *testing.T) {
assert.ErrorAs(t, err, &qerr, "dial must timeout")
}

func TestReservedTag(t *testing.T) {
sfn := NewClient("sfn", testaddr1, ClientTypeStreamFunction, WithLogger(discardingLogger))

assert.Panics(t, func() { sfn.SetObserveDataTags(0xF000) })
assert.Panics(t, func() { sfn.SetObserveDataTags(0xF001) })
assert.Panics(t, func() { sfn.SetObserveDataTags(0xFFFF) })

}

func TestConnectTo(t *testing.T) {
t.Parallel()
connectToEndpoint := "127.0.0.1:19996"
Expand Down