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

feat: 增加对流式解析的支持 #9

Merged
merged 2 commits into from
Jan 23, 2024
Merged

Conversation

p1g3
Copy link
Contributor

@p1g3 p1g3 commented Jan 19, 2024

No description provided.

@@ -5,11 +5,63 @@ import (
"io"
)

type CommonStream interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这样修改更清真一点:
修改 stream ,让其通过传入一个 readSeeker 来完成构造。

// 实现 EOF ReadN PeekN 等方法
type Stream struct {
	reader io.ReadSeeker
	current int64
}

func NewStream(rs io.ReadSeeker) *Stream {}


// 之前定义好的函数如何实现,以 ReadFromBytes 为例
func FromBytes(b []byte) (*Serialization, error) {
    rs := bytes.NewReader(b)
    var stream = NewObjectStream(rs)
}

serz/parser.go Outdated
@@ -19,6 +20,37 @@ type Serialization struct {
Contents []*TCContent
}

func FromReadSeeker(r io.ReadSeeker, len int) (*Serialization, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个接口 @phith0n 看一眼吧。
实际需求是希望从一个流中读出特定长度的 TCcontent. 看看是目前这个定义好,还是我下面的定义好。

// 外层手动跳过 magic 和 version
func ReadTCContentFromReader(io.ReadSeeker)  (*TCContent, error) 

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个len的意义确实不明确,libaray没有必要支持读取多个

@phith0n phith0n merged commit b842d91 into phith0n:master Jan 23, 2024
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.

3 participants