Git Product home page Git Product logo

jt808-golang's Introduction

Go

部分实现和测试用例参考 https://github.com/SmallChi/JT808

Project is WIP

Message Def

type Body0001 struct {
	AckMesgId   uint16
	AckSerialId uint16
	AckType     uint8
}

结构体字段顺序按照序列化的先后顺序。

Field type mapping

Golang Type Protocl Type Tag
uint8 byte
uint16 word
uint32 dword
[]byte byte[n] n,raw
string bcd[n] n,bcd
string string n,gbk

Complex message unmarshal

./jt808/message/0200.go

先将消息解析为 []byte 类型,然后在结构体中增加方法单独解析。

Package message unmarshal

如果消息头部中包含分包信息MessagePack.Package,则消息正文会被解析为message.PartialPackBody

待消息全部接收完成后,使用 jt808.ConcatUnmarshal(packs []*MessagePack[*message.PartialPackBody], target *MessagePack[T]) 方法一并进行解析。

详情见 ./jt808/decoder_test.go:40 中的测试用例。

Benchmark

Just to see how it works. Don't take it seriously.

> go version
go version go1.20.10 darwin/arm64

> sysctl -a | grep machdep.cpu.brand_string
machdep.cpu.brand_string: Apple M1 Pro

> go test -bench=. -benchmem  ./...
Benchmark_Unmarshal0001-8   	 1186509	      1006 ns/op	     776 B/op	      23 allocs/op

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.