Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
熹乐科技
Yomo
提交
59e55409
Y
Yomo
项目概览
熹乐科技
/
Yomo
通知
24
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
Yomo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
59e55409
编写于
2月 18, 2021
作者:
J
JJW
提交者:
GitHub
2月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(rx): add y3Encode (#127)
Co-authored-by:
N
jjwygjj
<
wangyaoguang@cel.la
>
上级
bb7834f9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
18 deletion
+42
-18
example/flow/app.go
example/flow/app.go
+2
-1
example/sink/app.go
example/sink/app.go
+2
-1
internal/cmd/run.go
internal/cmd/run.go
+1
-16
pkg/rx/rxstream.go
pkg/rx/rxstream.go
+1
-0
pkg/rx/rxstream_operator.go
pkg/rx/rxstream_operator.go
+36
-0
未找到文件。
example/flow/app.go
浏览文件 @
59e55409
...
@@ -43,7 +43,8 @@ func Handler(rxstream rx.RxStream) rx.RxStream {
...
@@ -43,7 +43,8 @@ func Handler(rxstream rx.RxStream) rx.RxStream {
OnObserve
(
callback
)
.
OnObserve
(
callback
)
.
Debounce
(
rxgo
.
WithDuration
(
50
*
time
.
Millisecond
))
.
Debounce
(
rxgo
.
WithDuration
(
50
*
time
.
Millisecond
))
.
Map
(
printer
)
.
Map
(
printer
)
.
StdOut
()
StdOut
()
.
Encode
(
0x10
)
return
stream
return
stream
}
}
example/sink/app.go
浏览文件 @
59e55409
...
@@ -25,6 +25,7 @@ func Handler(rxstream rx.RxStream) rx.RxStream {
...
@@ -25,6 +25,7 @@ func Handler(rxstream rx.RxStream) rx.RxStream {
Subscribe
(
0x11
)
.
Subscribe
(
0x11
)
.
OnObserve
(
callback
)
.
OnObserve
(
callback
)
.
AuditTime
(
100
*
time
.
Millisecond
)
.
AuditTime
(
100
*
time
.
Millisecond
)
.
Map
(
store
)
Map
(
store
)
.
Encode
(
0x10
)
return
stream
return
stream
}
}
internal/cmd/run.go
浏览文件 @
59e55409
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"plugin"
"plugin"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
y3
"github.com/yomorun/y3-codec-golang"
"github.com/yomorun/yomo/internal/dispatcher"
"github.com/yomorun/yomo/internal/dispatcher"
"github.com/yomorun/yomo/internal/serverless"
"github.com/yomorun/yomo/internal/serverless"
"github.com/yomorun/yomo/pkg/quic"
"github.com/yomorun/yomo/pkg/quic"
...
@@ -19,8 +18,6 @@ type RunOptions struct {
...
@@ -19,8 +18,6 @@ type RunOptions struct {
baseOptions
baseOptions
// Port is the port number of UDP host for Serverless function (default is 4242).
// Port is the port number of UDP host for Serverless function (default is 4242).
Port
int
Port
int
mockSink
bool
}
}
// NewCmdRun creates a new command run.
// NewCmdRun creates a new command run.
...
@@ -47,7 +44,6 @@ func NewCmdRun() *cobra.Command {
...
@@ -47,7 +44,6 @@ func NewCmdRun() *cobra.Command {
endpoint
:=
fmt
.
Sprintf
(
"0.0.0.0:%d"
,
opts
.
Port
)
endpoint
:=
fmt
.
Sprintf
(
"0.0.0.0:%d"
,
opts
.
Port
)
quicHandler
:=
&
quicServerHandler
{
quicHandler
:=
&
quicServerHandler
{
serverlessHandle
:
slHandler
,
serverlessHandle
:
slHandler
,
mockSink
:
opts
.
mockSink
,
}
}
err
=
serverless
.
Run
(
endpoint
,
quicHandler
)
err
=
serverless
.
Run
(
endpoint
,
quicHandler
)
...
@@ -59,14 +55,12 @@ func NewCmdRun() *cobra.Command {
...
@@ -59,14 +55,12 @@ func NewCmdRun() *cobra.Command {
cmd
.
Flags
()
.
StringVarP
(
&
opts
.
Filename
,
"file-name"
,
"f"
,
"app.go"
,
"Serverless function file (default is app.go)"
)
cmd
.
Flags
()
.
StringVarP
(
&
opts
.
Filename
,
"file-name"
,
"f"
,
"app.go"
,
"Serverless function file (default is app.go)"
)
cmd
.
Flags
()
.
IntVarP
(
&
opts
.
Port
,
"port"
,
"p"
,
4242
,
"Port is the port number of UDP host for Serverless function (default is 4242)"
)
cmd
.
Flags
()
.
IntVarP
(
&
opts
.
Port
,
"port"
,
"p"
,
4242
,
"Port is the port number of UDP host for Serverless function (default is 4242)"
)
cmd
.
Flags
()
.
BoolVar
(
&
opts
.
mockSink
,
"mock-sink"
,
false
,
"Indicates whether the Serverless is a mock sink"
)
return
cmd
return
cmd
}
}
type
quicServerHandler
struct
{
type
quicServerHandler
struct
{
serverlessHandle
plugin
.
Symbol
serverlessHandle
plugin
.
Symbol
mockSink
bool
}
}
func
(
s
quicServerHandler
)
Listen
()
error
{
func
(
s
quicServerHandler
)
Listen
()
error
{
...
@@ -76,21 +70,12 @@ func (s quicServerHandler) Listen() error {
...
@@ -76,21 +70,12 @@ func (s quicServerHandler) Listen() error {
func
(
s
quicServerHandler
)
Read
(
st
quic
.
Stream
)
error
{
func
(
s
quicServerHandler
)
Read
(
st
quic
.
Stream
)
error
{
stream
:=
dispatcher
.
Dispatcher
(
s
.
serverlessHandle
,
rx
.
FromReaderWithY3
(
st
))
stream
:=
dispatcher
.
Dispatcher
(
s
.
serverlessHandle
,
rx
.
FromReaderWithY3
(
st
))
y3codec
:=
y3
.
NewCodec
(
0x10
)
go
func
()
{
go
func
()
{
for
customer
:=
range
stream
.
Observe
()
{
for
customer
:=
range
stream
.
Observe
()
{
if
customer
.
Error
()
{
if
customer
.
Error
()
{
fmt
.
Println
(
customer
.
E
.
Error
())
fmt
.
Println
(
customer
.
E
.
Error
())
}
else
if
customer
.
V
!=
nil
{
}
else
if
customer
.
V
!=
nil
{
// HACK
st
.
Write
((
customer
.
V
)
.
([]
byte
))
if
s
.
mockSink
{
st
.
Write
([]
byte
(
"Finish sink!"
))
}
else
{
// use Y3 codec to encode the data
sendingBuf
,
_
:=
y3codec
.
Marshal
(
customer
.
V
)
st
.
Write
(
sendingBuf
)
}
}
}
}
}
}()
}()
...
...
pkg/rx/rxstream.go
浏览文件 @
59e55409
...
@@ -13,6 +13,7 @@ type RxStream interface {
...
@@ -13,6 +13,7 @@ type RxStream interface {
rxgo
.
Iterable
rxgo
.
Iterable
MergeReadWriterWithFunc
(
rwf
func
()
(
io
.
ReadWriter
,
func
()),
opts
...
rxgo
.
Option
)
RxStream
MergeReadWriterWithFunc
(
rwf
func
()
(
io
.
ReadWriter
,
func
()),
opts
...
rxgo
.
Option
)
RxStream
Subscribe
(
key
byte
)
RxStream
Subscribe
(
key
byte
)
RxStream
Encode
(
key
byte
,
opts
...
rxgo
.
Option
)
RxStream
OnObserve
(
function
func
(
v
[]
byte
)
(
interface
{},
error
))
RxStream
OnObserve
(
function
func
(
v
[]
byte
)
(
interface
{},
error
))
RxStream
StdOut
(
opts
...
rxgo
.
Option
)
RxStream
StdOut
(
opts
...
rxgo
.
Option
)
RxStream
AuditTime
(
timespan
time
.
Duration
,
opts
...
rxgo
.
Option
)
RxStream
AuditTime
(
timespan
time
.
Duration
,
opts
...
rxgo
.
Option
)
RxStream
...
...
pkg/rx/rxstream_operator.go
浏览文件 @
59e55409
...
@@ -571,6 +571,42 @@ func (s *RxStreamImpl) OnObserve(function func(v []byte) (interface{}, error)) R
...
@@ -571,6 +571,42 @@ func (s *RxStreamImpl) OnObserve(function func(v []byte) (interface{}, error)) R
return
CreateObservable
(
f
)
return
CreateObservable
(
f
)
}
}
func
(
s
*
RxStreamImpl
)
Encode
(
key
byte
,
opts
...
rxgo
.
Option
)
RxStream
{
y3codec
:=
y3
.
NewCodec
(
key
)
f
:=
func
(
ctx
context
.
Context
,
next
chan
rxgo
.
Item
)
{
defer
close
(
next
)
observe
:=
s
.
Observe
(
opts
...
)
for
{
select
{
case
<-
ctx
.
Done
()
:
return
case
item
,
ok
:=
<-
observe
:
if
!
ok
{
return
}
if
item
.
Error
()
{
return
}
buf
,
err
:=
y3codec
.
Marshal
(
item
.
V
)
if
err
!=
nil
{
return
}
if
!
Of
(
buf
)
.
SendContext
(
ctx
,
next
)
{
return
}
}
}
}
return
CreateObservable
(
f
,
opts
...
)
}
func
CreateObservable
(
f
func
(
ctx
context
.
Context
,
next
chan
rxgo
.
Item
),
opts
...
rxgo
.
Option
)
RxStream
{
func
CreateObservable
(
f
func
(
ctx
context
.
Context
,
next
chan
rxgo
.
Item
),
opts
...
rxgo
.
Option
)
RxStream
{
next
:=
make
(
chan
rxgo
.
Item
)
next
:=
make
(
chan
rxgo
.
Item
)
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录