Skip to content

francistm/jt808-golang

Repository files navigation

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

About

JT808 Serde Golang 实现

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages