1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

feat: add jsonpb marshallers (#3165)

This commit is contained in:
Kasefuchs 2024-10-12 21:26:59 +03:00 committed by GitHub
parent 229b30d877
commit 6a242d1e2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 0 deletions

View File

@ -221,3 +221,9 @@ func (d *IPOrDomain) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, bytes []by
d.Address = result.Address
return nil
}
func (d *IPOrDomain) MarshalJSONPB(marshaler *jsonpb.Marshaler) ([]byte, error) {
ipod := d.AsAddress().String()
return json.Marshal(ipod)
}

View File

@ -37,6 +37,16 @@ func (nl *NetworkList) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, bytes []
return newError("unknown format of a string list: " + string(bytes))
}
func (nl *NetworkList) MarshalJSONPB(marshaler *jsonpb.Marshaler) ([]byte, error) {
networkStrList := make([]string, len(nl.Network))
for idx, network := range nl.Network {
networkStrList[idx] = network.String()
}
return json.Marshal(networkStrList)
}
// HasNetwork returns true if the network list has a certain network.
func HasNetwork(list []Network, network Network) bool {
for _, value := range list {

View File

@ -26,6 +26,12 @@ func (c *CipherTypeWrapper) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, byt
return nil
}
func (c *CipherTypeWrapper) MarshalJSONPB(marshaler *jsonpb.Marshaler) ([]byte, error) {
method := c.Value.String()
return json.Marshal(method)
}
func init() {
common.Must(common.RegisterConfig((*ServerConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
simplifiedServer := config.(*ServerConfig)