mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-27 15:53:57 +00:00
Update reflection_helpers.go
This commit is contained in:
parent
60c1e2ab0f
commit
ce05a503f8
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user