|
|
@ -26,26 +26,31 @@ func Hash(base string, name string) SerializedType {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type SerializedType uint64
|
|
|
|
type SerializedType uint64
|
|
|
|
|
|
|
|
|
|
|
|
func (t SerializedType) String() string {
|
|
|
|
func (t SerializedType) String() string {
|
|
|
|
return fmt.Sprintf("0x%x", uint64(t))
|
|
|
|
return fmt.Sprintf("0x%x", uint64(t))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type ExtType SerializedType
|
|
|
|
type ExtType SerializedType
|
|
|
|
|
|
|
|
|
|
|
|
func (t ExtType) String() string {
|
|
|
|
func (t ExtType) String() string {
|
|
|
|
return fmt.Sprintf("0x%x", uint64(t))
|
|
|
|
return fmt.Sprintf("0x%x", uint64(t))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type NodeType SerializedType
|
|
|
|
type NodeType SerializedType
|
|
|
|
|
|
|
|
|
|
|
|
func (t NodeType) String() string {
|
|
|
|
func (t NodeType) String() string {
|
|
|
|
return fmt.Sprintf("0x%x", uint64(t))
|
|
|
|
return fmt.Sprintf("0x%x", uint64(t))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type SignalType SerializedType
|
|
|
|
type SignalType SerializedType
|
|
|
|
|
|
|
|
|
|
|
|
func (t SignalType) String() string {
|
|
|
|
func (t SignalType) String() string {
|
|
|
|
return fmt.Sprintf("0x%x", uint64(t))
|
|
|
|
return fmt.Sprintf("0x%x", uint64(t))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type PolicyType SerializedType
|
|
|
|
type PolicyType SerializedType
|
|
|
|
|
|
|
|
|
|
|
|
func (t PolicyType) String() string {
|
|
|
|
func (t PolicyType) String() string {
|
|
|
|
return fmt.Sprintf("0x%x", uint64(t))
|
|
|
|
return fmt.Sprintf("0x%x", uint64(t))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -84,13 +89,14 @@ var (
|
|
|
|
StopSignalType = NewSignalType("STOP")
|
|
|
|
StopSignalType = NewSignalType("STOP")
|
|
|
|
CreateSignalType = NewSignalType("CREATE")
|
|
|
|
CreateSignalType = NewSignalType("CREATE")
|
|
|
|
StartSignalType = NewSignalType("START")
|
|
|
|
StartSignalType = NewSignalType("START")
|
|
|
|
ErrorSignalType = NewSignalType("ERROR")
|
|
|
|
|
|
|
|
StatusSignalType = NewSignalType("STATUS")
|
|
|
|
StatusSignalType = NewSignalType("STATUS")
|
|
|
|
LinkSignalType = NewSignalType("LINK")
|
|
|
|
LinkSignalType = NewSignalType("LINK")
|
|
|
|
LockSignalType = NewSignalType("LOCK")
|
|
|
|
LockSignalType = NewSignalType("LOCK")
|
|
|
|
ReadSignalType = NewSignalType("READ")
|
|
|
|
ReadSignalType = NewSignalType("READ")
|
|
|
|
ReadResultSignalType = NewSignalType("READ_RESULT")
|
|
|
|
|
|
|
|
ACLTimeoutSignalType = NewSignalType("ACL_TIMEOUT")
|
|
|
|
ACLTimeoutSignalType = NewSignalType("ACL_TIMEOUT")
|
|
|
|
|
|
|
|
ErrorSignalType = NewSignalType("ERROR")
|
|
|
|
|
|
|
|
SuccessSignalType = NewSignalType("SUCCESS")
|
|
|
|
|
|
|
|
ReadResultSignalType = NewSignalType("READ_RESULT")
|
|
|
|
|
|
|
|
|
|
|
|
MemberOfPolicyType = NewPolicyType("USER_OF")
|
|
|
|
MemberOfPolicyType = NewPolicyType("USER_OF")
|
|
|
|
RequirementOfPolicyType = NewPolicyType("REQUIEMENT_OF")
|
|
|
|
RequirementOfPolicyType = NewPolicyType("REQUIEMENT_OF")
|
|
|
@ -134,6 +140,9 @@ var (
|
|
|
|
PendingACLType = NewSerializedType("PENDING_ACL")
|
|
|
|
PendingACLType = NewSerializedType("PENDING_ACL")
|
|
|
|
PendingSignalType = NewSerializedType("PENDING_SIGNAL")
|
|
|
|
PendingSignalType = NewSerializedType("PENDING_SIGNAL")
|
|
|
|
TimeType = NewSerializedType("TIME")
|
|
|
|
TimeType = NewSerializedType("TIME")
|
|
|
|
|
|
|
|
ResultType = NewSerializedType("RESULT")
|
|
|
|
|
|
|
|
TreeType = NewSerializedType("TREE")
|
|
|
|
|
|
|
|
SerializedTypeSerialized = NewSerializedType("SERIALIZED_TYPE")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func SerializeArray(ctx *Context, ctx_type SerializedType, reflect_type reflect.Type, value *reflect.Value) (SerializedValue, error) {
|
|
|
|
func SerializeArray(ctx *Context, ctx_type SerializedType, reflect_type reflect.Type, value *reflect.Value) (SerializedValue, error) {
|
|
|
@ -164,7 +173,7 @@ func SerializeArray(ctx *Context, ctx_type SerializedType, reflect_type reflect.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func DeserializeArray[T any](ctx *Context)(func(ctx *Context, value SerializedValue)(reflect.Type,*reflect.Value,SerializedValue,error)){
|
|
|
|
func DeserializeArray[T any](ctx *Context) func(ctx *Context, value SerializedValue) (reflect.Type, *reflect.Value, SerializedValue, error) {
|
|
|
|
var zero T
|
|
|
|
var zero T
|
|
|
|
array_type := reflect.TypeOf(zero)
|
|
|
|
array_type := reflect.TypeOf(zero)
|
|
|
|
array_size := array_type.Len()
|
|
|
|
array_size := array_type.Len()
|
|
|
@ -198,7 +207,7 @@ func DeserializeArray[T any](ctx *Context)(func(ctx *Context, value SerializedVa
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func SerializeUintN(size int)(func(*Context,SerializedType,reflect.Type,*reflect.Value)(SerializedValue,error)){
|
|
|
|
func SerializeUintN(size int) func(*Context, SerializedType, reflect.Type, *reflect.Value) (SerializedValue, error) {
|
|
|
|
var fill_data func([]byte, uint64) = nil
|
|
|
|
var fill_data func([]byte, uint64) = nil
|
|
|
|
switch size {
|
|
|
|
switch size {
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
@ -233,7 +242,9 @@ func SerializeUintN(size int)(func(*Context,SerializedType,reflect.Type,*reflect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func DeserializeUintN[T interface{~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64}](size int)(func(ctx *Context, value SerializedValue)(reflect.Type,*reflect.Value,SerializedValue,error)){
|
|
|
|
func DeserializeUintN[T interface {
|
|
|
|
|
|
|
|
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
|
|
|
|
|
|
|
|
}](size int) func(ctx *Context, value SerializedValue) (reflect.Type, *reflect.Value, SerializedValue, error) {
|
|
|
|
var get_uint func([]byte) uint64
|
|
|
|
var get_uint func([]byte) uint64
|
|
|
|
switch size {
|
|
|
|
switch size {
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
@ -274,7 +285,7 @@ func DeserializeUintN[T interface{~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func SerializeIntN(size int)(func(ctx *Context, ctx_type SerializedType, reflect_type reflect.Type, value *reflect.Value)(SerializedValue,error)){
|
|
|
|
func SerializeIntN(size int) func(ctx *Context, ctx_type SerializedType, reflect_type reflect.Type, value *reflect.Value) (SerializedValue, error) {
|
|
|
|
var fill_data func([]byte, int64) = nil
|
|
|
|
var fill_data func([]byte, int64) = nil
|
|
|
|
switch size {
|
|
|
|
switch size {
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
@ -309,7 +320,9 @@ func SerializeIntN(size int)(func(ctx *Context, ctx_type SerializedType, reflect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func DeserializeIntN[T interface{~int | ~int8 | ~int16 | ~int32 | ~int64}](size int)(func(ctx *Context, value SerializedValue)(reflect.Type,*reflect.Value,SerializedValue,error)){
|
|
|
|
func DeserializeIntN[T interface {
|
|
|
|
|
|
|
|
~int | ~int8 | ~int16 | ~int32 | ~int64
|
|
|
|
|
|
|
|
}](size int) func(ctx *Context, value SerializedValue) (reflect.Type, *reflect.Value, SerializedValue, error) {
|
|
|
|
var get_int func([]byte) int64
|
|
|
|
var get_int func([]byte) int64
|
|
|
|
switch size {
|
|
|
|
switch size {
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
@ -373,7 +386,7 @@ var DeserializableType = reflect.TypeOf(&deserializable_zero).Elem()
|
|
|
|
func structInfo(ctx *Context, struct_type reflect.Type) StructInfo {
|
|
|
|
func structInfo(ctx *Context, struct_type reflect.Type) StructInfo {
|
|
|
|
field_order := []SerializedType{}
|
|
|
|
field_order := []SerializedType{}
|
|
|
|
field_map := map[SerializedType]FieldInfo{}
|
|
|
|
field_map := map[SerializedType]FieldInfo{}
|
|
|
|
for _, field := range(reflect.VisibleFields(struct_type)) {
|
|
|
|
for _, field := range reflect.VisibleFields(struct_type) {
|
|
|
|
gv_tag, tagged_gv := field.Tag.Lookup("gv")
|
|
|
|
gv_tag, tagged_gv := field.Tag.Lookup("gv")
|
|
|
|
if tagged_gv == false {
|
|
|
|
if tagged_gv == false {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -423,7 +436,7 @@ func structInfo(ctx *Context, struct_type reflect.Type)StructInfo{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func SerializeStruct(ctx *Context, struct_type reflect.Type)(func(*Context,SerializedType,reflect.Type,*reflect.Value)(SerializedValue,error)){
|
|
|
|
func SerializeStruct(ctx *Context, struct_type reflect.Type) func(*Context, SerializedType, reflect.Type, *reflect.Value) (SerializedValue, error) {
|
|
|
|
struct_info := structInfo(ctx, struct_type)
|
|
|
|
struct_info := structInfo(ctx, struct_type)
|
|
|
|
return func(ctx *Context, ctx_type SerializedType, reflect_type reflect.Type, value *reflect.Value) (SerializedValue, error) {
|
|
|
|
return func(ctx *Context, ctx_type SerializedType, reflect_type reflect.Type, value *reflect.Value) (SerializedValue, error) {
|
|
|
|
type_stack := []SerializedType{ctx_type}
|
|
|
|
type_stack := []SerializedType{ctx_type}
|
|
|
@ -432,7 +445,7 @@ func SerializeStruct(ctx *Context, struct_type reflect.Type)(func(*Context,Seria
|
|
|
|
data = nil
|
|
|
|
data = nil
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
data = make([]byte, 8)
|
|
|
|
data = make([]byte, 8)
|
|
|
|
for _, field_hash := range(struct_info.FieldOrder) {
|
|
|
|
for _, field_hash := range struct_info.FieldOrder {
|
|
|
|
field_hash_bytes := make([]byte, 8)
|
|
|
|
field_hash_bytes := make([]byte, 8)
|
|
|
|
binary.BigEndian.PutUint64(field_hash_bytes, uint64(field_hash))
|
|
|
|
binary.BigEndian.PutUint64(field_hash_bytes, uint64(field_hash))
|
|
|
|
field_info := struct_info.FieldMap[field_hash]
|
|
|
|
field_info := struct_info.FieldMap[field_hash]
|
|
|
@ -453,7 +466,7 @@ func SerializeStruct(ctx *Context, struct_type reflect.Type)(func(*Context,Seria
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func DeserializeStruct(ctx *Context, struct_type reflect.Type)(func(*Context,SerializedValue)(reflect.Type,*reflect.Value,SerializedValue,error)){
|
|
|
|
func DeserializeStruct(ctx *Context, struct_type reflect.Type) func(*Context, SerializedValue) (reflect.Type, *reflect.Value, SerializedValue, error) {
|
|
|
|
struct_info := structInfo(ctx, struct_type)
|
|
|
|
struct_info := structInfo(ctx, struct_type)
|
|
|
|
return func(ctx *Context, value SerializedValue) (reflect.Type, *reflect.Value, SerializedValue, error) {
|
|
|
|
return func(ctx *Context, value SerializedValue) (reflect.Type, *reflect.Value, SerializedValue, error) {
|
|
|
|
if value.Data == nil {
|
|
|
|
if value.Data == nil {
|
|
|
@ -537,7 +550,7 @@ func SerializeInterface(ctx *Context, ctx_type SerializedType, reflect_type refl
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func DeserializeInterface[T any]()(func(*Context,SerializedValue)(reflect.Type,*reflect.Value,SerializedValue,error)){
|
|
|
|
func DeserializeInterface[T any]() func(*Context, SerializedValue) (reflect.Type, *reflect.Value, SerializedValue, error) {
|
|
|
|
return func(ctx *Context, value SerializedValue) (reflect.Type, *reflect.Value, SerializedValue, error) {
|
|
|
|
return func(ctx *Context, value SerializedValue) (reflect.Type, *reflect.Value, SerializedValue, error) {
|
|
|
|
var interface_zero T
|
|
|
|
var interface_zero T
|
|
|
|
var interface_type = reflect.ValueOf(&interface_zero).Type().Elem()
|
|
|
|
var interface_type = reflect.ValueOf(&interface_zero).Type().Elem()
|
|
|
@ -641,7 +654,7 @@ func ExtField(ctx *Context, ext Extension, field_name string) (reflect.Value, er
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ext_value := reflect.ValueOf(ext).Elem()
|
|
|
|
ext_value := reflect.ValueOf(ext).Elem()
|
|
|
|
for _, field := range(reflect.VisibleFields(ext_value.Type())) {
|
|
|
|
for _, field := range reflect.VisibleFields(ext_value.Type()) {
|
|
|
|
gv_tag, tagged := field.Tag.Lookup("gv")
|
|
|
|
gv_tag, tagged := field.Tag.Lookup("gv")
|
|
|
|
if tagged == true && gv_tag == field_name {
|
|
|
|
if tagged == true && gv_tag == field_name {
|
|
|
|
return ext_value.FieldByIndex(field.Index), nil
|
|
|
|
return ext_value.FieldByIndex(field.Index), nil
|
|
|
@ -665,7 +678,7 @@ func (value SerializedValue) MarshalBinary() ([]byte, error) {
|
|
|
|
binary.BigEndian.PutUint64(data[0:8], uint64(len(value.TypeStack)))
|
|
|
|
binary.BigEndian.PutUint64(data[0:8], uint64(len(value.TypeStack)))
|
|
|
|
binary.BigEndian.PutUint64(data[8:16], uint64(len(value.Data)))
|
|
|
|
binary.BigEndian.PutUint64(data[8:16], uint64(len(value.Data)))
|
|
|
|
|
|
|
|
|
|
|
|
for i, t := range(value.TypeStack) {
|
|
|
|
for i, t := range value.TypeStack {
|
|
|
|
type_start := (i + 2) * 8
|
|
|
|
type_start := (i + 2) * 8
|
|
|
|
type_end := (i + 3) * 8
|
|
|
|
type_end := (i + 3) * 8
|
|
|
|
binary.BigEndian.PutUint64(data[type_start:type_end], uint64(t))
|
|
|
|
binary.BigEndian.PutUint64(data[type_start:type_end], uint64(t))
|
|
|
|