1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        Y3快速和低 CPU 損耗的編解碼器

        聯(lián)合創(chuàng)作 · 2023-09-29 16:34

        Y3 是一種 YoMo Codec 的 Golang 實(shí)現(xiàn),它描述了個(gè)快速和低 CPU 損耗的編解碼器,專注于邊緣計(jì)算和流處理。

        查看 explainer 獲取更多信息,了解更多與 YoMo 組合的方式。

        Y3 Codec

        查看 Y3 Codec SPEC

        測(cè)試

        go test ./...

        使用

        go get -u github.com/yomorun/y3-codec-golang
        

        編碼例子

        package main
        
        import (
        	"fmt"
        	y3 "github.com/yomorun/y3-codec-golang"
        )
        
        func main() {
        	// if we want to repesent `var obj = &foo{ID: -1, bar: &bar{Name: "C"}}` 
        	// in Y3-Codec:
        
        	// 0x81 -> node
        	var foo = y3.NewNodePacketEncoder(0x01)
        
        	// 0x02 -> foo.ID=-11
        	var yp1 = y3.NewPrimitivePacketEncoder(0x02)
        	yp1.SetInt32Value(-1)
        	foo.AddPrimitivePacket(yp1)
        
        	// 0x83 -> &bar{}
        	var bar = y3.NewNodePacketEncoder(0x03)
        
        	// 0x04 -> bar.Name="C"
        	var yp2 = y3.NewPrimitivePacketEncoder(0x04)
        	yp2.SetStringValue("C")
        	bar.AddPrimitivePacket(yp2)
        	
        	// -> foo.bar=&bar
        	foo.AddNodePacket(bar)
        
        	fmt.Printf("res=%#v", foo.Encode()) // res=[]byte{0x81, 0x08, 0x02, 0x01, 0x7F, 0x83, 0x03, 0x04, 0x01, 0x43}
        }

        解碼例子 1: 解碼一個(gè)原始數(shù)據(jù)包

        package main
        
        import (
        	"fmt"
        	y3 "github.com/yomorun/y3-codec-golang"
        )
        
        func main() {
        	fmt.Println(">> Parsing [0x0A, 0x01, 0x7F], which like Key-Value format = 0x0A: 127")
        	buf := []byte{0x0A, 0x01, 0x7F}
        	res, _, err := y3.DecodePrimitivePacket(buf)
        	v1, err := res.ToUInt32()
        	if err != nil {
        		panic(err)
        	}
        
        	fmt.Printf("Tag Key=[%#X], Value=%v\\n", res.SeqID(), v1)
        }

        解碼例子 2: 解碼一個(gè)節(jié)點(diǎn)數(shù)據(jù)包

        package main
        
        import (
        	"fmt"
        	y3 "github.com/yomorun/y3-codec-golang"
        )
        
        func main() {
        	fmt.Println(">> Parsing [0x84, 0x06, 0x0A, 0x01, 0x7F, 0x0B, 0x01, 0x43] EQUALS JSON= 0x84: { 0x0A: -1, 0x0B: 'C' }")
        	buf := []byte{0x84, 0x06, 0x0A, 0x01, 0x7F, 0x0B, 0x01, 0x43}
        	res, _, err := y3.DecodeNodePacket(buf)
        	v1 := res.PrimitivePackets[0]
        
        	p1, err := v1.ToInt32()
        	if err != nil {
        		panic(err)
        	}
        	fmt.Printf("Tag Key=[%#X.%#X], Value=%v\\n", res.SeqID(), v1.SeqID(), p1)
        
        	v2 := res.PrimitivePackets[1]
        
        	p2, err := v2.ToUTF8String()
        	if err != nil {
        		panic(err)
        	}
        
        	fmt.Printf("Tag Key=[%#X.%#X], Value=%v\\n", res.SeqID(), v2.SeqID(), p2)
        }
        

        性能

        瀏覽 23
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            国产丝袜91久久久久久久久久久 | 北条麻妃最新黑人 码 | 激情午夜天 | 五月激情深爱网 | 加勒比无码视频在线观看 | 特黄AV | 亚洲精品午夜成人片DY888 | 国产拍拍 | 免费视频一区二区三区四区 | 亚州乱伦视频 |