forked from AmarnathCJD/gogram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.go
executable file
·77 lines (60 loc) · 1.59 KB
/
object.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) 2024 RoseLoverX
package tl
type Object interface {
CRC() uint32
}
type FlagIndexGetter interface {
FlagIndex() int
}
type Marshaler interface {
MarshalTL(*Encoder) error
}
type Unmarshaler interface {
UnmarshalTL(*Decoder) error
}
//==========================================================================================================//
// Next types are specific structs for handling bool types, slice and null as object. // //
//==========================================================================================================//
// PseudoTrue is a support struct which is required to get native
type PseudoTrue struct{}
func (*PseudoTrue) CRC() uint32 {
return CrcTrue
}
// PseudoFalse is a support struct which is required to get native
type PseudoFalse struct{}
func (*PseudoFalse) CRC() uint32 {
return CrcFalse
}
type PseudoNil struct{}
func (*PseudoNil) CRC() uint32 {
return CrcNull
}
// you won't use it, right?
func (*PseudoNil) Unwrap() any {
return nil
}
// WrappedSlice is pseudo type. YOU SHOULD NOT use it customly, instead, you must encode/decode value by
// encoder.PutVector or decoder.PopVector
type WrappedSlice struct {
data any
}
func (*WrappedSlice) CRC() uint32 {
return CrcVector
}
func (w *WrappedSlice) Unwrap() any {
return w.data
}
func UnwrapNativeTypes(in Object) any {
switch i := in.(type) {
case *PseudoTrue:
return true
case *PseudoFalse:
return false
case *PseudoNil:
return nil
case *WrappedSlice:
return i.Unwrap()
default:
return in
}
}