Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored to use one proto file #60

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions client/client-1.0/compress_client/compress_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ func performCommand(commandNumber int, conn *websocket.Conn, optionChannel chan
}

func performPbCommand(commandNumber int, conn *websocket.Conn, optionChannel chan string) {
compressedRequest := utils.JsonToProtobuf(requestList.Request[commandNumber], convertToCompression(compression))
compressedRequest := utils.JsonToProtobuf(requestList.Request[commandNumber])
fmt.Printf("JSON request size= %d, Protobuf request size=%d\n", len(requestList.Request[commandNumber]), len(compressedRequest))
fmt.Printf("Compression= %d%\n", (100*len(requestList.Request[commandNumber]))/len(compressedRequest))
compressedResponse := getResponse(conn, compressedRequest)
jsonResponse := utils.ProtobufToJson(compressedResponse, convertToCompression(compression))
jsonResponse := utils.ProtobufToJson(compressedResponse)
fmt.Printf("Response: %s\n", jsonResponse)
fmt.Printf("JSON response size= %d, Protobuf response size=%d\n", len(jsonResponse), len(compressedResponse))
fmt.Printf("Compression= %d%\n", (100*len(jsonResponse))/len(compressedResponse))
Expand All @@ -161,7 +161,7 @@ func performPbCommand(commandNumber int, conn *websocket.Conn, optionChannel cha
fmt.Printf("Notification error: %s\n", err)
return
}
jsonNotification := utils.ProtobufToJson(msg, convertToCompression(compression))
jsonNotification := utils.ProtobufToJson(msg)
fmt.Printf("Notification: %s\n", jsonNotification)
fmt.Printf("JSON notification size= %d, Protobuf notification size=%d\n", len(jsonNotification), len(msg))
fmt.Printf("Compression= %d%\n", (100*len(jsonNotification))/len(msg))
Expand All @@ -170,7 +170,7 @@ func performPbCommand(commandNumber int, conn *websocket.Conn, optionChannel cha
// issue unsubscribe request
subscriptionId := utils.ExtractSubscriptionId(jsonResponse)
unsubReq := `{"action":"unsubscribe", "subscriptionId":"` + subscriptionId + `"}`
pbUnsubReq := utils.JsonToProtobuf(unsubReq, convertToCompression(compression))
pbUnsubReq := utils.JsonToProtobuf(unsubReq)
getResponse(conn, pbUnsubReq)
return
default:
Expand All @@ -179,14 +179,6 @@ func performPbCommand(commandNumber int, conn *websocket.Conn, optionChannel cha
}
}

func convertToCompression(encoding string) utils.Encoding {
switch encoding {
case "proto":
return utils.PROTOBUF
}
return utils.NONE
}

func displayOptions() {
fmt.Printf("\n\nSelect one of the following numbers:\n")
fmt.Printf("0: Exit program\n")
Expand Down
16 changes: 4 additions & 12 deletions client/client-1.0/csv_client/csv_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ func saveInCsv(valArray []string, tsArray []string, arrayIndex int) {
}

func performPbCommand(commandNumber int, conn *websocket.Conn, optionChannel chan string) {
compressedRequest := utils.JsonToProtobuf(requestList.Request[commandNumber], convertToCompression(compression))
compressedRequest := utils.JsonToProtobuf(requestList.Request[commandNumber])
fmt.Printf("JSON request size= %d, Protobuf request size=%d\n", len(requestList.Request[commandNumber]), len(compressedRequest))
fmt.Printf("Compression= %d%\n", (100*len(requestList.Request[commandNumber]))/len(compressedRequest))
compressedResponse := getResponse(conn, compressedRequest)
jsonResponse := utils.ProtobufToJson(compressedResponse, convertToCompression(compression))
jsonResponse := utils.ProtobufToJson(compressedResponse)
fmt.Printf("Response: %s\n", jsonResponse)
fmt.Printf("JSON response size= %d, Protobuf response size=%d\n", len(jsonResponse), len(compressedResponse))
fmt.Printf("Compression= %d%\n", (100*len(jsonResponse))/len(compressedResponse))
Expand All @@ -309,7 +309,7 @@ func performPbCommand(commandNumber int, conn *websocket.Conn, optionChannel cha
fmt.Printf("Notification error: %s\n", err)
return
}
jsonNotification := utils.ProtobufToJson(msg, convertToCompression(compression))
jsonNotification := utils.ProtobufToJson(msg)
fmt.Printf("Notification: %s\n", jsonNotification)
fmt.Printf("JSON notification size= %d, Protobuf notification size=%d\n", len(jsonNotification), len(msg))
fmt.Printf("Compression= %d%\n", (100*len(jsonNotification))/len(msg))
Expand All @@ -318,7 +318,7 @@ func performPbCommand(commandNumber int, conn *websocket.Conn, optionChannel cha
// issue unsubscribe request
subscriptionId := utils.ExtractSubscriptionId(jsonResponse)
unsubReq := `{"action":"unsubscribe", "subscriptionId":"` + subscriptionId + `"}`
pbUnsubReq := utils.JsonToProtobuf(unsubReq, convertToCompression(compression))
pbUnsubReq := utils.JsonToProtobuf(unsubReq)
getResponse(conn, pbUnsubReq)
return
default:
Expand All @@ -327,14 +327,6 @@ func performPbCommand(commandNumber int, conn *websocket.Conn, optionChannel cha
}
}

func convertToCompression(compression string) utils.Encoding {
switch compression {
case "proto":
return utils.PROTOBUF
}
return utils.NONE
}

func displayOptions() {
fmt.Printf("\n\nSelect one of the following numbers:\n")
fmt.Printf("0: Exit program\n")
Expand Down
23 changes: 10 additions & 13 deletions client/client-1.0/grpc_client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const (
name = "VISSv2-gRPC-client"
)

var grpcEncoding utils.Encoding

var commandList []string

func initCommandList() {
Expand Down Expand Up @@ -82,32 +80,32 @@ func noStreamCall(commandIndex int) {
return
}
defer conn.Close()
client := pb.NewVISSv2Client(conn)
client := pb.NewVISSClient(conn)

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
vssRequest := commandList[commandIndex%10]
var vssResponse string
switch commandIndex % 10 {
case 0: //get
pbRequest := utils.GetRequestJsonToPb(vssRequest, grpcEncoding)
pbRequest := utils.GetRequestJsonToPb(vssRequest)
pbResponse, err := client.GetRequest(ctx, pbRequest)
if err != nil {
log.Fatal(err)
return
}
vssResponse = utils.GetResponsePbToJson(pbResponse, grpcEncoding)
vssResponse = utils.GetResponsePbToJson(pbResponse)
case 1: // set
pbRequest := utils.SetRequestJsonToPb(vssRequest, grpcEncoding)
pbRequest := utils.SetRequestJsonToPb(vssRequest)
pbResponse, _ := client.SetRequest(ctx, pbRequest)
vssResponse = utils.SetResponsePbToJson(pbResponse, grpcEncoding)
vssResponse = utils.SetResponsePbToJson(pbResponse)
case 3: //unsubscribe
subIdIndex := strings.Index(vssRequest, "X")
vssRequest = vssRequest[:subIdIndex] + strconv.Itoa(commandIndex/10) + vssRequest[subIdIndex+1:]
fmt.Printf("Unsubscribe request=:%s\n", vssRequest)
pbRequest := utils.UnsubscribeRequestJsonToPb(vssRequest, grpcEncoding)
pbRequest := utils.UnsubscribeRequestJsonToPb(vssRequest)
pbResponse, _ := client.UnsubscribeRequest(ctx, pbRequest)
vssResponse = utils.UnsubscribeResponsePbToJson(pbResponse, grpcEncoding)
vssResponse = utils.UnsubscribeResponsePbToJson(pbResponse)
}
if err != nil {
fmt.Printf("Error when issuing request=:%s\n", vssRequest)
Expand Down Expand Up @@ -135,20 +133,20 @@ func streamCall(commandIndex int) {
return
}
defer conn.Close()
client := pb.NewVISSv2Client(conn)
client := pb.NewVISSClient(conn)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
vssRequest := commandList[commandIndex]
pbRequest := utils.SubscribeRequestJsonToPb(vssRequest, grpcEncoding)
pbRequest := utils.SubscribeRequestJsonToPb(vssRequest)
stream, err := client.SubscribeRequest(ctx, pbRequest)
for {
pbResponse, err := stream.Recv()
if err != nil {
fmt.Printf("Error=%v when issuing request=:%s", err, vssRequest)
break
}
vssResponse := utils.SubscribeStreamPbToJson(pbResponse, grpcEncoding)
vssResponse := utils.SubscribeStreamPbToJson(pbResponse)
fmt.Printf("Received response:%s\n", vssResponse)
}
}
Expand All @@ -171,7 +169,6 @@ func main() {
}

utils.InitLog("grpc_client-log.txt", "./logs", *logFile, *logLevel)
grpcEncoding = utils.PROTOBUF
readTransportSecConfig()
utils.Info.Printf("secConfig.TransportSec=%s", secConfig.TransportSec)
if secConfig.TransportSec == "yes" {
Expand Down
23 changes: 10 additions & 13 deletions client/client-1.0/grpc_client/grpc_map_client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const (
name = "VISSv2-gRPC-client"
)

var grpcCompression utils.Compression

var commandList []string

func initCommandList() {
Expand Down Expand Up @@ -77,28 +75,28 @@ func noStreamCall(commandIndex int) {
return
}
defer conn.Close()
client := pb.NewVISSv2Client(conn)
client := pb.NewVISSClient(conn)

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
vssRequest := commandList[commandIndex]
var vssResponse string
if commandIndex == 0 {
pbRequest := utils.GetRequestJsonToPb(vssRequest, grpcCompression)
pbRequest := utils.GetRequestJsonToPb(vssRequest)
pbResponse, err := client.GetRequest(ctx, pbRequest)
if err != nil {
log.Fatal(err)
return
}
vssResponse = utils.GetResponsePbToJson(pbResponse, grpcCompression)
vssResponse = utils.GetResponsePbToJson(pbResponse)
} else if commandIndex == 2 {
pbRequest := utils.UnsubscribeRequestJsonToPb(vssRequest, grpcCompression)
pbRequest := utils.UnsubscribeRequestJsonToPb(vssRequest)
pbResponse, _ := client.UnsubscribeRequest(ctx, pbRequest)
vssResponse = utils.UnsubscribeResponsePbToJson(pbResponse, grpcCompression)
vssResponse = utils.UnsubscribeResponsePbToJson(pbResponse)
} else {
pbRequest := utils.SetRequestJsonToPb(vssRequest, grpcCompression)
pbRequest := utils.SetRequestJsonToPb(vssRequest)
pbResponse, _ := client.SetRequest(ctx, pbRequest)
vssResponse = utils.SetResponsePbToJson(pbResponse, grpcCompression)
vssResponse = utils.SetResponsePbToJson(pbResponse)
}
if err != nil {
fmt.Printf("Error when issuing request=:%s", vssRequest)
Expand Down Expand Up @@ -126,16 +124,16 @@ func streamCall(commandIndex int) {
return
}
defer conn.Close()
client := pb.NewVISSv2Client(conn)
client := pb.NewVISSClient(conn)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
vssRequest := commandList[commandIndex]
pbRequest := utils.SubscribeRequestJsonToPb(vssRequest, grpcCompression)
pbRequest := utils.SubscribeRequestJsonToPb(vssRequest)
stream, err := client.SubscribeRequest(ctx, pbRequest)
for {
pbResponse, err := stream.Recv()
vssResponse := utils.SubscribeStreamPbToJson(pbResponse, grpcCompression)
vssResponse := utils.SubscribeStreamPbToJson(pbResponse)
if err != nil {
fmt.Printf("Error=%v when issuing request=:%s", err, vssRequest)
} else {
Expand Down Expand Up @@ -163,7 +161,6 @@ func main() {
}

utils.InitLog("grpc_client-log.txt", "./logs", *logFile, *logLevel)
grpcCompression = utils.PROTOBUF
readTransportSecConfig()
utils.Info.Printf("secConfig.TransportSec=%s", secConfig.TransportSec)
if secConfig.TransportSec == "yes" {
Expand Down
52 changes: 0 additions & 52 deletions go.modtmp

This file was deleted.

4 changes: 1 addition & 3 deletions grpc_pb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ The gRPC implementation is payload compatible with the Websocket and MQTT implem

The following command builds the VISSv3.proto file:

protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative VISSv3.proto


protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative VISSv3.0.proto
Loading