88 "bytes"
99 "encoding/binary"
1010 "fmt"
11+ "iter"
1112 "maps"
1213 "math"
1314 "reflect"
@@ -274,66 +275,26 @@ func (p *Properties) String() string {
274275 return buf .String ()
275276}
276277
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 {
318281 p .Loaded = make (map [uintptr ]struct {})
319282 v := reflect .ValueOf (p ).Elem ()
320283
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 {
324285 if f , ok := propTagMap [string (key )]; ok {
325286 p .Loaded [f .Offset ] = struct {}{}
326287 field := v .FieldByIndex (f .Index )
327288 switch f .Type .Kind () {
328289 case reflect .Bool :
329- field .SetBool (bytes .Equal (value , propBoolTrue ))
290+ field .SetBool (bytes .Equal (val , propBoolTrue ))
330291 case reflect .Uint32 :
331- field .SetUint (uint64 (binary .LittleEndian .Uint32 (value )))
292+ field .SetUint (uint64 (binary .LittleEndian .Uint32 (val )))
332293 case reflect .Uint64 :
333- n , _ := binary .Uvarint (value )
294+ n , _ := binary .Uvarint (val )
334295 field .SetUint (n )
335296 case reflect .String :
336- field .SetString (intern .Bytes (value ))
297+ field .SetString (intern .Bytes (val ))
337298 default :
338299 panic ("not reached" )
339300 }
@@ -344,7 +305,7 @@ func (p *Properties) load(b []byte, deniedUserProperties map[string]struct{}) er
344305 }
345306
346307 if _ , denied := deniedUserProperties [string (key )]; ! denied {
347- p .UserProperties [intern .Bytes (key )] = string (value )
308+ p .UserProperties [intern .Bytes (key )] = string (val )
348309 }
349310 }
350311 return nil
0 commit comments