romichan / protobuf Goto Github PK
View Code? Open in Web Editor NEWlightweight and fast protobuf support for go
License: MIT License
lightweight and fast protobuf support for go
License: MIT License
Todo:
package main
import (
"encoding/hex"
"fmt"
"github.com/RomiChan/protobuf/proto" // v0.1.1-0.20220524030518-4f349493f9da
)
type ST1 struct {
ST *ST2 `protobuf:"bytes,1,opt"`
}
type ST2 struct {
ST *ST3 `protobuf:"bytes,1,opt"`
}
type ST3 struct {
Str []byte `protobuf:"bytes,1,opt"`
}
func main() {
st := &ST1{&ST2{&ST3{
Str: make([]byte, 0x7D),
}}}
b, _ := proto.Marshal(st)
fmt.Println(hex.Dump(b))
st.ST = nil
err := proto.Unmarshal(b, st)
if err != nil {
fmt.Println(err)
}
}
00000000 0a 82 01 0a 7f 0a 7d 00 00 00 00 00 00 00 00 00 |......}.........|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000080 00 00 00 00 |....|
field number 1 with wire type 2: unexpected EOF
在 \proto\walker.go 中,计算内容长度时误把tagsize算了进去
...
func (w *walker) structCodec(t reflect.Type) *codec {
...
c.size = func(p unsafe.Pointer, f *structField) int {
p = deref(p)
if p != nil {
n := info.size(p) + f.tagsize // ???
n += sizeOfVarint(uint64(n))
return n
}
return 0
}
...
}
...
更改为以下代码即可
...
func (w *walker) structCodec(t reflect.Type) *codec {
...
c.size = func(p unsafe.Pointer, f *structField) int {
p = deref(p)
if p != nil {
n := info.size(p)
n += sizeOfVarint(uint64(n)) + f.tagsize // √
return n
}
return 0
}
...
}
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.