Selaa lähdekoodia

protobuf for network list

Darien Raymond 9 vuotta sitten
vanhempi
commit
88ae8248a5

+ 1 - 0
common/net/address.pb.go

@@ -14,6 +14,7 @@ It is generated from these files:
 It has these top-level messages:
 It has these top-level messages:
 	AddressPB
 	AddressPB
 	DestinationPB
 	DestinationPB
+	NetworkList
 	PortRange
 	PortRange
 */
 */
 package net
 package net

+ 9 - 9
common/net/network.go

@@ -25,8 +25,9 @@ func ParseNetwork(nwStr string) Network {
 }
 }
 
 
 func (this Network) AsList() *NetworkList {
 func (this Network) AsList() *NetworkList {
-	list := NetworkList([]Network{this})
-	return &list
+	return &NetworkList{
+		Network: []Network{this},
+	}
 }
 }
 
 
 func (this Network) SystemString() string {
 func (this Network) SystemString() string {
@@ -55,21 +56,20 @@ func (this Network) UrlPrefix() string {
 	}
 	}
 }
 }
 
 
-// NetworkList is a list of Networks.
-type NetworkList []Network
-
 // NewNetworkList construsts a NetWorklist from the given StringListeralList.
 // NewNetworkList construsts a NetWorklist from the given StringListeralList.
-func NewNetworkList(networks collect.StringList) NetworkList {
-	list := NetworkList(make([]Network, networks.Len()))
+func NewNetworkList(networks collect.StringList) *NetworkList {
+	list := &NetworkList{
+		Network: make([]Network, networks.Len()),
+	}
 	for idx, network := range networks {
 	for idx, network := range networks {
-		list[idx] = ParseNetwork(network)
+		list.Network[idx] = ParseNetwork(network)
 	}
 	}
 	return list
 	return list
 }
 }
 
 
 // HashNetwork returns true if the given network is in this NetworkList.
 // HashNetwork returns true if the given network is in this NetworkList.
 func (this *NetworkList) HasNetwork(network Network) bool {
 func (this *NetworkList) HasNetwork(network Network) bool {
-	for _, value := range *this {
+	for _, value := range this.Network {
 		if string(value) == string(network) {
 		if string(value) == string(network) {
 			return true
 			return true
 		}
 		}

+ 19 - 7
common/net/network.pb.go

@@ -46,22 +46,34 @@ func (x Network) String() string {
 }
 }
 func (Network) EnumDescriptor() ([]byte, []int) { return fileDescriptor2, []int{0} }
 func (Network) EnumDescriptor() ([]byte, []int) { return fileDescriptor2, []int{0} }
 
 
+type NetworkList struct {
+	Network []Network `protobuf:"varint,1,rep,packed,name=network,enum=com.v2ray.core.common.net.Network" json:"network,omitempty"`
+}
+
+func (m *NetworkList) Reset()                    { *m = NetworkList{} }
+func (m *NetworkList) String() string            { return proto.CompactTextString(m) }
+func (*NetworkList) ProtoMessage()               {}
+func (*NetworkList) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{0} }
+
 func init() {
 func init() {
+	proto.RegisterType((*NetworkList)(nil), "com.v2ray.core.common.net.NetworkList")
 	proto.RegisterEnum("com.v2ray.core.common.net.Network", Network_name, Network_value)
 	proto.RegisterEnum("com.v2ray.core.common.net.Network", Network_name, Network_value)
 }
 }
 
 
 func init() { proto.RegisterFile("v2ray.com/core/common/net/network.proto", fileDescriptor2) }
 func init() { proto.RegisterFile("v2ray.com/core/common/net/network.proto", fileDescriptor2) }
 
 
 var fileDescriptor2 = []byte{
 var fileDescriptor2 = []byte{
-	// 159 bytes of a gzipped FileDescriptorProto
+	// 192 bytes of a gzipped FileDescriptorProto
 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x33, 0x2a, 0x4a,
 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x33, 0x2a, 0x4a,
 	0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xcf, 0xcd, 0xcd,
 	0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xcf, 0xcd, 0xcd,
 	0xcf, 0xd3, 0xcf, 0x4b, 0x2d, 0x01, 0xe1, 0xf2, 0xfc, 0xa2, 0x6c, 0xbd, 0x82, 0xa2, 0xfc, 0x92,
 	0xcf, 0xd3, 0xcf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xa1, 0x62, 0x42, 0xdc, 0x5c, 0xec, 0xa1, 0x79,
+	0xd9, 0x79, 0xf9, 0xe5, 0x79, 0x02, 0x0c, 0x42, 0x5c, 0x5c, 0x6c, 0x41, 0x89, 0xe5, 0x21, 0xce,
+	0x01, 0x02, 0x8c, 0x42, 0xec, 0x5c, 0xcc, 0x20, 0x06, 0x13, 0x88, 0x11, 0xea, 0x12, 0x20, 0xc0,
+	0x0c, 0x62, 0x78, 0x3b, 0x07, 0x08, 0xb0, 0x08, 0xf1, 0x72, 0x71, 0x86, 0xa7, 0x26, 0x05, 0xe7,
+	0x27, 0x67, 0xa7, 0x96, 0x08, 0xb0, 0x3a, 0xb1, 0x46, 0x31, 0xe7, 0xa5, 0x96, 0x24, 0xb1, 0x81,
+	0xfd, 0x60, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x8e, 0x1a, 0x8a, 0xb3, 0xee, 0x00, 0x00, 0x00,
 }
 }

+ 4 - 0
common/net/network.proto

@@ -10,4 +10,8 @@ enum Network {
   UDP = 3;
   UDP = 3;
   KCP = 4;
   KCP = 4;
   WebSocket = 5;
   WebSocket = 5;
+}
+
+message NetworkList {
+  repeated Network network = 1;
 }
 }

+ 1 - 1
common/net/network_json.go

@@ -13,6 +13,6 @@ func (this *NetworkList) UnmarshalJSON(data []byte) error {
 	if err := json.Unmarshal(data, &strlist); err != nil {
 	if err := json.Unmarshal(data, &strlist); err != nil {
 		return err
 		return err
 	}
 	}
-	*this = NewNetworkList(strlist)
+	*this = *NewNetworkList(strlist)
 	return nil
 	return nil
 }
 }