Giter Club home page Giter Club logo

Comments (3)

MrChang0 avatar MrChang0 commented on May 25, 2024 2

@xhaoxiong 我们对unpack的设计和理解应该是从一个tcp原始数据 -> 我们可以用的最基本的数据包,将业务代码和原始报文处理分离。在里面就需要人们根据自己的需求去实现对应的unpack方法。换而言之,netty的各种decoder方法我们都可以基于我们的 unpack 去实现对应功能。
我这里举个例子,如果我们是按长度取数的话,在unpack里就可以 if buffer.virtrualLength() > 100 去判断是否有足够的数据,再决定返回内容继续处理还是nil来等待下次数据到来。对于其他的decoder方法都可以类比实现(有机会我们会在库里提供对应实现方便使用)。
当然还有很多不完善和有问题的的地方,如果有更好的意见或者建议请提给我们。

from gev.

itlabers avatar itlabers commented on May 25, 2024

使用protobuf 序列化 , 通过多线程发报文的情况下,确实有粘报文体,代码如下:
top, tail := buffer.PeekAll()
data := append(top, tail...)
log.Printf("request Host:[%s] msg:%x", c.PeerAddr(), data)
var communication protobuf.Communication
if e := proto.Unmarshal(data, &communication); e == nil {
buffer.RetrieveAll()
//逻辑处理
} else {
log.Printf("Unmarshal error %v", e)
}

communication Unmarshal error:proto: protobuf.Communication: illegal tag 0 (wire type 1)

from gev.

MrChang0 avatar MrChang0 commented on May 25, 2024

@itlabers 对于网络处理,一定要有方式去把“数据包”正确完整得取出来。对于你这种推荐在包头用2字节确认后续包长度,可以看ws对于数据包得处理。

from gev.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.