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:
parent
229b30d877
commit
6a242d1e2e
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user