Giter Site home page Giter Site logo

goframe's Issues

关于LengthFieldBasedFrame的困惑

我把example中的例子改成下面这样为啥就跑不通了呢?希望鸟哥解惑下

encoderConfig := goframe.EncoderConfig{
		ByteOrder:                       binary.BigEndian,
		LengthFieldLength:               2,
		LengthAdjustment:                -2,
		LengthIncludesLengthFieldLength: false,
	}

	decoderConfig := goframe.DecoderConfig{
		ByteOrder:           binary.BigEndian,
		LengthFieldOffset:   0,
		LengthFieldLength:   2,
		LengthAdjustment:    -2,
		InitialBytesToStrip: 0,
	}

如何确认使用某个类型的编解码器

我发现我现在的消息满足
3 bytes length field at the beginning of 5 bytes header, do not strip header
这个格式,但是不知道要用哪一个编解码器
希望可以得到解答

参数配置和期望结果不一样,劳烦请教一下。

[]byte{  0xFF,0xFF, //固定头1
	0x09,//长度 = 序列号域 + 命令代码 + 数据域 +校验和域 (不包含 固定头1 固定头2)
	0x80,//固定头2 
	0x31,//序列号域
	0x32,//命令代码
	0x33,0x34,0x35,0x36,0x37,0x38,//数据域
	0xFA,//校验和域
}

使用

	decoderConfig := goframe.DecoderConfig{
		ByteOrder:           binary.BigEndian,
		LengthFieldOffset:   2, //起始域
		LengthFieldLength:   1, //长度域
		LengthAdjustment:    0 , //版本
		InitialBytesToStrip: 3, // 起始域 + 长度域
	}

期望值

0x31,//序列号域
0x32,//命令代码
0x33,0x34,0x35,0x36,0x37,0x38,//数据域
0xFA,//校验和域

实际解析出来

---------------------------------------------
003132333435
---------------------------------------------
3738FAFFFF09003132333435363738FAFFFF09003132333435363738FAFFFF09003132333435363738FAFFFF09003132333435
---------------------------------------------
3738FAFFFF09003132333435363738FAFFFF09003132333435363738FAFFFF09003132333435363738FAFFFF09003132333435
---------------------------------------------
3738FAFFFF09003132333435363738FAFFFF09003132333435363738FAFFFF09003132333435363738FA333435363738FAFFFF
---------------------------------------------
003132333435
---------------------------------------------
3738FAFFFF09003132333435363738FAFFFF09003132333435363738FAFFFF09003132333435363738FAFFFF09003132333435
---------------------------------------------
3738FAFFFF09003132333435363738FAFFFF09003132333435363738FAFFFF09003132333435363738FAFFFF09003132333435

请问该如何配置 ,谢谢您!

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.