Compare commits
No commits in common. "master" and "master" have entirely different histories.
33 changed files with 48 additions and 206 deletions
|
@ -1,70 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Generator: Adobe Illustrator 25.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
|
||||||
<svg version="1.1" id="Слой_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
|
||||||
viewBox="0 0 184.2 51.8" style="enable-background:new 0 0 184.2 51.8;" xml:space="preserve">
|
|
||||||
<style type="text/css">
|
|
||||||
.st0{display:none;}
|
|
||||||
.st1{display:inline;}
|
|
||||||
.st2{fill:#01E397;}
|
|
||||||
.st3{display:inline;fill:#010032;}
|
|
||||||
.st4{display:inline;fill:#00E599;}
|
|
||||||
.st5{display:inline;fill:#00AF92;}
|
|
||||||
.st6{fill:#00C3E5;}
|
|
||||||
</style>
|
|
||||||
<g id="Layer_2">
|
|
||||||
<g id="Layer_1-2" class="st0">
|
|
||||||
<g class="st1">
|
|
||||||
<path class="st2" d="M146.6,18.3v7.2h10.9V29h-10.9v10.7h-4V14.8h18v3.5H146.6z"/>
|
|
||||||
<path class="st2" d="M180,15.7c1.7,0.9,3,2.2,4,3.8l-3,2.7c-0.6-1.3-1.5-2.4-2.6-3.3c-1.3-0.7-2.8-1-4.3-1
|
|
||||||
c-1.4-0.1-2.8,0.3-4,1.1c-0.9,0.5-1.5,1.5-1.4,2.6c0,1,0.5,1.9,1.4,2.4c1.5,0.8,3.2,1.3,4.9,1.5c1.9,0.3,3.7,0.8,5.4,1.6
|
|
||||||
c1.2,0.5,2.2,1.3,2.9,2.3c0.6,1,1,2.2,0.9,3.4c0,1.4-0.5,2.7-1.3,3.8c-0.9,1.2-2.1,2.1-3.5,2.6c-1.7,0.6-3.4,0.9-5.2,0.8
|
|
||||||
c-5,0-8.6-1.6-10.7-5l2.9-2.8c0.7,1.4,1.8,2.5,3.1,3.3c1.5,0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3-3.2-2-5.1-1.9C91.5,17.3,89.6,18,88.1,19.3z"/>
|
|
||||||
<path class="st3" d="M131,17.3c2.2,2.3,3.2,5.5,3.2,9.5s-1,7.3-3.2,9.6s-5.1,3.4-8.8,3.4s-6.7-1.1-8.9-3.4s-3.2-5.5-3.2-9.6
|
|
||||||
s1.1-7.2,3.2-9.5s5.1-3.4,8.9-3.4S128.9,15,131,17.3z M116.2,19.9c-1.5,2-2.2,4.4-2.1,6.9c-0.2,2.5,0.6,5,2.1,7
|
|
||||||
c1.5,1.7,3.7,2.7,6,2.6c2.3,0.1,4.4-0.9,5.9-2.6c1.5-2,2.3-4.5,2.1-7c0.1-2.5-0.6-4.9-2.1-6.9c-1.5-1.7-3.6-2.7-5.9-2.6
|
|
||||||
C119.9,17.2,117.7,18.2,116.2,19.9z"/>
|
|
||||||
<polygon class="st4" points="0,9.1 0,43.7 22.5,51.8 22.5,16.9 46.8,7.9 24.8,0 "/>
|
|
||||||
<polygon class="st5" points="24.3,17.9 24.3,36.8 46.8,44.9 46.8,9.6 "/>
|
|
||||||
</g>
|
|
||||||
<g>
|
|
||||||
<g>
|
|
||||||
<path class="st6" d="M41.6,17.5H28.2v6.9h10.4v3.3H28.2v10.2h-3.9V14.2h17.2V17.5z"/>
|
|
||||||
<path class="st6" d="M45.8,37.9v-18h3.3l0.4,3.2c0.5-1.2,1.2-2.1,2.1-2.7c0.9-0.6,2.1-0.9,3.5-0.9c0.4,0,0.7,0,1.1,0.1
|
|
||||||
c0.4,0.1,0.7,0.2,0.9,0.3l-0.5,3.4c-0.3-0.1-0.6-0.2-0.9-0.2C55.4,23,54.9,23,54.4,23c-0.7,0-1.5,0.2-2.2,0.6
|
|
||||||
c-0.7,0.4-1.3,1-1.8,1.8s-0.7,1.8-0.7,3v9.5H45.8z"/>
|
|
||||||
<path class="st6" d="M68.6,19.6c1.8,0,3.3,0.4,4.6,1.1c1.3,0.7,2.4,1.8,3.1,3.2s1.1,3.1,1.1,5c0,1.9-0.4,3.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.1,0,2.1-0.1,2.9-0.4c0.8-0.3,1.4-0.7,1.8-1.2c0.4-0.5,0.6-1.1,0.6-1.9
|
|
||||||
c0-0.7-0.2-1.3-0.7-1.8c-0.5-0.5-1.3-0.9-2.6-1.2l-5.2-1.2c-1.4-0.3-2.6-0.8-3.6-1.3c-0.9-0.6-1.6-1.3-2.1-2.1s-0.7-1.8-0.7-2.8
|
|
||||||
c0-1.3,0.4-2.6,1.1-3.7c0.7-1.1,1.8-2,3.2-2.6C147.3,14.1,148.9,13.8,150.9,13.8z"/>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 5.5 KiB |
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
* @TrueCloudLab/storage-core @TrueCloudLab/storage-services @TrueCloudLab/committers
|
|
@ -50,7 +50,7 @@ linters:
|
||||||
- bidichk
|
- bidichk
|
||||||
- durationcheck
|
- durationcheck
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- copyloopvar
|
- exportloopref
|
||||||
- gofmt
|
- gofmt
|
||||||
- goimports
|
- goimports
|
||||||
- misspell
|
- misspell
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
.* @TrueCloudLab/storage-core-committers @TrueCloudLab/storage-core-developers @TrueCloudLab/storage-services-committers @TrueCloudLab/storage-services-developers
|
|
||||||
.forgejo/.* @potyarkin
|
|
|
@ -25,8 +25,7 @@ Start by forking the `frostfs-api-go` repository, make changes in a branch and t
|
||||||
send a pull request. We encourage pull requests to discuss code changes. Here
|
send a pull request. We encourage pull requests to discuss code changes. Here
|
||||||
are the steps in details:
|
are the steps in details:
|
||||||
|
|
||||||
### Set up your repository
|
### Set up your GitHub Repository
|
||||||
|
|
||||||
Fork [FrostFS node upstream](https://git.frostfs.info/TrueCloudLab/frostfs-api-go/fork) source
|
Fork [FrostFS node upstream](https://git.frostfs.info/TrueCloudLab/frostfs-api-go/fork) source
|
||||||
repository to your own personal repository. Copy the URL of your fork (you will
|
repository to your own personal repository. Copy the URL of your fork (you will
|
||||||
need it for the `git clone` command below).
|
need it for the `git clone` command below).
|
||||||
|
@ -87,7 +86,7 @@ $ git push origin feature/123-something_awesome
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create a Pull Request
|
### Create a Pull Request
|
||||||
Pull requests can be created via git.frostfs.info. Refer to [this
|
Pull requests can be created via GitHub. Refer to [this
|
||||||
document](https://help.github.com/articles/creating-a-pull-request/) for
|
document](https://help.github.com/articles/creating-a-pull-request/) for
|
||||||
detailed steps on how to create a pull request. After a Pull Request gets peer
|
detailed steps on how to create a pull request. After a Pull Request gets peer
|
||||||
reviewed and approved, it will be merged.
|
reviewed and approved, it will be merged.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="./.forgejo/logo.svg" width="500px" alt="FrostFS">
|
<img src="./.github/logo.svg" width="500px" alt="FrostFS">
|
||||||
</p>
|
</p>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
Low-level Golang API for <a href="https://frostfs.info">FrostFS</a>
|
Low-level Golang API for <a href="https://frostfs.info">FrostFS</a>
|
||||||
|
|
BIN
accounting/grpc/service_frostfs.pb.go
generated
BIN
accounting/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
accounting/grpc/service_grpc.pb.go
generated
BIN
accounting/grpc/service_grpc.pb.go
generated
Binary file not shown.
BIN
accounting/grpc/types_frostfs.pb.go
generated
BIN
accounting/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
acl/grpc/types_frostfs.pb.go
generated
BIN
acl/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
ape/grpc/types_frostfs.pb.go
generated
BIN
ape/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
apemanager/grpc/service_frostfs.pb.go
generated
BIN
apemanager/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
container/grpc/service_frostfs.pb.go
generated
BIN
container/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
container/grpc/types_frostfs.pb.go
generated
BIN
container/grpc/types_frostfs.pb.go
generated
Binary file not shown.
|
@ -35,11 +35,11 @@ Tag a release (must be signed) and push it:
|
||||||
$ git tag -s vX.Y.Z[-rc.N] && git push origin vX.Y.Z[-rc.N]
|
$ git tag -s vX.Y.Z[-rc.N] && git push origin vX.Y.Z[-rc.N]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Make a proper release
|
## Make a Github release
|
||||||
|
|
||||||
Using git.frostfs.info web interface create a new release based on just created tag
|
Using Github's web interface create a new release based on just created tag
|
||||||
with the same changes from changelog and publish it.
|
with the same changes from changelog and publish it.
|
||||||
|
|
||||||
## Close milestone
|
## Close github milestone
|
||||||
|
|
||||||
Close corresponding vX.Y.Z milestone.
|
Close corresponding vX.Y.Z github milestone.
|
||||||
|
|
BIN
lock/grpc/types_frostfs.pb.go
generated
BIN
lock/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
netmap/grpc/service_frostfs.pb.go
generated
BIN
netmap/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
netmap/grpc/service_grpc.pb.go
generated
BIN
netmap/grpc/service_grpc.pb.go
generated
Binary file not shown.
BIN
netmap/grpc/types_frostfs.pb.go
generated
BIN
netmap/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
object/grpc/service_frostfs.pb.go
generated
BIN
object/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
object/grpc/service_grpc.pb.go
generated
BIN
object/grpc/service_grpc.pb.go
generated
Binary file not shown.
BIN
object/grpc/types_frostfs.pb.go
generated
BIN
object/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
refs/grpc/types_frostfs.pb.go
generated
BIN
refs/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
session/grpc/service_frostfs.pb.go
generated
BIN
session/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
session/grpc/types_frostfs.pb.go
generated
BIN
session/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
status/grpc/types_frostfs.pb.go
generated
BIN
status/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
tombstone/grpc/types_frostfs.pb.go
generated
BIN
tombstone/grpc/types_frostfs.pb.go
generated
Binary file not shown.
|
@ -26,34 +26,11 @@ func nonZero[T protoInt]() T {
|
||||||
|
|
||||||
func TestStableMarshalSingle(t *testing.T) {
|
func TestStableMarshalSingle(t *testing.T) {
|
||||||
t.Run("empty", func(t *testing.T) {
|
t.Run("empty", func(t *testing.T) {
|
||||||
t.Run("proto", func(t *testing.T) {
|
input := &generated.Primitives{}
|
||||||
input := &generated.Primitives{}
|
require.Zero(t, input.StableSize())
|
||||||
require.Zero(t, input.StableSize())
|
|
||||||
|
|
||||||
r := input.MarshalProtobuf(nil)
|
r := input.MarshalProtobuf(nil)
|
||||||
require.Empty(t, r)
|
require.Empty(t, r)
|
||||||
})
|
|
||||||
t.Run("json", func(t *testing.T) {
|
|
||||||
input := &generated.Primitives{}
|
|
||||||
r, err := input.MarshalJSON()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.NotEmpty(t, r)
|
|
||||||
|
|
||||||
var actual test.Primitives
|
|
||||||
require.NoError(t, protojson.Unmarshal(r, &actual))
|
|
||||||
|
|
||||||
t.Run("protojson compatibility", func(t *testing.T) {
|
|
||||||
data, err := protojson.MarshalOptions{EmitUnpopulated: true}.Marshal(&actual)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.JSONEq(t, string(data), string(r))
|
|
||||||
})
|
|
||||||
|
|
||||||
var actualFrostfs generated.Primitives
|
|
||||||
require.NoError(t, actualFrostfs.UnmarshalJSON(r))
|
|
||||||
require.Equal(t, input, &actualFrostfs)
|
|
||||||
|
|
||||||
primitivesEqual(t, input, &actual)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
marshalCases := []struct {
|
marshalCases := []struct {
|
||||||
|
@ -99,12 +76,6 @@ func TestStableMarshalSingle(t *testing.T) {
|
||||||
var actual test.Primitives
|
var actual test.Primitives
|
||||||
require.NoError(t, protojson.Unmarshal(r, &actual))
|
require.NoError(t, protojson.Unmarshal(r, &actual))
|
||||||
|
|
||||||
t.Run("protojson compatibility", func(t *testing.T) {
|
|
||||||
data, err := protojson.MarshalOptions{EmitUnpopulated: true}.Marshal(&actual)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.JSONEq(t, string(data), string(r))
|
|
||||||
})
|
|
||||||
|
|
||||||
var actualFrostfs generated.Primitives
|
var actualFrostfs generated.Primitives
|
||||||
require.NoError(t, actualFrostfs.UnmarshalJSON(r))
|
require.NoError(t, actualFrostfs.UnmarshalJSON(r))
|
||||||
require.Equal(t, tc.input, &actualFrostfs)
|
require.Equal(t, tc.input, &actualFrostfs)
|
||||||
|
@ -117,7 +88,6 @@ func TestStableMarshalSingle(t *testing.T) {
|
||||||
|
|
||||||
func primitivesEqual(t *testing.T, a *generated.Primitives, b *test.Primitives) {
|
func primitivesEqual(t *testing.T, a *generated.Primitives, b *test.Primitives) {
|
||||||
// Compare each field directly, because proto-generated code has private fields.
|
// Compare each field directly, because proto-generated code has private fields.
|
||||||
require.Equal(t, len(a.FieldA), len(b.FieldA))
|
|
||||||
require.Equal(t, a.FieldA, b.FieldA)
|
require.Equal(t, a.FieldA, b.FieldA)
|
||||||
require.Equal(t, a.FieldB, b.FieldB)
|
require.Equal(t, a.FieldB, b.FieldB)
|
||||||
require.Equal(t, a.FieldC, b.FieldC)
|
require.Equal(t, a.FieldC, b.FieldC)
|
||||||
|
|
BIN
util/proto/test/custom/test_frostfs.pb.go
generated
BIN
util/proto/test/custom/test_frostfs.pb.go
generated
Binary file not shown.
|
@ -59,35 +59,6 @@ func emitJSONUnmarshal(g *protogen.GeneratedFile, msg *protogen.Message) {
|
||||||
g.P("}")
|
g.P("}")
|
||||||
}
|
}
|
||||||
|
|
||||||
func emitJSONParseInteger(g *protogen.GeneratedFile, ident string, method string, bitSize int, typ string) {
|
|
||||||
g.P("r := in.JsonNumber()")
|
|
||||||
g.P("n := r.String()")
|
|
||||||
g.P("v, err := ", strconvPackage.Ident(method), "(n, 10, ", bitSize, ")")
|
|
||||||
g.P("if err != nil {")
|
|
||||||
g.P(" in.AddError(err)")
|
|
||||||
g.P(" return")
|
|
||||||
g.P("}")
|
|
||||||
g.P(ident, " := ", typ, "(v)")
|
|
||||||
}
|
|
||||||
|
|
||||||
func emitJSONReadEnum(g *protogen.GeneratedFile, name string, enumType string) {
|
|
||||||
g.P(`switch v := in.Interface().(type) {
|
|
||||||
case string:
|
|
||||||
if vv, ok := `+enumType+`_value[v]; ok {
|
|
||||||
`+name+` = `+enumType+`(vv)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
vv, err := `, strconvPackage.Ident("ParseInt"), `(v, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
in.AddError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
`+name+` = `+enumType+`(vv)
|
|
||||||
case float64:
|
|
||||||
`+name+` = `+enumType+`(v)
|
|
||||||
}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string) {
|
func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string) {
|
||||||
g.P("{")
|
g.P("{")
|
||||||
defer g.P("}")
|
defer g.P("}")
|
||||||
|
@ -112,20 +83,30 @@ func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string
|
||||||
|
|
||||||
enumType := fieldType(g, f).String()
|
enumType := fieldType(g, f).String()
|
||||||
g.P("var parsedValue " + enumType)
|
g.P("var parsedValue " + enumType)
|
||||||
emitJSONReadEnum(g, "parsedValue", enumType)
|
g.P(`switch v := in.Interface().(type) {
|
||||||
|
case string:
|
||||||
|
if vv, ok := `+enumType+`_value[v]; ok {
|
||||||
|
parsedValue = `+enumType+`(vv)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
vv, err := `, strconvPackage.Ident("ParseInt"), `(v, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
in.AddError(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
parsedValue = `+enumType+`(vv)
|
||||||
|
case float64:
|
||||||
|
parsedValue = `+enumType+`(v)
|
||||||
|
}`)
|
||||||
template = "%s = parsedValue"
|
template = "%s = parsedValue"
|
||||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
||||||
emitJSONParseInteger(g, "pv", "ParseInt", 32, "int32")
|
template = "%s = in.Int32()"
|
||||||
template = "%s = pv"
|
|
||||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
||||||
emitJSONParseInteger(g, "pv", "ParseUint", 32, "uint32")
|
template = "%s = in.Uint32()"
|
||||||
template = "%s = pv"
|
|
||||||
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
||||||
emitJSONParseInteger(g, "pv", "ParseInt", 64, "int64")
|
template = "%s = in.Int64()"
|
||||||
template = "%s = pv"
|
|
||||||
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
||||||
emitJSONParseInteger(g, "pv", "ParseUint", 64, "uint64")
|
template = "%s = in.Uint64()"
|
||||||
template = "%s = pv"
|
|
||||||
case protoreflect.FloatKind:
|
case protoreflect.FloatKind:
|
||||||
template = "%s = in.Float32()"
|
template = "%s = in.Float32()"
|
||||||
case protoreflect.DoubleKind:
|
case protoreflect.DoubleKind:
|
||||||
|
@ -133,17 +114,7 @@ func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string
|
||||||
case protoreflect.StringKind:
|
case protoreflect.StringKind:
|
||||||
template = "%s = in.String()"
|
template = "%s = in.String()"
|
||||||
case protoreflect.BytesKind:
|
case protoreflect.BytesKind:
|
||||||
// Since some time ago proto3 support optional keyword, thus the presence is not tracked by default:
|
template = "%s = in.Bytes()"
|
||||||
// https://github.com/protocolbuffers/protobuf-go/blob/fb995f184a1719ec42b247a3771d1036d92adf67/internal/impl/message_reflect_field.go#L327
|
|
||||||
// We do not explicitly support `optional` keyword, protoc will fail on such fileds.
|
|
||||||
// Thus, treat empty string as `[]byte(nil)`.
|
|
||||||
template = `{
|
|
||||||
tmp := in.Bytes()
|
|
||||||
if len(tmp) == 0 {
|
|
||||||
tmp = nil
|
|
||||||
}
|
|
||||||
%s = tmp
|
|
||||||
}`
|
|
||||||
case protoreflect.MessageKind:
|
case protoreflect.MessageKind:
|
||||||
if f.Desc.IsList() {
|
if f.Desc.IsList() {
|
||||||
g.P("f = ", fieldType(g, f)[2:], "{}")
|
g.P("f = ", fieldType(g, f)[2:], "{}")
|
||||||
|
@ -176,11 +147,8 @@ func emitJSONMarshal(g *protogen.GeneratedFile, msg *protogen.Message) {
|
||||||
g.P("func (x *", msg.GoIdent.GoName, ") MarshalEasyJSON(out *", jwriterPackage.Ident("Writer"), ") {")
|
g.P("func (x *", msg.GoIdent.GoName, ") MarshalEasyJSON(out *", jwriterPackage.Ident("Writer"), ") {")
|
||||||
g.P(`if x == nil { out.RawString("null"); return }`)
|
g.P(`if x == nil { out.RawString("null"); return }`)
|
||||||
|
|
||||||
if len(msg.Fields) != 0 {
|
|
||||||
g.P("first := true")
|
|
||||||
}
|
|
||||||
g.P("out.RawByte('{')")
|
g.P("out.RawByte('{')")
|
||||||
for _, f := range msg.Fields {
|
for i, f := range msg.Fields {
|
||||||
if f.Oneof != nil {
|
if f.Oneof != nil {
|
||||||
if f.Oneof.Fields[0] != f {
|
if f.Oneof.Fields[0] != f {
|
||||||
continue
|
continue
|
||||||
|
@ -189,38 +157,29 @@ func emitJSONMarshal(g *protogen.GeneratedFile, msg *protogen.Message) {
|
||||||
g.P("switch xx := x.", f.Oneof.GoName, ".(type) {")
|
g.P("switch xx := x.", f.Oneof.GoName, ".(type) {")
|
||||||
for _, ff := range f.Oneof.Fields {
|
for _, ff := range f.Oneof.Fields {
|
||||||
g.P("case *", ff.GoIdent, ":")
|
g.P("case *", ff.GoIdent, ":")
|
||||||
emitJSONFieldWrite(g, ff, "xx")
|
emitJSONFieldWrite(g, ff, "xx", i == 0)
|
||||||
}
|
}
|
||||||
g.P("}")
|
g.P("}")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
emitJSONFieldWrite(g, f, "x")
|
emitJSONFieldWrite(g, f, "x", i == 0)
|
||||||
}
|
}
|
||||||
g.P("out.RawByte('}')")
|
g.P("out.RawByte('}')")
|
||||||
g.P("}")
|
g.P("}")
|
||||||
}
|
}
|
||||||
|
|
||||||
func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name string) {
|
func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name string, first bool) {
|
||||||
g.P("{")
|
g.P("{")
|
||||||
defer g.P("}")
|
defer g.P("}")
|
||||||
|
|
||||||
|
g.P("const prefix string = ", `",\"`, fieldJSONName(f), `\":"`)
|
||||||
|
if first {
|
||||||
|
g.P("out.RawString(prefix[1:])")
|
||||||
|
} else {
|
||||||
|
g.P("out.RawString(prefix)")
|
||||||
|
}
|
||||||
|
|
||||||
selector := name + "." + f.GoName
|
selector := name + "." + f.GoName
|
||||||
|
|
||||||
// This code is responsible for ignoring default values.
|
|
||||||
// We will restore it after having parametrized JSON marshaling.
|
|
||||||
//
|
|
||||||
// isNotDefault := notNil
|
|
||||||
// if f.Desc.IsList() {
|
|
||||||
// isNotDefault = notEmpty
|
|
||||||
// } else if f.Desc.Kind() != protoreflect.MessageKind {
|
|
||||||
// _, isNotDefault = easyprotoKindInfo(f.Desc.Kind())
|
|
||||||
// }
|
|
||||||
// g.P("if ", isNotDefault(selector), "{")
|
|
||||||
// defer g.P("}")
|
|
||||||
|
|
||||||
g.P("if !first { out.RawByte(','); } else { first = false; }")
|
|
||||||
g.P("const prefix string = ", `"\"`, fieldJSONName(f), `\":"`)
|
|
||||||
g.P("out.RawString(prefix)")
|
|
||||||
if f.Desc.IsList() {
|
if f.Desc.IsList() {
|
||||||
selector += "[i]"
|
selector += "[i]"
|
||||||
g.P("out.RawByte('[')")
|
g.P("out.RawByte('[')")
|
||||||
|
@ -236,27 +195,15 @@ func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name strin
|
||||||
case protoreflect.BoolKind:
|
case protoreflect.BoolKind:
|
||||||
template = "out.Bool(%s)"
|
template = "out.Bool(%s)"
|
||||||
case protoreflect.EnumKind:
|
case protoreflect.EnumKind:
|
||||||
enumType := fieldType(g, f).String()
|
template = "out.Int32(int32(%s))"
|
||||||
template = `v := int32(%s)
|
|
||||||
if vv, ok := ` + enumType + `_name[v]; ok {
|
|
||||||
out.String(vv)
|
|
||||||
} else {
|
|
||||||
out.Int32(v)
|
|
||||||
}`
|
|
||||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
||||||
template = "out.Int32(%s)"
|
template = "out.Int32(%s)"
|
||||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
||||||
template = "out.Uint32(%s)"
|
template = "out.Uint32(%s)"
|
||||||
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
||||||
g.P("out.RawByte('\"')")
|
template = "out.Int64(%s)"
|
||||||
g.P("out.Buffer.Buf = ", strconvPackage.Ident("AppendInt"), "(out.Buffer.Buf, ", selector, ", 10)")
|
|
||||||
g.P("out.RawByte('\"')")
|
|
||||||
return
|
|
||||||
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
||||||
g.P("out.RawByte('\"')")
|
template = "out.Uint64(%s)"
|
||||||
g.P("out.Buffer.Buf = ", strconvPackage.Ident("AppendUint"), "(out.Buffer.Buf, ", selector, ", 10)")
|
|
||||||
g.P("out.RawByte('\"')")
|
|
||||||
return
|
|
||||||
case protoreflect.FloatKind:
|
case protoreflect.FloatKind:
|
||||||
template = "out.Float32(%s)"
|
template = "out.Float32(%s)"
|
||||||
case protoreflect.DoubleKind:
|
case protoreflect.DoubleKind:
|
||||||
|
@ -264,10 +211,7 @@ func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name strin
|
||||||
case protoreflect.StringKind:
|
case protoreflect.StringKind:
|
||||||
template = "out.String(%s)"
|
template = "out.String(%s)"
|
||||||
case protoreflect.BytesKind:
|
case protoreflect.BytesKind:
|
||||||
g.P("if ", selector, "!= nil {")
|
template = "out.Base64Bytes(%s)"
|
||||||
g.P("out.Base64Bytes(", selector, ")")
|
|
||||||
g.P("} else { out.String(\"\") }")
|
|
||||||
return
|
|
||||||
case protoreflect.MessageKind:
|
case protoreflect.MessageKind:
|
||||||
template = "%s.MarshalEasyJSON(out)"
|
template = "%s.MarshalEasyJSON(out)"
|
||||||
case protoreflect.GroupKind:
|
case protoreflect.GroupKind:
|
||||||
|
|
Loading…
Reference in a new issue