gitlab.com/evatix-go/core@v1.3.55/coredata/corejson/newResultsPtrCollectionCreator.go (about) 1 package corejson 2 3 import ( 4 "gitlab.com/evatix-go/core/constants" 5 ) 6 7 type newResultsPtrCollectionCreator struct{} 8 9 // UnmarshalUsingBytes 10 // 11 // Aka. alias for DeserializeUsingBytes 12 // 13 // Should be used when ResultsPtrCollection itself is Serialized 14 // and save to somewhere and then unmarshal or deserialize 15 func (it newResultsPtrCollectionCreator) UnmarshalUsingBytes( 16 deserializingBytes []byte, 17 ) (*ResultsPtrCollection, error) { 18 return it.DeserializeUsingBytes(deserializingBytes) 19 } 20 21 // DeserializeUsingBytes 22 // 23 // Should be used when ResultsPtrCollection itself is Serialized 24 // and save to somewhere and then unmarshal or deserialize 25 func (it newResultsPtrCollectionCreator) DeserializeUsingBytes( 26 deserializingBytes []byte, 27 ) (*ResultsPtrCollection, error) { 28 empty := it.Empty() 29 30 err := Deserialize. 31 UsingBytes(deserializingBytes, empty) 32 33 if err == nil { 34 return empty, nil 35 } 36 37 return nil, err 38 } 39 40 func (it newResultsPtrCollectionCreator) DeserializeUsingResult( 41 jsonResult *Result, 42 ) (*ResultsPtrCollection, error) { 43 if jsonResult.HasIssuesOrEmpty() { 44 return nil, jsonResult.MeaningfulError() 45 } 46 47 empty := it.Empty() 48 49 err := Deserialize. 50 UsingBytes(jsonResult.SafeBytes(), empty) 51 52 if err == nil { 53 return empty, nil 54 } 55 56 return nil, err 57 } 58 59 func (it newResultsPtrCollectionCreator) Empty() *ResultsPtrCollection { 60 list := make([]*Result, 0) 61 62 return &ResultsPtrCollection{ 63 Items: list, 64 } 65 } 66 67 func (it newResultsPtrCollectionCreator) UsingCap( 68 capacity int, 69 ) *ResultsPtrCollection { 70 list := make([]*Result, 0, capacity) 71 72 return &ResultsPtrCollection{ 73 Items: list, 74 } 75 } 76 77 func (it newResultsPtrCollectionCreator) Default() *ResultsPtrCollection { 78 list := make([]*Result, 0, constants.Capacity8) 79 80 return &ResultsPtrCollection{ 81 Items: list, 82 } 83 } 84 85 func (it newResultsPtrCollectionCreator) AnyItemsPlusCap( 86 capacity int, 87 anyItems ...interface{}, 88 ) *ResultsPtrCollection { 89 length := capacity + len(anyItems) 90 91 if length == 0 || len(anyItems) == 0 { 92 return it.UsingCap(length) 93 } 94 95 collection := it.UsingCap(length) 96 97 return collection.AddAnyItems( 98 anyItems...) 99 } 100 101 func (it newResultsPtrCollectionCreator) AnyItems( 102 anyItems ...interface{}, 103 ) *ResultsPtrCollection { 104 return it.AnyItemsPlusCap( 105 0, 106 anyItems...) 107 } 108 109 func (it newResultsPtrCollectionCreator) UsingResultsPlusCap( 110 addCapacity int, 111 results ...*Result, 112 ) *ResultsPtrCollection { 113 length := addCapacity + len(results) 114 115 if length == 0 || len(results) == 0 { 116 return it.UsingCap(length) 117 } 118 119 list := it.UsingCap(length) 120 121 return list. 122 AddNonNilItemsPtr(results...) 123 } 124 125 func (it newResultsPtrCollectionCreator) UsingResults( 126 results ...*Result, 127 ) *ResultsPtrCollection { 128 return it.UsingResultsPlusCap( 129 0, 130 results...) 131 } 132 133 func (it newResultsPtrCollectionCreator) JsonersPlusCap( 134 isIgnoreNilOrErr bool, 135 capacity int, 136 jsoners ...Jsoner, 137 ) *ResultsPtrCollection { 138 length := capacity + len(jsoners) 139 140 if length == 0 || len(jsoners) == 0 { 141 return it.UsingCap(length) 142 } 143 144 collection := it.UsingCap(length) 145 146 return collection.AddJsoners( 147 isIgnoreNilOrErr, 148 jsoners...) 149 } 150 151 func (it newResultsPtrCollectionCreator) Jsoners( 152 jsoners ...Jsoner, 153 ) *ResultsPtrCollection { 154 return it.JsonersPlusCap( 155 true, 156 0, 157 jsoners...) 158 } 159 160 func (it newResultsPtrCollectionCreator) Serializers( 161 serializers ...bytesSerializer, 162 ) *ResultsPtrCollection { 163 if len(serializers) == 0 { 164 return it.Empty() 165 } 166 167 collection := it.UsingCap(len(serializers)) 168 169 for _, serializer := range serializers { 170 collection.AddSerializer(serializer) 171 } 172 173 return collection 174 }