Coder Social home page Coder Social logo

protocol-engine's Introduction

protocol-engine

项目背景

目前java解析二进制字节流没有好的类库封装,我们在解析字节流的协议时,需要按照字段顺序逐个手动抠出,
费事费力且很容易出错,受C语言解析二进制字节流的启发,封装了此Java类库,欢迎大家使用!

再开始介绍这个框架时,首先约定一下协议的定义方式

X1 X2 X3 ... Xn

X1:代表第一个字节
X2:代表第二个字节
Xn: 代表第n个字节

C语言协议解析简介

假如我们有个这样的协议需要解析:
X1 X2 X3 X4 X5 X6 X1 X2:长度16Bit 小端格式
X3 X4:长度16Bit 小端格式
X5: 长度1个字节
X6: 长度一个字节
那么我们用C语言会以如下方式来解析

struct protocol_example
{
	unsigned short column1,
	unsigned short column2,
	unsigned char column3,
	unsigned char column4
}
code example:
unsigned char[] recv_buf = ...;
protocol_example* example = (protocol_example*) &recv_buf;
if(example->column1 == 355) {
	dosomeing();
}
// decode protocol end

protocol-engine's People

Contributors

tuna-cloud avatar xsyjjh avatar endlessc avatar

Watchers

James Cloos avatar  avatar  avatar

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.