GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tuna-cloud/engine: binary protocol decoder/encoder

BranchesTags
Open more actions menu

Latest commit

 

History

22 Commits
22 Commits

Folders and files

NameName
Last commit message
Last commit date
com-github-ioprotocol
com-github-ioprotocol
 
 
documention
documention
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

Protocol-Engine

ProtocolEngine is a binary protocol decoder or encoder, its work just like struct in C language,while the ProtocolEngine also provide much more advanced features.

Installation

To use ProtocolEngine you just need to include the com-github-ioprotocol-x.x.x.jar file in the classpath.

If you are using Maven just add the following dependency to your pom.xml:

<dependency>
    <groupId>com.github.ioprotocol</groupId>
    <artifactId>com-github-ioprotocol</artifactId>
    <version>1.2.0</version>
</dependency>

How to use it ?

ProtocolEngine engin = new ProtocolEngine();
JavaBean bean = engine.decode(byte[] buf, JavaBean.class);
// or
byte[] buf = engine.encode(bean);

Simple Example

Now we use a simple binary protocol begin our travel.
The binary protocol like this:

+--------+---------+--------+----------------+
| Header | Version | Length |   Content      |
| 0x2882 |   0x01  | 0x000B | "HELLO, WORLD" |
+--------+---------+--------+----------------+

First we need define a java class like this:

import com.github.io.protocol.annotation.AsciiString;
import com.github.io.protocol.annotation.ByteOrder;
import com.github.io.protocol.annotation.Number;

public class ProtocolTest {
    @Number(width = 16, order = ByteOrder.BigEndian)
    private int header;
    @Number(width = 8)
    private int version;
    @Number(width = 16, order = ByteOrder.BigEndian)
    private int contentLength;
    @AsciiString(length = "getContentLength")
    private String content;

    public int getHeader() {
        return header;
    }

    public void setHeader(int header) {
        this.header = header;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public int getContentLength() {
        return contentLength;
    }

    public void setContentLength(int contentLength) {
        this.contentLength = contentLength;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}

then we can decode or encode the protocol like this:

@Test
public void test() throws Exception {
	ProtocolEngine engine = new ProtocolEngine();

	ProtocolTest test = new ProtocolTest();
	test.setHeader(0x2882);
	test.setVersion(1);
	test.setContentLength(12);
	test.setContent("HELLO, WORLD");

	// we encode the ProtocolTest object to byte buffer.
	byte[] buf = engine.encode(test);
	System.out.println(HexStringUtil.toHexString(buf));
	// print msg:
	// 288201000C48454C4C4F2C20574F524C44

	// ok, now we decode the ProtocolTest object from byte[] array.
	ProtocolTest testDecode = engine.decode(buf, ProtocolTest.class);

	System.out.println(testDecode.toString());
	// print msg:
	// ProtocolTest{header=10370, version=1, contentLength=12, content='HELLO, WORLD'}
	// wow... is it work?
}

For more usage examples check the tests. Please check the documention. There are lots of cool things you should know.

Documention

  • More docs
  • Changelog
  • Important note
  • Wiki

Submit BUG

While you find bug or have good idea, welcome email to me.

Author info

Email:[email protected]
QQ:845158228

About

binary protocol decoder/encoder

github.com/ioprotocol/engine

Topics

binary-protocolprotocol-decoderprotocol-encoderprotocol-engine

Resources

Readme
Apache-2.0 license
Activity

Stars

3 stars

Watchers

2 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.