Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/protoc-gen-golite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// both proto2 and proto3 versions of the protocol buffer language.
//
// For more information about the usage of this plugin, see:
//
// https://developers.google.com/protocol-buffers/docs/reference/go-generated
package main

Expand Down
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
module github.com/RomiChan/protobuf

go 1.18
go 1.26

Comment on lines +3 to 4
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping the module’s go version from 1.18 to 1.26 is a breaking change for consumers and CI/tooling. Please confirm this is intentional (and supported by your build pipeline), or consider keeping the minimum version lower / adding a toolchain directive if you only want to pin the toolchain used by this repo.

Suggested change
go 1.26
go 1.18
toolchain go1.26.0

Copilot uses AI. Check for mistakes.
require (
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
github.com/stretchr/testify v1.7.0
google.golang.org/protobuf v1.27.1
github.com/stretchr/testify v1.11.1
google.golang.org/protobuf v1.36.11
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
40 changes: 24 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 h1:S/ferNiehVjNaBMNNBxUjLtVmP/YWD6Yh79RfPv4ehU=
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 12 additions & 0 deletions internal/runtime_reflect/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,24 @@ type hiter struct {
checkBucket uintptr
}

// ***** ***** king add 20260331 ****** *****

// 传入map的地址 不能为*map
func GetSize(m unsafe.Pointer) int { return reflect_maplen(m) }

//go:noescape
//go:linkname reflect_maplen reflect.maplen
func reflect_maplen(m unsafe.Pointer) int
Comment on lines +78 to +83
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetSize is a misleading name (it returns the map length, not a size), and the comment says “pass the map address” which doesn’t match how it’s used (callers pass the map value pointer, not a *map). Please rename to something like MapLen and clarify the parameter expectations in the comment.

Copilot uses AI. Check for mistakes.

// ***** ***** king add 20260331 ****** *****

//go:noescape
//go:linkname makemap reflect.makemap
func makemap(t unsafe.Pointer, cap int) unsafe.Pointer

// m escapes into the return value, but the caller of mapiterinit
// doesn't let the return value escape.
//
//go:noescape
//go:linkname mapiterinit runtime.mapiterinit
func mapiterinit(t unsafe.Pointer, m unsafe.Pointer, it *hiter)
Expand Down
24 changes: 16 additions & 8 deletions proto/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func (w *walker) mapCodec(t reflect.Type, f *mapField) *codec {
return m
}

// ??? map len

Comment on lines +30 to +31
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment // ??? map len is unclear and doesn’t document any behavior. Please replace it with a meaningful comment (or remove it) so future readers understand why map length handling is special here.

Suggested change
// ??? map len
// Nil maps and maps with zero entries contribute no encoded size, so
// size/encode paths return early before creating an iterator.

Copilot uses AI. Check for mistakes.
func mapSizeFuncOf(t reflect.Type, f *mapField) sizeFunc {
mapTagSize := sizeOfVarint(f.wiretag)
keyCodec := f.keyField.codec
Expand All @@ -36,11 +38,14 @@ func mapSizeFuncOf(t reflect.Type, f *mapField) sizeFunc {
if p == nil {
return 0
}
if p = *(*unsafe.Pointer)(p); p == nil {
return 0
} // king add 20260331 // *map => map // map == nil
if GetSize(p) == 0 {
return 0
} // king add 20260331 // map.len == 0,
Comment on lines +41 to +46
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new GetSize/early-return behavior changes map encoding semantics for nil/empty maps. There are existing map round-trip tests, but none cover nil or empty maps; please add a test that (1) marshaling a nil/empty map emits no bytes for that field, and (2) unmarshaling does not create a default key/value entry.

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +46
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new early return for GetSize(p) == 0, the later if n == 0 { ... } fallback (below this block) should be unreachable. Consider removing that fallback to avoid confusing control-flow and to prevent accidentally reintroducing the old “empty map encodes as one empty entry” behavior.

Copilot uses AI. Check for mistakes.

p = *(*unsafe.Pointer)(p)

n := 0
m := MapIter{}
n, m := 0, MapIter{}
defer m.Done()

for m.Init(pointer(t), p); m.HasNext(); m.Next() {
Expand All @@ -65,11 +70,14 @@ func mapEncodeFuncOf(t reflect.Type, f *mapField) encodeFunc {
if p == nil {
return b
}
p = *(*unsafe.Pointer)(p)

origLen := len(b)
if p = *(*unsafe.Pointer)(p); p == nil {
return b
} // king add 20260331 // *map => map // map == nil
if GetSize(p) == 0 {
return b
} // king add 20260331 // map.len == 0 不写入buf
Comment on lines +76 to +78
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new early return for GetSize(p) == 0, the later if len(b) == origLen { ... } fallback (later in this function) should be unreachable. Consider removing it so empty maps are handled only by the explicit early return and to reduce dead code paths.

Copilot uses AI. Check for mistakes.

m := MapIter{}
origLen, m := len(b), MapIter{}
defer m.Done()

for m.Init(pointer(t), p); m.HasNext(); m.Next() {
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the iteration below, valSize is computed using keyCodec.size(...) instead of valCodec.size(...) (see the map-entry sizing inside the loop). This will produce an incorrect length prefix when key/value codecs differ, corrupting the encoded output and potentially breaking decoding.

Copilot uses AI. Check for mistakes.
Expand Down
Loading