Update reflection_helpers.go

This commit is contained in:
topianet 2023-12-23 02:09:59 +01:00 committed by GitHub
parent 60c1e2ab0f
commit ce05a503f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,12 +4,12 @@ import (
"reflect"
"unicode"
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/protowire"
"github.com/fabbez/topiad/infrastructure/network/netadapter/server/grpcserver/protowire"
)
// protobuf generates the command types with two types:
// 1. A concrete type that holds the fields of the command bearing the name of the command with `RequestMessage` as suffix
// 2. A wrapper that implements isKaspadMessage_Payload, having a single field pointing to the concrete command
// 2. A wrapper that implements istopiadMessage_Payload, having a single field pointing to the concrete command
// bearing the name of the command with `KaspadMessage_` prefix and `Request` suffix
// unwrapCommandType converts a reflect.Type signifying a wrapper type into the concrete request type
@ -28,14 +28,14 @@ func isFieldExported(field reflect.StructField) bool {
return unicode.IsUpper(rune(field.Name[0]))
}
// generateKaspadMessage generates a wrapped KaspadMessage with the given `commandValue`
func generateKaspadMessage(commandValue reflect.Value, commandDesc *commandDescription) (*protowire.KaspadMessage, error) {
// generatetopiaddMessage generates a wrapped topiadMessage with the given `commandValue`
func generatetopiadMessage(commandValue reflect.Value, commandDesc *commandDescription) (*protowire.topiadMessage, error) {
commandWrapper := reflect.New(commandDesc.typeof)
unwrapCommandValue(commandWrapper).Set(commandValue)
kaspadMessage := reflect.New(reflect.TypeOf(protowire.KaspadMessage{}))
kaspadMessage.Elem().FieldByName("Payload").Set(commandWrapper)
return kaspadMessage.Interface().(*protowire.KaspadMessage), nil
topiadMessage := reflect.New(reflect.TypeOf(protowire.topiadMessage{}))
topiadMessage.Elem().FieldByName("Payload").Set(commandWrapper)
return topiadMessage.Interface().(*protowire.topiadMessage), nil
}
// pointerToValue returns a reflect.Value that represents a pointer to the given value