mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
move protofilter to common
This commit is contained in:
parent
08b841aee1
commit
e645e68c83
@ -1,6 +1,7 @@
|
|||||||
package protofilter
|
package protofilter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"github.com/v2fly/v2ray-core/v4/common/platform/filesystem"
|
"github.com/v2fly/v2ray-core/v4/common/platform/filesystem"
|
||||||
"github.com/v2fly/v2ray-core/v4/common/protoext"
|
"github.com/v2fly/v2ray-core/v4/common/protoext"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
@ -9,12 +10,12 @@ import (
|
|||||||
|
|
||||||
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
|
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
|
||||||
|
|
||||||
func FilterProtoConfig(config proto.Message) error {
|
func FilterProtoConfig(ctx context.Context, config proto.Message) error {
|
||||||
messageProtoReflect := config.ProtoReflect()
|
messageProtoReflect := config.ProtoReflect()
|
||||||
return filterMessage(messageProtoReflect)
|
return filterMessage(ctx, messageProtoReflect)
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterMessage(message protoreflect.Message) error {
|
func filterMessage(ctx context.Context, message protoreflect.Message) error {
|
||||||
var err error
|
var err error
|
||||||
type fileRead struct {
|
type fileRead struct {
|
||||||
filename string
|
filename string
|
||||||
@ -42,14 +43,14 @@ func filterMessage(message protoreflect.Message) error {
|
|||||||
switch descriptor.Kind() {
|
switch descriptor.Kind() {
|
||||||
case protoreflect.MessageKind:
|
case protoreflect.MessageKind:
|
||||||
if descriptor.IsMap() {
|
if descriptor.IsMap() {
|
||||||
err = filterMap(value.Map())
|
err = filterMap(ctx, value.Map())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if descriptor.IsList() {
|
if descriptor.IsList() {
|
||||||
err = filterList(value.List())
|
err = filterList(ctx, value.List())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
err = filterMessage(value.Message())
|
err = filterMessage(ctx, value.Message())
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@ -65,10 +66,10 @@ func filterMessage(message protoreflect.Message) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterMap(mapValue protoreflect.Map) error {
|
func filterMap(ctx context.Context, mapValue protoreflect.Map) error {
|
||||||
var err error
|
var err error
|
||||||
mapValue.Range(func(key protoreflect.MapKey, value protoreflect.Value) bool {
|
mapValue.Range(func(key protoreflect.MapKey, value protoreflect.Value) bool {
|
||||||
err = filterMessage(value.Message())
|
err = filterMessage(ctx, value.Message())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -77,11 +78,11 @@ func filterMap(mapValue protoreflect.Map) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterList(listValue protoreflect.List) error {
|
func filterList(ctx context.Context, listValue protoreflect.List) error {
|
||||||
var err error
|
var err error
|
||||||
size := listValue.Len()
|
size := listValue.Len()
|
||||||
for i := 0; i < size; i++ {
|
for i := 0; i < size; i++ {
|
||||||
err = filterMessage(listValue.Get(i).Message())
|
err = filterMessage(ctx, listValue.Get(i).Message())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user