8
8
"bytes"
9
9
"encoding/binary"
10
10
"fmt"
11
+ "iter"
11
12
"maps"
12
13
"math"
13
14
"reflect"
@@ -274,66 +275,26 @@ func (p *Properties) String() string {
274
275
return buf .String ()
275
276
}
276
277
277
- func (p * Properties ) loadFromRowBlock (b []byte , deniedUserProperties map [string ]struct {}) error {
278
- i , err := rowblk .NewRawIter (bytes .Compare , b )
279
- if err != nil {
280
- return err
281
- }
282
- p .Loaded = make (map [uintptr ]struct {})
283
- v := reflect .ValueOf (p ).Elem ()
284
-
285
- for valid := i .First (); valid ; valid = i .Next () {
286
- if f , ok := propTagMap [string (i .Key ().UserKey )]; ok {
287
- p .Loaded [f .Offset ] = struct {}{}
288
- field := v .FieldByIndex (f .Index )
289
- switch f .Type .Kind () {
290
- case reflect .Bool :
291
- field .SetBool (bytes .Equal (i .Value (), propBoolTrue ))
292
- case reflect .Uint32 :
293
- field .SetUint (uint64 (binary .LittleEndian .Uint32 (i .Value ())))
294
- case reflect .Uint64 :
295
- n , _ := binary .Uvarint (i .Value ())
296
- field .SetUint (n )
297
- case reflect .String :
298
- field .SetString (intern .Bytes (i .Value ()))
299
- default :
300
- panic ("not reached" )
301
- }
302
- continue
303
- }
304
- if p .UserProperties == nil {
305
- p .UserProperties = make (map [string ]string )
306
- }
307
-
308
- if _ , denied := deniedUserProperties [string (i .Key ().UserKey )]; ! denied {
309
- p .UserProperties [intern .Bytes (i .Key ().UserKey )] = string (i .Value ())
310
- }
311
- }
312
- return nil
313
- }
314
-
315
- func (p * Properties ) load (b []byte , deniedUserProperties map [string ]struct {}) error {
316
- var decoder colblk.KeyValueBlockDecoder
317
- decoder .Init (b )
278
+ func (p * Properties ) load (
279
+ i iter.Seq2 [[]byte , []byte ], deniedUserProperties map [string ]struct {},
280
+ ) error {
318
281
p .Loaded = make (map [uintptr ]struct {})
319
282
v := reflect .ValueOf (p ).Elem ()
320
283
321
- for i := 0 ; i < decoder .BlockDecoder ().Rows (); i ++ {
322
- key := decoder .KeyAt (i )
323
- value := decoder .ValueAt (i )
284
+ for key , val := range i {
324
285
if f , ok := propTagMap [string (key )]; ok {
325
286
p .Loaded [f .Offset ] = struct {}{}
326
287
field := v .FieldByIndex (f .Index )
327
288
switch f .Type .Kind () {
328
289
case reflect .Bool :
329
- field .SetBool (bytes .Equal (value , propBoolTrue ))
290
+ field .SetBool (bytes .Equal (val , propBoolTrue ))
330
291
case reflect .Uint32 :
331
- field .SetUint (uint64 (binary .LittleEndian .Uint32 (value )))
292
+ field .SetUint (uint64 (binary .LittleEndian .Uint32 (val )))
332
293
case reflect .Uint64 :
333
- n , _ := binary .Uvarint (value )
294
+ n , _ := binary .Uvarint (val )
334
295
field .SetUint (n )
335
296
case reflect .String :
336
- field .SetString (intern .Bytes (value ))
297
+ field .SetString (intern .Bytes (val ))
337
298
default :
338
299
panic ("not reached" )
339
300
}
@@ -344,7 +305,7 @@ func (p *Properties) load(b []byte, deniedUserProperties map[string]struct{}) er
344
305
}
345
306
346
307
if _ , denied := deniedUserProperties [string (key )]; ! denied {
347
- p .UserProperties [intern .Bytes (key )] = string (value )
308
+ p .UserProperties [intern .Bytes (key )] = string (val )
348
309
}
349
310
}
350
311
return nil
0 commit comments