go-hep.org/x/hep@v0.40.0/groot/rtree/leaf_gen.go (about) 1 // Copyright ©2019 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Automatically generated. DO NOT EDIT. 6 7 package rtree 8 9 import ( 10 "fmt" 11 "reflect" 12 "strings" 13 "unsafe" 14 15 "go-hep.org/x/hep/groot/rbase" 16 "go-hep.org/x/hep/groot/rbytes" 17 "go-hep.org/x/hep/groot/rdict" 18 "go-hep.org/x/hep/groot/rmeta" 19 "go-hep.org/x/hep/groot/root" 20 "go-hep.org/x/hep/groot/rtypes" 21 "go-hep.org/x/hep/groot/rvers" 22 ) 23 24 // LeafO implements ROOT TLeafO 25 type LeafO struct { 26 rvers int16 27 tleaf 28 ptr *bool 29 sli *[]bool 30 min bool 31 max bool 32 } 33 34 func newLeafO(b Branch, name string, shape []int, unsigned bool, count Leaf) *LeafO { 35 const etype = 1 36 var lcnt leafCount 37 if count != nil { 38 lcnt = count.(leafCount) 39 } 40 return &LeafO{ 41 rvers: rvers.LeafO, 42 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 43 } 44 } 45 46 // Class returns the ROOT class name. 47 func (leaf *LeafO) Class() string { 48 return "TLeafO" 49 } 50 51 // Minimum returns the minimum value of the leaf. 52 func (leaf *LeafO) Minimum() bool { 53 return leaf.min 54 } 55 56 // Maximum returns the maximum value of the leaf. 57 func (leaf *LeafO) Maximum() bool { 58 return leaf.max 59 } 60 61 // Kind returns the leaf's kind. 62 func (leaf *LeafO) Kind() reflect.Kind { 63 return reflect.Bool 64 } 65 66 // Type returns the leaf's type. 67 func (leaf *LeafO) Type() reflect.Type { 68 return reflect.TypeFor[bool]() 69 } 70 71 func (leaf *LeafO) TypeName() string { 72 return "bool" 73 } 74 75 func (leaf *LeafO) MarshalROOT(w *rbytes.WBuffer) (int, error) { 76 if w.Err() != nil { 77 return 0, w.Err() 78 } 79 80 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 81 w.WriteObject(&leaf.tleaf) 82 w.WriteBool(leaf.min) 83 w.WriteBool(leaf.max) 84 85 return w.SetHeader(hdr) 86 } 87 88 func (leaf *LeafO) UnmarshalROOT(r *rbytes.RBuffer) error { 89 if r.Err() != nil { 90 return r.Err() 91 } 92 93 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 94 leaf.rvers = hdr.Vers 95 96 r.ReadObject(&leaf.tleaf) 97 98 leaf.min = r.ReadBool() 99 leaf.max = r.ReadBool() 100 101 r.CheckHeader(hdr) 102 return r.Err() 103 } 104 105 func (leaf *LeafO) readFromBuffer(r *rbytes.RBuffer) error { 106 if r.Err() != nil { 107 return r.Err() 108 } 109 110 if leaf.count == nil && leaf.ptr != nil { 111 *leaf.ptr = r.ReadBool() 112 } else { 113 if leaf.count != nil { 114 n := leaf.count.ivalue() 115 max := leaf.count.imax() 116 if n > max { 117 n = max 118 } 119 nn := leaf.tleaf.len * n 120 *leaf.sli = rbytes.ResizeBool(*leaf.sli, nn) 121 r.ReadArrayBool(*leaf.sli) 122 } else { 123 nn := leaf.tleaf.len 124 *leaf.sli = rbytes.ResizeBool(*leaf.sli, nn) 125 r.ReadArrayBool(*leaf.sli) 126 } 127 } 128 return r.Err() 129 } 130 131 func (leaf *LeafO) unsafeDecayArray(ptr any) any { 132 rv := reflect.ValueOf(ptr).Elem() 133 sz := rv.Type().Size() / 1 134 sli := unsafe.Slice((*bool)(unsafe.Pointer(rv.UnsafeAddr())), sz) 135 return &sli 136 } 137 138 func (leaf *LeafO) setAddress(ptr any) error { 139 if ptr == nil { 140 return leaf.setAddress(newValue(leaf)) 141 } 142 143 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 144 sli := leaf.unsafeDecayArray(ptr) 145 switch sli := sli.(type) { 146 case *[]bool: 147 return leaf.setAddress(sli) 148 default: 149 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 150 } 151 } 152 153 switch v := ptr.(type) { 154 case *bool: 155 leaf.ptr = v 156 case *[]bool: 157 leaf.sli = v 158 if *v == nil { 159 *leaf.sli = make([]bool, 0) 160 } 161 default: 162 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 163 } 164 return nil 165 } 166 167 func (leaf *LeafO) writeToBuffer(w *rbytes.WBuffer) (int, error) { 168 if w.Err() != nil { 169 return 0, w.Err() 170 } 171 172 var nbytes int 173 switch { 174 case leaf.ptr != nil: 175 w.WriteBool(*leaf.ptr) 176 nbytes += leaf.tleaf.etype 177 case leaf.count != nil: 178 n := leaf.count.ivalue() 179 max := leaf.count.imax() 180 if n > max { 181 n = max 182 } 183 end := leaf.tleaf.len * n 184 w.WriteArrayBool((*leaf.sli)[:end]) 185 nbytes += leaf.tleaf.etype * end 186 default: 187 w.WriteArrayBool((*leaf.sli)[:leaf.tleaf.len]) 188 nbytes += leaf.tleaf.etype * leaf.tleaf.len 189 } 190 191 return nbytes, w.Err() 192 } 193 194 func init() { 195 f := func() reflect.Value { 196 o := &LeafO{} 197 return reflect.ValueOf(o) 198 } 199 rtypes.Factory.Add("TLeafO", f) 200 } 201 202 var ( 203 _ root.Object = (*LeafO)(nil) 204 _ root.Named = (*LeafO)(nil) 205 _ Leaf = (*LeafO)(nil) 206 _ rbytes.Marshaler = (*LeafO)(nil) 207 _ rbytes.Unmarshaler = (*LeafO)(nil) 208 ) 209 210 // LeafB implements ROOT TLeafB 211 type LeafB struct { 212 rvers int16 213 tleaf 214 ptr *int8 215 sli *[]int8 216 min int8 217 max int8 218 } 219 220 func newLeafB(b Branch, name string, shape []int, unsigned bool, count Leaf) *LeafB { 221 const etype = 1 222 var lcnt leafCount 223 if count != nil { 224 lcnt = count.(leafCount) 225 } 226 return &LeafB{ 227 rvers: rvers.LeafB, 228 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 229 } 230 } 231 232 // Class returns the ROOT class name. 233 func (leaf *LeafB) Class() string { 234 return "TLeafB" 235 } 236 237 // Minimum returns the minimum value of the leaf. 238 func (leaf *LeafB) Minimum() int8 { 239 return leaf.min 240 } 241 242 // Maximum returns the maximum value of the leaf. 243 func (leaf *LeafB) Maximum() int8 { 244 return leaf.max 245 } 246 247 // Kind returns the leaf's kind. 248 func (leaf *LeafB) Kind() reflect.Kind { 249 if leaf.IsUnsigned() { 250 return reflect.Uint8 251 } 252 return reflect.Int8 253 } 254 255 // Type returns the leaf's type. 256 func (leaf *LeafB) Type() reflect.Type { 257 if leaf.IsUnsigned() { 258 return reflect.TypeFor[uint8]() 259 } 260 return reflect.TypeFor[int8]() 261 } 262 263 // ivalue returns the first leaf value as int 264 func (leaf *LeafB) ivalue() int { 265 return int(*leaf.ptr) 266 } 267 268 // imax returns the leaf maximum value as int 269 func (leaf *LeafB) imax() int { 270 return int(leaf.max) 271 } 272 273 func (leaf *LeafB) TypeName() string { 274 if leaf.IsUnsigned() { 275 return "uint8" 276 } 277 return "int8" 278 } 279 280 func (leaf *LeafB) MarshalROOT(w *rbytes.WBuffer) (int, error) { 281 if w.Err() != nil { 282 return 0, w.Err() 283 } 284 285 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 286 w.WriteObject(&leaf.tleaf) 287 w.WriteI8(leaf.min) 288 w.WriteI8(leaf.max) 289 290 return w.SetHeader(hdr) 291 } 292 293 func (leaf *LeafB) UnmarshalROOT(r *rbytes.RBuffer) error { 294 if r.Err() != nil { 295 return r.Err() 296 } 297 298 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 299 leaf.rvers = hdr.Vers 300 301 r.ReadObject(&leaf.tleaf) 302 303 leaf.min = r.ReadI8() 304 leaf.max = r.ReadI8() 305 306 r.CheckHeader(hdr) 307 return r.Err() 308 } 309 310 func (leaf *LeafB) readFromBuffer(r *rbytes.RBuffer) error { 311 if r.Err() != nil { 312 return r.Err() 313 } 314 315 if leaf.count == nil && leaf.ptr != nil { 316 *leaf.ptr = r.ReadI8() 317 } else { 318 if leaf.count != nil { 319 n := leaf.count.ivalue() 320 max := leaf.count.imax() 321 if n > max { 322 n = max 323 } 324 nn := leaf.tleaf.len * n 325 *leaf.sli = rbytes.ResizeI8(*leaf.sli, nn) 326 r.ReadArrayI8(*leaf.sli) 327 } else { 328 nn := leaf.tleaf.len 329 *leaf.sli = rbytes.ResizeI8(*leaf.sli, nn) 330 r.ReadArrayI8(*leaf.sli) 331 } 332 } 333 return r.Err() 334 } 335 336 func (leaf *LeafB) unsafeDecayArray(ptr any) any { 337 rv := reflect.ValueOf(ptr).Elem() 338 sz := rv.Type().Size() / 1 339 sli := unsafe.Slice((*int8)(unsafe.Pointer(rv.UnsafeAddr())), sz) 340 return &sli 341 } 342 343 func (leaf *LeafB) setAddress(ptr any) error { 344 if ptr == nil { 345 return leaf.setAddress(newValue(leaf)) 346 } 347 348 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 349 sli := leaf.unsafeDecayArray(ptr) 350 switch sli := sli.(type) { 351 case *[]int8: 352 return leaf.setAddress(sli) 353 case *[]uint8: 354 return leaf.setAddress(sli) 355 default: 356 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 357 } 358 } 359 360 switch v := ptr.(type) { 361 case *int8: 362 leaf.ptr = v 363 case *[]int8: 364 leaf.sli = v 365 if *v == nil { 366 *leaf.sli = make([]int8, 0) 367 } 368 case *uint8: 369 leaf.ptr = (*int8)(unsafe.Pointer(v)) 370 case *[]uint8: 371 leaf.sli = (*[]int8)(unsafe.Pointer(v)) 372 if *v == nil { 373 *leaf.sli = make([]int8, 0) 374 } 375 default: 376 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 377 } 378 return nil 379 } 380 381 func (leaf *LeafB) writeToBuffer(w *rbytes.WBuffer) (int, error) { 382 if w.Err() != nil { 383 return 0, w.Err() 384 } 385 386 var nbytes int 387 switch { 388 case leaf.ptr != nil: 389 w.WriteI8(*leaf.ptr) 390 nbytes += leaf.tleaf.etype 391 if v := *leaf.ptr; v > leaf.max { 392 leaf.max = v 393 } 394 case leaf.count != nil: 395 n := leaf.count.ivalue() 396 max := leaf.count.imax() 397 if n > max { 398 n = max 399 } 400 end := leaf.tleaf.len * n 401 w.WriteArrayI8((*leaf.sli)[:end]) 402 nbytes += leaf.tleaf.etype * end 403 default: 404 w.WriteArrayI8((*leaf.sli)[:leaf.tleaf.len]) 405 nbytes += leaf.tleaf.etype * leaf.tleaf.len 406 } 407 408 return nbytes, w.Err() 409 } 410 411 func init() { 412 f := func() reflect.Value { 413 o := &LeafB{} 414 return reflect.ValueOf(o) 415 } 416 rtypes.Factory.Add("TLeafB", f) 417 } 418 419 var ( 420 _ root.Object = (*LeafB)(nil) 421 _ root.Named = (*LeafB)(nil) 422 _ Leaf = (*LeafB)(nil) 423 _ rbytes.Marshaler = (*LeafB)(nil) 424 _ rbytes.Unmarshaler = (*LeafB)(nil) 425 ) 426 427 // LeafS implements ROOT TLeafS 428 type LeafS struct { 429 rvers int16 430 tleaf 431 ptr *int16 432 sli *[]int16 433 min int16 434 max int16 435 } 436 437 func newLeafS(b Branch, name string, shape []int, unsigned bool, count Leaf) *LeafS { 438 const etype = 2 439 var lcnt leafCount 440 if count != nil { 441 lcnt = count.(leafCount) 442 } 443 return &LeafS{ 444 rvers: rvers.LeafS, 445 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 446 } 447 } 448 449 // Class returns the ROOT class name. 450 func (leaf *LeafS) Class() string { 451 return "TLeafS" 452 } 453 454 // Minimum returns the minimum value of the leaf. 455 func (leaf *LeafS) Minimum() int16 { 456 return leaf.min 457 } 458 459 // Maximum returns the maximum value of the leaf. 460 func (leaf *LeafS) Maximum() int16 { 461 return leaf.max 462 } 463 464 // Kind returns the leaf's kind. 465 func (leaf *LeafS) Kind() reflect.Kind { 466 if leaf.IsUnsigned() { 467 return reflect.Uint16 468 } 469 return reflect.Int16 470 } 471 472 // Type returns the leaf's type. 473 func (leaf *LeafS) Type() reflect.Type { 474 if leaf.IsUnsigned() { 475 return reflect.TypeFor[uint16]() 476 } 477 return reflect.TypeFor[int16]() 478 } 479 480 // ivalue returns the first leaf value as int 481 func (leaf *LeafS) ivalue() int { 482 return int(*leaf.ptr) 483 } 484 485 // imax returns the leaf maximum value as int 486 func (leaf *LeafS) imax() int { 487 return int(leaf.max) 488 } 489 490 func (leaf *LeafS) TypeName() string { 491 if leaf.IsUnsigned() { 492 return "uint16" 493 } 494 return "int16" 495 } 496 497 func (leaf *LeafS) MarshalROOT(w *rbytes.WBuffer) (int, error) { 498 if w.Err() != nil { 499 return 0, w.Err() 500 } 501 502 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 503 w.WriteObject(&leaf.tleaf) 504 w.WriteI16(leaf.min) 505 w.WriteI16(leaf.max) 506 507 return w.SetHeader(hdr) 508 } 509 510 func (leaf *LeafS) UnmarshalROOT(r *rbytes.RBuffer) error { 511 if r.Err() != nil { 512 return r.Err() 513 } 514 515 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 516 leaf.rvers = hdr.Vers 517 518 r.ReadObject(&leaf.tleaf) 519 520 leaf.min = r.ReadI16() 521 leaf.max = r.ReadI16() 522 523 r.CheckHeader(hdr) 524 return r.Err() 525 } 526 527 func (leaf *LeafS) readFromBuffer(r *rbytes.RBuffer) error { 528 if r.Err() != nil { 529 return r.Err() 530 } 531 532 if leaf.count == nil && leaf.ptr != nil { 533 *leaf.ptr = r.ReadI16() 534 } else { 535 if leaf.count != nil { 536 n := leaf.count.ivalue() 537 max := leaf.count.imax() 538 if n > max { 539 n = max 540 } 541 nn := leaf.tleaf.len * n 542 *leaf.sli = rbytes.ResizeI16(*leaf.sli, nn) 543 r.ReadArrayI16(*leaf.sli) 544 } else { 545 nn := leaf.tleaf.len 546 *leaf.sli = rbytes.ResizeI16(*leaf.sli, nn) 547 r.ReadArrayI16(*leaf.sli) 548 } 549 } 550 return r.Err() 551 } 552 553 func (leaf *LeafS) unsafeDecayArray(ptr any) any { 554 rv := reflect.ValueOf(ptr).Elem() 555 sz := rv.Type().Size() / 2 556 sli := unsafe.Slice((*int16)(unsafe.Pointer(rv.UnsafeAddr())), sz) 557 return &sli 558 } 559 560 func (leaf *LeafS) setAddress(ptr any) error { 561 if ptr == nil { 562 return leaf.setAddress(newValue(leaf)) 563 } 564 565 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 566 sli := leaf.unsafeDecayArray(ptr) 567 switch sli := sli.(type) { 568 case *[]int16: 569 return leaf.setAddress(sli) 570 case *[]uint16: 571 return leaf.setAddress(sli) 572 default: 573 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 574 } 575 } 576 577 switch v := ptr.(type) { 578 case *int16: 579 leaf.ptr = v 580 case *[]int16: 581 leaf.sli = v 582 if *v == nil { 583 *leaf.sli = make([]int16, 0) 584 } 585 case *uint16: 586 leaf.ptr = (*int16)(unsafe.Pointer(v)) 587 case *[]uint16: 588 leaf.sli = (*[]int16)(unsafe.Pointer(v)) 589 if *v == nil { 590 *leaf.sli = make([]int16, 0) 591 } 592 default: 593 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 594 } 595 return nil 596 } 597 598 func (leaf *LeafS) writeToBuffer(w *rbytes.WBuffer) (int, error) { 599 if w.Err() != nil { 600 return 0, w.Err() 601 } 602 603 var nbytes int 604 switch { 605 case leaf.ptr != nil: 606 w.WriteI16(*leaf.ptr) 607 nbytes += leaf.tleaf.etype 608 if v := *leaf.ptr; v > leaf.max { 609 leaf.max = v 610 } 611 case leaf.count != nil: 612 n := leaf.count.ivalue() 613 max := leaf.count.imax() 614 if n > max { 615 n = max 616 } 617 end := leaf.tleaf.len * n 618 w.WriteArrayI16((*leaf.sli)[:end]) 619 nbytes += leaf.tleaf.etype * end 620 default: 621 w.WriteArrayI16((*leaf.sli)[:leaf.tleaf.len]) 622 nbytes += leaf.tleaf.etype * leaf.tleaf.len 623 } 624 625 return nbytes, w.Err() 626 } 627 628 func init() { 629 f := func() reflect.Value { 630 o := &LeafS{} 631 return reflect.ValueOf(o) 632 } 633 rtypes.Factory.Add("TLeafS", f) 634 } 635 636 var ( 637 _ root.Object = (*LeafS)(nil) 638 _ root.Named = (*LeafS)(nil) 639 _ Leaf = (*LeafS)(nil) 640 _ rbytes.Marshaler = (*LeafS)(nil) 641 _ rbytes.Unmarshaler = (*LeafS)(nil) 642 ) 643 644 // LeafI implements ROOT TLeafI 645 type LeafI struct { 646 rvers int16 647 tleaf 648 ptr *int32 649 sli *[]int32 650 min int32 651 max int32 652 } 653 654 func newLeafI(b Branch, name string, shape []int, unsigned bool, count Leaf) *LeafI { 655 const etype = 4 656 var lcnt leafCount 657 if count != nil { 658 lcnt = count.(leafCount) 659 } 660 return &LeafI{ 661 rvers: rvers.LeafI, 662 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 663 } 664 } 665 666 // Class returns the ROOT class name. 667 func (leaf *LeafI) Class() string { 668 return "TLeafI" 669 } 670 671 // Minimum returns the minimum value of the leaf. 672 func (leaf *LeafI) Minimum() int32 { 673 return leaf.min 674 } 675 676 // Maximum returns the maximum value of the leaf. 677 func (leaf *LeafI) Maximum() int32 { 678 return leaf.max 679 } 680 681 // Kind returns the leaf's kind. 682 func (leaf *LeafI) Kind() reflect.Kind { 683 if leaf.IsUnsigned() { 684 return reflect.Uint32 685 } 686 return reflect.Int32 687 } 688 689 // Type returns the leaf's type. 690 func (leaf *LeafI) Type() reflect.Type { 691 if leaf.IsUnsigned() { 692 return reflect.TypeFor[uint32]() 693 } 694 return reflect.TypeFor[int32]() 695 } 696 697 // ivalue returns the first leaf value as int 698 func (leaf *LeafI) ivalue() int { 699 return int(*leaf.ptr) 700 } 701 702 // imax returns the leaf maximum value as int 703 func (leaf *LeafI) imax() int { 704 return int(leaf.max) 705 } 706 707 func (leaf *LeafI) TypeName() string { 708 if leaf.IsUnsigned() { 709 return "uint32" 710 } 711 return "int32" 712 } 713 714 func (leaf *LeafI) MarshalROOT(w *rbytes.WBuffer) (int, error) { 715 if w.Err() != nil { 716 return 0, w.Err() 717 } 718 719 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 720 w.WriteObject(&leaf.tleaf) 721 w.WriteI32(leaf.min) 722 w.WriteI32(leaf.max) 723 724 return w.SetHeader(hdr) 725 } 726 727 func (leaf *LeafI) UnmarshalROOT(r *rbytes.RBuffer) error { 728 if r.Err() != nil { 729 return r.Err() 730 } 731 732 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 733 leaf.rvers = hdr.Vers 734 735 r.ReadObject(&leaf.tleaf) 736 737 leaf.min = r.ReadI32() 738 leaf.max = r.ReadI32() 739 740 r.CheckHeader(hdr) 741 return r.Err() 742 } 743 744 func (leaf *LeafI) readFromBuffer(r *rbytes.RBuffer) error { 745 if r.Err() != nil { 746 return r.Err() 747 } 748 749 if leaf.count == nil && leaf.ptr != nil { 750 *leaf.ptr = r.ReadI32() 751 } else { 752 if leaf.count != nil { 753 n := leaf.count.ivalue() 754 max := leaf.count.imax() 755 if n > max { 756 n = max 757 } 758 nn := leaf.tleaf.len * n 759 *leaf.sli = rbytes.ResizeI32(*leaf.sli, nn) 760 r.ReadArrayI32(*leaf.sli) 761 } else { 762 nn := leaf.tleaf.len 763 *leaf.sli = rbytes.ResizeI32(*leaf.sli, nn) 764 r.ReadArrayI32(*leaf.sli) 765 } 766 } 767 return r.Err() 768 } 769 770 func (leaf *LeafI) unsafeDecayArray(ptr any) any { 771 rv := reflect.ValueOf(ptr).Elem() 772 sz := rv.Type().Size() / 4 773 sli := unsafe.Slice((*int32)(unsafe.Pointer(rv.UnsafeAddr())), sz) 774 return &sli 775 } 776 777 func (leaf *LeafI) setAddress(ptr any) error { 778 if ptr == nil { 779 return leaf.setAddress(newValue(leaf)) 780 } 781 782 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 783 sli := leaf.unsafeDecayArray(ptr) 784 switch sli := sli.(type) { 785 case *[]int32: 786 return leaf.setAddress(sli) 787 case *[]uint32: 788 return leaf.setAddress(sli) 789 default: 790 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 791 } 792 } 793 794 switch v := ptr.(type) { 795 case *int32: 796 leaf.ptr = v 797 case *[]int32: 798 leaf.sli = v 799 if *v == nil { 800 *leaf.sli = make([]int32, 0) 801 } 802 case *uint32: 803 leaf.ptr = (*int32)(unsafe.Pointer(v)) 804 case *[]uint32: 805 leaf.sli = (*[]int32)(unsafe.Pointer(v)) 806 if *v == nil { 807 *leaf.sli = make([]int32, 0) 808 } 809 default: 810 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 811 } 812 return nil 813 } 814 815 func (leaf *LeafI) writeToBuffer(w *rbytes.WBuffer) (int, error) { 816 if w.Err() != nil { 817 return 0, w.Err() 818 } 819 820 var nbytes int 821 switch { 822 case leaf.ptr != nil: 823 w.WriteI32(*leaf.ptr) 824 nbytes += leaf.tleaf.etype 825 if v := *leaf.ptr; v > leaf.max { 826 leaf.max = v 827 } 828 case leaf.count != nil: 829 n := leaf.count.ivalue() 830 max := leaf.count.imax() 831 if n > max { 832 n = max 833 } 834 end := leaf.tleaf.len * n 835 w.WriteArrayI32((*leaf.sli)[:end]) 836 nbytes += leaf.tleaf.etype * end 837 default: 838 w.WriteArrayI32((*leaf.sli)[:leaf.tleaf.len]) 839 nbytes += leaf.tleaf.etype * leaf.tleaf.len 840 } 841 842 return nbytes, w.Err() 843 } 844 845 func init() { 846 f := func() reflect.Value { 847 o := &LeafI{} 848 return reflect.ValueOf(o) 849 } 850 rtypes.Factory.Add("TLeafI", f) 851 } 852 853 var ( 854 _ root.Object = (*LeafI)(nil) 855 _ root.Named = (*LeafI)(nil) 856 _ Leaf = (*LeafI)(nil) 857 _ rbytes.Marshaler = (*LeafI)(nil) 858 _ rbytes.Unmarshaler = (*LeafI)(nil) 859 ) 860 861 // LeafL implements ROOT TLeafL 862 type LeafL struct { 863 rvers int16 864 tleaf 865 ptr *int64 866 sli *[]int64 867 min int64 868 max int64 869 } 870 871 func newLeafL(b Branch, name string, shape []int, unsigned bool, count Leaf) *LeafL { 872 const etype = 8 873 var lcnt leafCount 874 if count != nil { 875 lcnt = count.(leafCount) 876 } 877 return &LeafL{ 878 rvers: rvers.LeafL, 879 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 880 } 881 } 882 883 // Class returns the ROOT class name. 884 func (leaf *LeafL) Class() string { 885 return "TLeafL" 886 } 887 888 // Minimum returns the minimum value of the leaf. 889 func (leaf *LeafL) Minimum() int64 { 890 return leaf.min 891 } 892 893 // Maximum returns the maximum value of the leaf. 894 func (leaf *LeafL) Maximum() int64 { 895 return leaf.max 896 } 897 898 // Kind returns the leaf's kind. 899 func (leaf *LeafL) Kind() reflect.Kind { 900 if leaf.IsUnsigned() { 901 return reflect.Uint64 902 } 903 return reflect.Int64 904 } 905 906 // Type returns the leaf's type. 907 func (leaf *LeafL) Type() reflect.Type { 908 if leaf.IsUnsigned() { 909 return reflect.TypeFor[uint64]() 910 } 911 return reflect.TypeFor[int64]() 912 } 913 914 // ivalue returns the first leaf value as int 915 func (leaf *LeafL) ivalue() int { 916 return int(*leaf.ptr) 917 } 918 919 // imax returns the leaf maximum value as int 920 func (leaf *LeafL) imax() int { 921 return int(leaf.max) 922 } 923 924 func (leaf *LeafL) TypeName() string { 925 if leaf.IsUnsigned() { 926 return "uint64" 927 } 928 return "int64" 929 } 930 931 func (leaf *LeafL) MarshalROOT(w *rbytes.WBuffer) (int, error) { 932 if w.Err() != nil { 933 return 0, w.Err() 934 } 935 936 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 937 w.WriteObject(&leaf.tleaf) 938 w.WriteI64(leaf.min) 939 w.WriteI64(leaf.max) 940 941 return w.SetHeader(hdr) 942 } 943 944 func (leaf *LeafL) UnmarshalROOT(r *rbytes.RBuffer) error { 945 if r.Err() != nil { 946 return r.Err() 947 } 948 949 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 950 leaf.rvers = hdr.Vers 951 952 r.ReadObject(&leaf.tleaf) 953 954 leaf.min = r.ReadI64() 955 leaf.max = r.ReadI64() 956 957 r.CheckHeader(hdr) 958 return r.Err() 959 } 960 961 func (leaf *LeafL) readFromBuffer(r *rbytes.RBuffer) error { 962 if r.Err() != nil { 963 return r.Err() 964 } 965 966 if leaf.count == nil && leaf.ptr != nil { 967 *leaf.ptr = r.ReadI64() 968 } else { 969 if leaf.count != nil { 970 n := leaf.count.ivalue() 971 max := leaf.count.imax() 972 if n > max { 973 n = max 974 } 975 nn := leaf.tleaf.len * n 976 *leaf.sli = rbytes.ResizeI64(*leaf.sli, nn) 977 r.ReadArrayI64(*leaf.sli) 978 } else { 979 nn := leaf.tleaf.len 980 *leaf.sli = rbytes.ResizeI64(*leaf.sli, nn) 981 r.ReadArrayI64(*leaf.sli) 982 } 983 } 984 return r.Err() 985 } 986 987 func (leaf *LeafL) unsafeDecayArray(ptr any) any { 988 rv := reflect.ValueOf(ptr).Elem() 989 sz := rv.Type().Size() / 8 990 sli := unsafe.Slice((*int64)(unsafe.Pointer(rv.UnsafeAddr())), sz) 991 return &sli 992 } 993 994 func (leaf *LeafL) setAddress(ptr any) error { 995 if ptr == nil { 996 return leaf.setAddress(newValue(leaf)) 997 } 998 999 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 1000 sli := leaf.unsafeDecayArray(ptr) 1001 switch sli := sli.(type) { 1002 case *[]int64: 1003 return leaf.setAddress(sli) 1004 case *[]uint64: 1005 return leaf.setAddress(sli) 1006 default: 1007 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 1008 } 1009 } 1010 1011 switch v := ptr.(type) { 1012 case *int64: 1013 leaf.ptr = v 1014 case *[]int64: 1015 leaf.sli = v 1016 if *v == nil { 1017 *leaf.sli = make([]int64, 0) 1018 } 1019 case *uint64: 1020 leaf.ptr = (*int64)(unsafe.Pointer(v)) 1021 case *[]uint64: 1022 leaf.sli = (*[]int64)(unsafe.Pointer(v)) 1023 if *v == nil { 1024 *leaf.sli = make([]int64, 0) 1025 } 1026 default: 1027 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 1028 } 1029 return nil 1030 } 1031 1032 func (leaf *LeafL) writeToBuffer(w *rbytes.WBuffer) (int, error) { 1033 if w.Err() != nil { 1034 return 0, w.Err() 1035 } 1036 1037 var nbytes int 1038 switch { 1039 case leaf.ptr != nil: 1040 w.WriteI64(*leaf.ptr) 1041 nbytes += leaf.tleaf.etype 1042 if v := *leaf.ptr; v > leaf.max { 1043 leaf.max = v 1044 } 1045 case leaf.count != nil: 1046 n := leaf.count.ivalue() 1047 max := leaf.count.imax() 1048 if n > max { 1049 n = max 1050 } 1051 end := leaf.tleaf.len * n 1052 w.WriteArrayI64((*leaf.sli)[:end]) 1053 nbytes += leaf.tleaf.etype * end 1054 default: 1055 w.WriteArrayI64((*leaf.sli)[:leaf.tleaf.len]) 1056 nbytes += leaf.tleaf.etype * leaf.tleaf.len 1057 } 1058 1059 return nbytes, w.Err() 1060 } 1061 1062 func init() { 1063 f := func() reflect.Value { 1064 o := &LeafL{} 1065 return reflect.ValueOf(o) 1066 } 1067 rtypes.Factory.Add("TLeafL", f) 1068 } 1069 1070 var ( 1071 _ root.Object = (*LeafL)(nil) 1072 _ root.Named = (*LeafL)(nil) 1073 _ Leaf = (*LeafL)(nil) 1074 _ rbytes.Marshaler = (*LeafL)(nil) 1075 _ rbytes.Unmarshaler = (*LeafL)(nil) 1076 ) 1077 1078 // LeafG implements ROOT TLeafG 1079 type LeafG struct { 1080 rvers int16 1081 tleaf 1082 ptr *int64 1083 sli *[]int64 1084 min int64 1085 max int64 1086 } 1087 1088 func newLeafG(b Branch, name string, shape []int, unsigned bool, count Leaf) *LeafG { 1089 const etype = 8 1090 var lcnt leafCount 1091 if count != nil { 1092 lcnt = count.(leafCount) 1093 } 1094 return &LeafG{ 1095 rvers: rvers.LeafG, 1096 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 1097 } 1098 } 1099 1100 // Class returns the ROOT class name. 1101 func (leaf *LeafG) Class() string { 1102 return "TLeafG" 1103 } 1104 1105 // Minimum returns the minimum value of the leaf. 1106 func (leaf *LeafG) Minimum() int64 { 1107 return leaf.min 1108 } 1109 1110 // Maximum returns the maximum value of the leaf. 1111 func (leaf *LeafG) Maximum() int64 { 1112 return leaf.max 1113 } 1114 1115 // Kind returns the leaf's kind. 1116 func (leaf *LeafG) Kind() reflect.Kind { 1117 if leaf.IsUnsigned() { 1118 return reflect.Uint64 1119 } 1120 return reflect.Int64 1121 } 1122 1123 // Type returns the leaf's type. 1124 func (leaf *LeafG) Type() reflect.Type { 1125 if leaf.IsUnsigned() { 1126 return reflect.TypeFor[uint64]() 1127 } 1128 return reflect.TypeFor[int64]() 1129 } 1130 1131 // ivalue returns the first leaf value as int 1132 func (leaf *LeafG) ivalue() int { 1133 return int(*leaf.ptr) 1134 } 1135 1136 // imax returns the leaf maximum value as int 1137 func (leaf *LeafG) imax() int { 1138 return int(leaf.max) 1139 } 1140 1141 func (leaf *LeafG) TypeName() string { 1142 if leaf.IsUnsigned() { 1143 return "uint64" 1144 } 1145 return "int64" 1146 } 1147 1148 func (leaf *LeafG) MarshalROOT(w *rbytes.WBuffer) (int, error) { 1149 if w.Err() != nil { 1150 return 0, w.Err() 1151 } 1152 1153 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 1154 w.WriteObject(&leaf.tleaf) 1155 w.WriteI64(leaf.min) 1156 w.WriteI64(leaf.max) 1157 1158 return w.SetHeader(hdr) 1159 } 1160 1161 func (leaf *LeafG) UnmarshalROOT(r *rbytes.RBuffer) error { 1162 if r.Err() != nil { 1163 return r.Err() 1164 } 1165 1166 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 1167 leaf.rvers = hdr.Vers 1168 1169 r.ReadObject(&leaf.tleaf) 1170 1171 leaf.min = r.ReadI64() 1172 leaf.max = r.ReadI64() 1173 1174 r.CheckHeader(hdr) 1175 return r.Err() 1176 } 1177 1178 func (leaf *LeafG) readFromBuffer(r *rbytes.RBuffer) error { 1179 if r.Err() != nil { 1180 return r.Err() 1181 } 1182 1183 if leaf.count == nil && leaf.ptr != nil { 1184 *leaf.ptr = r.ReadI64() 1185 } else { 1186 if leaf.count != nil { 1187 n := leaf.count.ivalue() 1188 max := leaf.count.imax() 1189 if n > max { 1190 n = max 1191 } 1192 nn := leaf.tleaf.len * n 1193 *leaf.sli = rbytes.ResizeI64(*leaf.sli, nn) 1194 r.ReadArrayI64(*leaf.sli) 1195 } else { 1196 nn := leaf.tleaf.len 1197 *leaf.sli = rbytes.ResizeI64(*leaf.sli, nn) 1198 r.ReadArrayI64(*leaf.sli) 1199 } 1200 } 1201 return r.Err() 1202 } 1203 1204 func (leaf *LeafG) unsafeDecayArray(ptr any) any { 1205 rv := reflect.ValueOf(ptr).Elem() 1206 sz := rv.Type().Size() / 8 1207 sli := unsafe.Slice((*int64)(unsafe.Pointer(rv.UnsafeAddr())), sz) 1208 return &sli 1209 } 1210 1211 func (leaf *LeafG) setAddress(ptr any) error { 1212 if ptr == nil { 1213 return leaf.setAddress(newValue(leaf)) 1214 } 1215 1216 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 1217 sli := leaf.unsafeDecayArray(ptr) 1218 switch sli := sli.(type) { 1219 case *[]int64: 1220 return leaf.setAddress(sli) 1221 case *[]uint64: 1222 return leaf.setAddress(sli) 1223 default: 1224 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 1225 } 1226 } 1227 1228 switch v := ptr.(type) { 1229 case *int64: 1230 leaf.ptr = v 1231 case *[]int64: 1232 leaf.sli = v 1233 if *v == nil { 1234 *leaf.sli = make([]int64, 0) 1235 } 1236 case *uint64: 1237 leaf.ptr = (*int64)(unsafe.Pointer(v)) 1238 case *[]uint64: 1239 leaf.sli = (*[]int64)(unsafe.Pointer(v)) 1240 if *v == nil { 1241 *leaf.sli = make([]int64, 0) 1242 } 1243 default: 1244 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 1245 } 1246 return nil 1247 } 1248 1249 func (leaf *LeafG) writeToBuffer(w *rbytes.WBuffer) (int, error) { 1250 if w.Err() != nil { 1251 return 0, w.Err() 1252 } 1253 1254 var nbytes int 1255 switch { 1256 case leaf.ptr != nil: 1257 w.WriteI64(*leaf.ptr) 1258 nbytes += leaf.tleaf.etype 1259 if v := *leaf.ptr; v > leaf.max { 1260 leaf.max = v 1261 } 1262 case leaf.count != nil: 1263 n := leaf.count.ivalue() 1264 max := leaf.count.imax() 1265 if n > max { 1266 n = max 1267 } 1268 end := leaf.tleaf.len * n 1269 w.WriteArrayI64((*leaf.sli)[:end]) 1270 nbytes += leaf.tleaf.etype * end 1271 default: 1272 w.WriteArrayI64((*leaf.sli)[:leaf.tleaf.len]) 1273 nbytes += leaf.tleaf.etype * leaf.tleaf.len 1274 } 1275 1276 return nbytes, w.Err() 1277 } 1278 1279 func init() { 1280 f := func() reflect.Value { 1281 o := &LeafG{} 1282 return reflect.ValueOf(o) 1283 } 1284 rtypes.Factory.Add("TLeafG", f) 1285 } 1286 1287 var ( 1288 _ root.Object = (*LeafG)(nil) 1289 _ root.Named = (*LeafG)(nil) 1290 _ Leaf = (*LeafG)(nil) 1291 _ rbytes.Marshaler = (*LeafG)(nil) 1292 _ rbytes.Unmarshaler = (*LeafG)(nil) 1293 ) 1294 1295 // LeafF implements ROOT TLeafF 1296 type LeafF struct { 1297 rvers int16 1298 tleaf 1299 ptr *float32 1300 sli *[]float32 1301 min float32 1302 max float32 1303 } 1304 1305 func newLeafF(b Branch, name string, shape []int, unsigned bool, count Leaf) *LeafF { 1306 const etype = 4 1307 var lcnt leafCount 1308 if count != nil { 1309 lcnt = count.(leafCount) 1310 } 1311 return &LeafF{ 1312 rvers: rvers.LeafF, 1313 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 1314 } 1315 } 1316 1317 // Class returns the ROOT class name. 1318 func (leaf *LeafF) Class() string { 1319 return "TLeafF" 1320 } 1321 1322 // Minimum returns the minimum value of the leaf. 1323 func (leaf *LeafF) Minimum() float32 { 1324 return leaf.min 1325 } 1326 1327 // Maximum returns the maximum value of the leaf. 1328 func (leaf *LeafF) Maximum() float32 { 1329 return leaf.max 1330 } 1331 1332 // Kind returns the leaf's kind. 1333 func (leaf *LeafF) Kind() reflect.Kind { 1334 return reflect.Float32 1335 } 1336 1337 // Type returns the leaf's type. 1338 func (leaf *LeafF) Type() reflect.Type { 1339 return reflect.TypeFor[float32]() 1340 } 1341 1342 func (leaf *LeafF) TypeName() string { 1343 return "float32" 1344 } 1345 1346 func (leaf *LeafF) MarshalROOT(w *rbytes.WBuffer) (int, error) { 1347 if w.Err() != nil { 1348 return 0, w.Err() 1349 } 1350 1351 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 1352 w.WriteObject(&leaf.tleaf) 1353 w.WriteF32(leaf.min) 1354 w.WriteF32(leaf.max) 1355 1356 return w.SetHeader(hdr) 1357 } 1358 1359 func (leaf *LeafF) UnmarshalROOT(r *rbytes.RBuffer) error { 1360 if r.Err() != nil { 1361 return r.Err() 1362 } 1363 1364 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 1365 leaf.rvers = hdr.Vers 1366 1367 r.ReadObject(&leaf.tleaf) 1368 1369 leaf.min = r.ReadF32() 1370 leaf.max = r.ReadF32() 1371 1372 r.CheckHeader(hdr) 1373 return r.Err() 1374 } 1375 1376 func (leaf *LeafF) readFromBuffer(r *rbytes.RBuffer) error { 1377 if r.Err() != nil { 1378 return r.Err() 1379 } 1380 1381 if leaf.count == nil && leaf.ptr != nil { 1382 *leaf.ptr = r.ReadF32() 1383 } else { 1384 if leaf.count != nil { 1385 n := leaf.count.ivalue() 1386 max := leaf.count.imax() 1387 if n > max { 1388 n = max 1389 } 1390 nn := leaf.tleaf.len * n 1391 *leaf.sli = rbytes.ResizeF32(*leaf.sli, nn) 1392 r.ReadArrayF32(*leaf.sli) 1393 } else { 1394 nn := leaf.tleaf.len 1395 *leaf.sli = rbytes.ResizeF32(*leaf.sli, nn) 1396 r.ReadArrayF32(*leaf.sli) 1397 } 1398 } 1399 return r.Err() 1400 } 1401 1402 func (leaf *LeafF) unsafeDecayArray(ptr any) any { 1403 rv := reflect.ValueOf(ptr).Elem() 1404 sz := rv.Type().Size() / 4 1405 sli := unsafe.Slice((*float32)(unsafe.Pointer(rv.UnsafeAddr())), sz) 1406 return &sli 1407 } 1408 1409 func (leaf *LeafF) setAddress(ptr any) error { 1410 if ptr == nil { 1411 return leaf.setAddress(newValue(leaf)) 1412 } 1413 1414 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 1415 sli := leaf.unsafeDecayArray(ptr) 1416 switch sli := sli.(type) { 1417 case *[]float32: 1418 return leaf.setAddress(sli) 1419 default: 1420 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 1421 } 1422 } 1423 1424 switch v := ptr.(type) { 1425 case *float32: 1426 leaf.ptr = v 1427 case *[]float32: 1428 leaf.sli = v 1429 if *v == nil { 1430 *leaf.sli = make([]float32, 0) 1431 } 1432 default: 1433 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 1434 } 1435 return nil 1436 } 1437 1438 func (leaf *LeafF) writeToBuffer(w *rbytes.WBuffer) (int, error) { 1439 if w.Err() != nil { 1440 return 0, w.Err() 1441 } 1442 1443 var nbytes int 1444 switch { 1445 case leaf.ptr != nil: 1446 w.WriteF32(*leaf.ptr) 1447 nbytes += leaf.tleaf.etype 1448 if v := *leaf.ptr; v > leaf.max { 1449 leaf.max = v 1450 } 1451 case leaf.count != nil: 1452 n := leaf.count.ivalue() 1453 max := leaf.count.imax() 1454 if n > max { 1455 n = max 1456 } 1457 end := leaf.tleaf.len * n 1458 w.WriteArrayF32((*leaf.sli)[:end]) 1459 nbytes += leaf.tleaf.etype * end 1460 default: 1461 w.WriteArrayF32((*leaf.sli)[:leaf.tleaf.len]) 1462 nbytes += leaf.tleaf.etype * leaf.tleaf.len 1463 } 1464 1465 return nbytes, w.Err() 1466 } 1467 1468 func init() { 1469 f := func() reflect.Value { 1470 o := &LeafF{} 1471 return reflect.ValueOf(o) 1472 } 1473 rtypes.Factory.Add("TLeafF", f) 1474 } 1475 1476 var ( 1477 _ root.Object = (*LeafF)(nil) 1478 _ root.Named = (*LeafF)(nil) 1479 _ Leaf = (*LeafF)(nil) 1480 _ rbytes.Marshaler = (*LeafF)(nil) 1481 _ rbytes.Unmarshaler = (*LeafF)(nil) 1482 ) 1483 1484 // LeafD implements ROOT TLeafD 1485 type LeafD struct { 1486 rvers int16 1487 tleaf 1488 ptr *float64 1489 sli *[]float64 1490 min float64 1491 max float64 1492 } 1493 1494 func newLeafD(b Branch, name string, shape []int, unsigned bool, count Leaf) *LeafD { 1495 const etype = 8 1496 var lcnt leafCount 1497 if count != nil { 1498 lcnt = count.(leafCount) 1499 } 1500 return &LeafD{ 1501 rvers: rvers.LeafD, 1502 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 1503 } 1504 } 1505 1506 // Class returns the ROOT class name. 1507 func (leaf *LeafD) Class() string { 1508 return "TLeafD" 1509 } 1510 1511 // Minimum returns the minimum value of the leaf. 1512 func (leaf *LeafD) Minimum() float64 { 1513 return leaf.min 1514 } 1515 1516 // Maximum returns the maximum value of the leaf. 1517 func (leaf *LeafD) Maximum() float64 { 1518 return leaf.max 1519 } 1520 1521 // Kind returns the leaf's kind. 1522 func (leaf *LeafD) Kind() reflect.Kind { 1523 return reflect.Float64 1524 } 1525 1526 // Type returns the leaf's type. 1527 func (leaf *LeafD) Type() reflect.Type { 1528 return reflect.TypeFor[float64]() 1529 } 1530 1531 func (leaf *LeafD) TypeName() string { 1532 return "float64" 1533 } 1534 1535 func (leaf *LeafD) MarshalROOT(w *rbytes.WBuffer) (int, error) { 1536 if w.Err() != nil { 1537 return 0, w.Err() 1538 } 1539 1540 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 1541 w.WriteObject(&leaf.tleaf) 1542 w.WriteF64(leaf.min) 1543 w.WriteF64(leaf.max) 1544 1545 return w.SetHeader(hdr) 1546 } 1547 1548 func (leaf *LeafD) UnmarshalROOT(r *rbytes.RBuffer) error { 1549 if r.Err() != nil { 1550 return r.Err() 1551 } 1552 1553 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 1554 leaf.rvers = hdr.Vers 1555 1556 r.ReadObject(&leaf.tleaf) 1557 1558 leaf.min = r.ReadF64() 1559 leaf.max = r.ReadF64() 1560 1561 r.CheckHeader(hdr) 1562 return r.Err() 1563 } 1564 1565 func (leaf *LeafD) readFromBuffer(r *rbytes.RBuffer) error { 1566 if r.Err() != nil { 1567 return r.Err() 1568 } 1569 1570 if leaf.count == nil && leaf.ptr != nil { 1571 *leaf.ptr = r.ReadF64() 1572 } else { 1573 if leaf.count != nil { 1574 n := leaf.count.ivalue() 1575 max := leaf.count.imax() 1576 if n > max { 1577 n = max 1578 } 1579 nn := leaf.tleaf.len * n 1580 *leaf.sli = rbytes.ResizeF64(*leaf.sli, nn) 1581 r.ReadArrayF64(*leaf.sli) 1582 } else { 1583 nn := leaf.tleaf.len 1584 *leaf.sli = rbytes.ResizeF64(*leaf.sli, nn) 1585 r.ReadArrayF64(*leaf.sli) 1586 } 1587 } 1588 return r.Err() 1589 } 1590 1591 func (leaf *LeafD) unsafeDecayArray(ptr any) any { 1592 rv := reflect.ValueOf(ptr).Elem() 1593 sz := rv.Type().Size() / 8 1594 sli := unsafe.Slice((*float64)(unsafe.Pointer(rv.UnsafeAddr())), sz) 1595 return &sli 1596 } 1597 1598 func (leaf *LeafD) setAddress(ptr any) error { 1599 if ptr == nil { 1600 return leaf.setAddress(newValue(leaf)) 1601 } 1602 1603 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 1604 sli := leaf.unsafeDecayArray(ptr) 1605 switch sli := sli.(type) { 1606 case *[]float64: 1607 return leaf.setAddress(sli) 1608 default: 1609 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 1610 } 1611 } 1612 1613 switch v := ptr.(type) { 1614 case *float64: 1615 leaf.ptr = v 1616 case *[]float64: 1617 leaf.sli = v 1618 if *v == nil { 1619 *leaf.sli = make([]float64, 0) 1620 } 1621 default: 1622 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 1623 } 1624 return nil 1625 } 1626 1627 func (leaf *LeafD) writeToBuffer(w *rbytes.WBuffer) (int, error) { 1628 if w.Err() != nil { 1629 return 0, w.Err() 1630 } 1631 1632 var nbytes int 1633 switch { 1634 case leaf.ptr != nil: 1635 w.WriteF64(*leaf.ptr) 1636 nbytes += leaf.tleaf.etype 1637 if v := *leaf.ptr; v > leaf.max { 1638 leaf.max = v 1639 } 1640 case leaf.count != nil: 1641 n := leaf.count.ivalue() 1642 max := leaf.count.imax() 1643 if n > max { 1644 n = max 1645 } 1646 end := leaf.tleaf.len * n 1647 w.WriteArrayF64((*leaf.sli)[:end]) 1648 nbytes += leaf.tleaf.etype * end 1649 default: 1650 w.WriteArrayF64((*leaf.sli)[:leaf.tleaf.len]) 1651 nbytes += leaf.tleaf.etype * leaf.tleaf.len 1652 } 1653 1654 return nbytes, w.Err() 1655 } 1656 1657 func init() { 1658 f := func() reflect.Value { 1659 o := &LeafD{} 1660 return reflect.ValueOf(o) 1661 } 1662 rtypes.Factory.Add("TLeafD", f) 1663 } 1664 1665 var ( 1666 _ root.Object = (*LeafD)(nil) 1667 _ root.Named = (*LeafD)(nil) 1668 _ Leaf = (*LeafD)(nil) 1669 _ rbytes.Marshaler = (*LeafD)(nil) 1670 _ rbytes.Unmarshaler = (*LeafD)(nil) 1671 ) 1672 1673 // LeafF16 implements ROOT TLeafF16 1674 type LeafF16 struct { 1675 rvers int16 1676 tleaf 1677 ptr *root.Float16 1678 sli *[]root.Float16 1679 min root.Float16 1680 max root.Float16 1681 elm rbytes.StreamerElement 1682 } 1683 1684 func newLeafF16(b Branch, name string, shape []int, unsigned bool, count Leaf, elm rbytes.StreamerElement) *LeafF16 { 1685 const etype = 4 1686 var lcnt leafCount 1687 if count != nil { 1688 lcnt = count.(leafCount) 1689 } 1690 return &LeafF16{ 1691 rvers: rvers.LeafF16, 1692 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 1693 elm: elm, 1694 } 1695 } 1696 1697 // Class returns the ROOT class name. 1698 func (leaf *LeafF16) Class() string { 1699 return "TLeafF16" 1700 } 1701 1702 // Minimum returns the minimum value of the leaf. 1703 func (leaf *LeafF16) Minimum() root.Float16 { 1704 return leaf.min 1705 } 1706 1707 // Maximum returns the maximum value of the leaf. 1708 func (leaf *LeafF16) Maximum() root.Float16 { 1709 return leaf.max 1710 } 1711 1712 // Kind returns the leaf's kind. 1713 func (leaf *LeafF16) Kind() reflect.Kind { 1714 return reflect.Float32 1715 } 1716 1717 // Type returns the leaf's type. 1718 func (leaf *LeafF16) Type() reflect.Type { 1719 return reflect.TypeFor[root.Float16]() 1720 } 1721 1722 func (leaf *LeafF16) TypeName() string { 1723 return "root.Float16" 1724 } 1725 1726 func (leaf *LeafF16) MarshalROOT(w *rbytes.WBuffer) (int, error) { 1727 if w.Err() != nil { 1728 return 0, w.Err() 1729 } 1730 1731 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 1732 w.WriteObject(&leaf.tleaf) 1733 w.WriteF16(leaf.min, leaf.elm) 1734 w.WriteF16(leaf.max, leaf.elm) 1735 1736 return w.SetHeader(hdr) 1737 } 1738 1739 func (leaf *LeafF16) UnmarshalROOT(r *rbytes.RBuffer) error { 1740 if r.Err() != nil { 1741 return r.Err() 1742 } 1743 1744 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 1745 leaf.rvers = hdr.Vers 1746 1747 r.ReadObject(&leaf.tleaf) 1748 1749 leaf.min = r.ReadF16(leaf.elm) 1750 leaf.max = r.ReadF16(leaf.elm) 1751 1752 if strings.Contains(leaf.Title(), "[") { 1753 elm := rdict.Element{ 1754 Name: *rbase.NewNamed(fmt.Sprintf("%s_Element", leaf.Name()), leaf.Title()), 1755 Offset: 0, 1756 Type: rmeta.Float16, 1757 }.New() 1758 leaf.elm = &elm 1759 } 1760 1761 r.CheckHeader(hdr) 1762 return r.Err() 1763 } 1764 1765 func (leaf *LeafF16) readFromBuffer(r *rbytes.RBuffer) error { 1766 if r.Err() != nil { 1767 return r.Err() 1768 } 1769 1770 if leaf.count == nil && leaf.ptr != nil { 1771 *leaf.ptr = r.ReadF16(leaf.elm) 1772 } else { 1773 if leaf.count != nil { 1774 n := leaf.count.ivalue() 1775 max := leaf.count.imax() 1776 if n > max { 1777 n = max 1778 } 1779 nn := leaf.tleaf.len * n 1780 *leaf.sli = rbytes.ResizeF16(*leaf.sli, nn) 1781 r.ReadArrayF16(*leaf.sli, leaf.elm) 1782 } else { 1783 nn := leaf.tleaf.len 1784 *leaf.sli = rbytes.ResizeF16(*leaf.sli, nn) 1785 r.ReadArrayF16(*leaf.sli, leaf.elm) 1786 } 1787 } 1788 return r.Err() 1789 } 1790 1791 func (leaf *LeafF16) unsafeDecayArray(ptr any) any { 1792 rv := reflect.ValueOf(ptr).Elem() 1793 sz := rv.Type().Size() / 4 1794 sli := unsafe.Slice((*root.Float16)(unsafe.Pointer(rv.UnsafeAddr())), sz) 1795 return &sli 1796 } 1797 1798 func (leaf *LeafF16) setAddress(ptr any) error { 1799 if ptr == nil { 1800 return leaf.setAddress(newValue(leaf)) 1801 } 1802 1803 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 1804 sli := leaf.unsafeDecayArray(ptr) 1805 switch sli := sli.(type) { 1806 case *[]root.Float16: 1807 return leaf.setAddress(sli) 1808 default: 1809 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 1810 } 1811 } 1812 1813 switch v := ptr.(type) { 1814 case *root.Float16: 1815 leaf.ptr = v 1816 case *[]root.Float16: 1817 leaf.sli = v 1818 if *v == nil { 1819 *leaf.sli = make([]root.Float16, 0) 1820 } 1821 default: 1822 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 1823 } 1824 return nil 1825 } 1826 1827 func (leaf *LeafF16) writeToBuffer(w *rbytes.WBuffer) (int, error) { 1828 if w.Err() != nil { 1829 return 0, w.Err() 1830 } 1831 1832 var nbytes int 1833 switch { 1834 case leaf.ptr != nil: 1835 w.WriteF16(*leaf.ptr, leaf.elm) 1836 nbytes += leaf.tleaf.etype 1837 if v := *leaf.ptr; v > leaf.max { 1838 leaf.max = v 1839 } 1840 case leaf.count != nil: 1841 n := leaf.count.ivalue() 1842 max := leaf.count.imax() 1843 if n > max { 1844 n = max 1845 } 1846 end := leaf.tleaf.len * n 1847 w.WriteArrayF16((*leaf.sli)[:end], leaf.elm) 1848 nbytes += leaf.tleaf.etype * end 1849 default: 1850 w.WriteArrayF16((*leaf.sli)[:leaf.tleaf.len], leaf.elm) 1851 nbytes += leaf.tleaf.etype * leaf.tleaf.len 1852 } 1853 1854 return nbytes, w.Err() 1855 } 1856 1857 func init() { 1858 f := func() reflect.Value { 1859 o := &LeafF16{} 1860 return reflect.ValueOf(o) 1861 } 1862 rtypes.Factory.Add("TLeafF16", f) 1863 } 1864 1865 var ( 1866 _ root.Object = (*LeafF16)(nil) 1867 _ root.Named = (*LeafF16)(nil) 1868 _ Leaf = (*LeafF16)(nil) 1869 _ rbytes.Marshaler = (*LeafF16)(nil) 1870 _ rbytes.Unmarshaler = (*LeafF16)(nil) 1871 ) 1872 1873 // LeafD32 implements ROOT TLeafD32 1874 type LeafD32 struct { 1875 rvers int16 1876 tleaf 1877 ptr *root.Double32 1878 sli *[]root.Double32 1879 min root.Double32 1880 max root.Double32 1881 elm rbytes.StreamerElement 1882 } 1883 1884 func newLeafD32(b Branch, name string, shape []int, unsigned bool, count Leaf, elm rbytes.StreamerElement) *LeafD32 { 1885 const etype = 8 1886 var lcnt leafCount 1887 if count != nil { 1888 lcnt = count.(leafCount) 1889 } 1890 return &LeafD32{ 1891 rvers: rvers.LeafD32, 1892 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 1893 elm: elm, 1894 } 1895 } 1896 1897 // Class returns the ROOT class name. 1898 func (leaf *LeafD32) Class() string { 1899 return "TLeafD32" 1900 } 1901 1902 // Minimum returns the minimum value of the leaf. 1903 func (leaf *LeafD32) Minimum() root.Double32 { 1904 return leaf.min 1905 } 1906 1907 // Maximum returns the maximum value of the leaf. 1908 func (leaf *LeafD32) Maximum() root.Double32 { 1909 return leaf.max 1910 } 1911 1912 // Kind returns the leaf's kind. 1913 func (leaf *LeafD32) Kind() reflect.Kind { 1914 return reflect.Float64 1915 } 1916 1917 // Type returns the leaf's type. 1918 func (leaf *LeafD32) Type() reflect.Type { 1919 return reflect.TypeFor[root.Double32]() 1920 } 1921 1922 func (leaf *LeafD32) TypeName() string { 1923 return "root.Double32" 1924 } 1925 1926 func (leaf *LeafD32) MarshalROOT(w *rbytes.WBuffer) (int, error) { 1927 if w.Err() != nil { 1928 return 0, w.Err() 1929 } 1930 1931 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 1932 w.WriteObject(&leaf.tleaf) 1933 w.WriteD32(leaf.min, leaf.elm) 1934 w.WriteD32(leaf.max, leaf.elm) 1935 1936 return w.SetHeader(hdr) 1937 } 1938 1939 func (leaf *LeafD32) UnmarshalROOT(r *rbytes.RBuffer) error { 1940 if r.Err() != nil { 1941 return r.Err() 1942 } 1943 1944 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 1945 leaf.rvers = hdr.Vers 1946 1947 r.ReadObject(&leaf.tleaf) 1948 1949 leaf.min = r.ReadD32(leaf.elm) 1950 leaf.max = r.ReadD32(leaf.elm) 1951 1952 if strings.Contains(leaf.Title(), "[") { 1953 elm := rdict.Element{ 1954 Name: *rbase.NewNamed(fmt.Sprintf("%s_Element", leaf.Name()), leaf.Title()), 1955 Offset: 0, 1956 Type: rmeta.Double32, 1957 }.New() 1958 leaf.elm = &elm 1959 } 1960 1961 r.CheckHeader(hdr) 1962 return r.Err() 1963 } 1964 1965 func (leaf *LeafD32) readFromBuffer(r *rbytes.RBuffer) error { 1966 if r.Err() != nil { 1967 return r.Err() 1968 } 1969 1970 if leaf.count == nil && leaf.ptr != nil { 1971 *leaf.ptr = r.ReadD32(leaf.elm) 1972 } else { 1973 if leaf.count != nil { 1974 n := leaf.count.ivalue() 1975 max := leaf.count.imax() 1976 if n > max { 1977 n = max 1978 } 1979 nn := leaf.tleaf.len * n 1980 *leaf.sli = rbytes.ResizeD32(*leaf.sli, nn) 1981 r.ReadArrayD32(*leaf.sli, leaf.elm) 1982 } else { 1983 nn := leaf.tleaf.len 1984 *leaf.sli = rbytes.ResizeD32(*leaf.sli, nn) 1985 r.ReadArrayD32(*leaf.sli, leaf.elm) 1986 } 1987 } 1988 return r.Err() 1989 } 1990 1991 func (leaf *LeafD32) unsafeDecayArray(ptr any) any { 1992 rv := reflect.ValueOf(ptr).Elem() 1993 sz := rv.Type().Size() / 8 1994 sli := unsafe.Slice((*root.Double32)(unsafe.Pointer(rv.UnsafeAddr())), sz) 1995 return &sli 1996 } 1997 1998 func (leaf *LeafD32) setAddress(ptr any) error { 1999 if ptr == nil { 2000 return leaf.setAddress(newValue(leaf)) 2001 } 2002 2003 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 2004 sli := leaf.unsafeDecayArray(ptr) 2005 switch sli := sli.(type) { 2006 case *[]root.Double32: 2007 return leaf.setAddress(sli) 2008 default: 2009 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 2010 } 2011 } 2012 2013 switch v := ptr.(type) { 2014 case *root.Double32: 2015 leaf.ptr = v 2016 case *[]root.Double32: 2017 leaf.sli = v 2018 if *v == nil { 2019 *leaf.sli = make([]root.Double32, 0) 2020 } 2021 default: 2022 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 2023 } 2024 return nil 2025 } 2026 2027 func (leaf *LeafD32) writeToBuffer(w *rbytes.WBuffer) (int, error) { 2028 if w.Err() != nil { 2029 return 0, w.Err() 2030 } 2031 2032 var nbytes int 2033 switch { 2034 case leaf.ptr != nil: 2035 w.WriteD32(*leaf.ptr, leaf.elm) 2036 nbytes += leaf.tleaf.etype 2037 if v := *leaf.ptr; v > leaf.max { 2038 leaf.max = v 2039 } 2040 case leaf.count != nil: 2041 n := leaf.count.ivalue() 2042 max := leaf.count.imax() 2043 if n > max { 2044 n = max 2045 } 2046 end := leaf.tleaf.len * n 2047 w.WriteArrayD32((*leaf.sli)[:end], leaf.elm) 2048 nbytes += leaf.tleaf.etype * end 2049 default: 2050 w.WriteArrayD32((*leaf.sli)[:leaf.tleaf.len], leaf.elm) 2051 nbytes += leaf.tleaf.etype * leaf.tleaf.len 2052 } 2053 2054 return nbytes, w.Err() 2055 } 2056 2057 func init() { 2058 f := func() reflect.Value { 2059 o := &LeafD32{} 2060 return reflect.ValueOf(o) 2061 } 2062 rtypes.Factory.Add("TLeafD32", f) 2063 } 2064 2065 var ( 2066 _ root.Object = (*LeafD32)(nil) 2067 _ root.Named = (*LeafD32)(nil) 2068 _ Leaf = (*LeafD32)(nil) 2069 _ rbytes.Marshaler = (*LeafD32)(nil) 2070 _ rbytes.Unmarshaler = (*LeafD32)(nil) 2071 ) 2072 2073 // LeafC implements ROOT TLeafC 2074 type LeafC struct { 2075 rvers int16 2076 tleaf 2077 ptr *string 2078 sli *[]string 2079 min int32 2080 max int32 2081 } 2082 2083 func newLeafC(b Branch, name string, shape []int, unsigned bool, count Leaf) *LeafC { 2084 const etype = 1 2085 var lcnt leafCount 2086 if count != nil { 2087 lcnt = count.(leafCount) 2088 } 2089 return &LeafC{ 2090 rvers: rvers.LeafC, 2091 tleaf: newLeaf(name, shape, etype, 0, false, unsigned, lcnt, b), 2092 } 2093 } 2094 2095 // Class returns the ROOT class name. 2096 func (leaf *LeafC) Class() string { 2097 return "TLeafC" 2098 } 2099 2100 // Minimum returns the minimum value of the leaf. 2101 func (leaf *LeafC) Minimum() int32 { 2102 return leaf.min 2103 } 2104 2105 // Maximum returns the maximum value of the leaf. 2106 func (leaf *LeafC) Maximum() int32 { 2107 return leaf.max 2108 } 2109 2110 // Kind returns the leaf's kind. 2111 func (leaf *LeafC) Kind() reflect.Kind { 2112 return reflect.String 2113 } 2114 2115 // Type returns the leaf's type. 2116 func (leaf *LeafC) Type() reflect.Type { 2117 return reflect.TypeFor[string]() 2118 } 2119 2120 func (leaf *LeafC) TypeName() string { 2121 return "string" 2122 } 2123 2124 func (leaf *LeafC) MarshalROOT(w *rbytes.WBuffer) (int, error) { 2125 if w.Err() != nil { 2126 return 0, w.Err() 2127 } 2128 2129 hdr := w.WriteHeader(leaf.Class(), leaf.rvers) 2130 w.WriteObject(&leaf.tleaf) 2131 w.WriteI32(leaf.min) 2132 w.WriteI32(leaf.max) 2133 2134 return w.SetHeader(hdr) 2135 } 2136 2137 func (leaf *LeafC) UnmarshalROOT(r *rbytes.RBuffer) error { 2138 if r.Err() != nil { 2139 return r.Err() 2140 } 2141 2142 hdr := r.ReadHeader(leaf.Class(), leaf.RVersion()) 2143 leaf.rvers = hdr.Vers 2144 2145 r.ReadObject(&leaf.tleaf) 2146 2147 leaf.min = r.ReadI32() 2148 leaf.max = r.ReadI32() 2149 2150 r.CheckHeader(hdr) 2151 return r.Err() 2152 } 2153 2154 func (leaf *LeafC) readFromBuffer(r *rbytes.RBuffer) error { 2155 if r.Err() != nil { 2156 return r.Err() 2157 } 2158 2159 if leaf.count == nil && leaf.ptr != nil { 2160 *leaf.ptr = r.ReadString() 2161 } else { 2162 if leaf.count != nil { 2163 n := leaf.count.ivalue() 2164 max := leaf.count.imax() 2165 if n > max { 2166 n = max 2167 } 2168 nn := leaf.tleaf.len * n 2169 *leaf.sli = rbytes.ResizeStr(*leaf.sli, nn) 2170 r.ReadArrayString(*leaf.sli) 2171 } else { 2172 nn := leaf.tleaf.len 2173 *leaf.sli = rbytes.ResizeStr(*leaf.sli, nn) 2174 r.ReadArrayString(*leaf.sli) 2175 } 2176 } 2177 return r.Err() 2178 } 2179 2180 func (leaf *LeafC) unsafeDecayArray(ptr any) any { 2181 rv := reflect.ValueOf(ptr).Elem() 2182 sz := rv.Type().Size() / 16 2183 sli := unsafe.Slice((*string)(unsafe.Pointer(rv.UnsafeAddr())), sz) 2184 return &sli 2185 } 2186 2187 func (leaf *LeafC) setAddress(ptr any) error { 2188 if ptr == nil { 2189 return leaf.setAddress(newValue(leaf)) 2190 } 2191 2192 if rv := reflect.Indirect(reflect.ValueOf(ptr)); rv.Kind() == reflect.Array { 2193 sli := leaf.unsafeDecayArray(ptr) 2194 switch sli := sli.(type) { 2195 case *[]string: 2196 return leaf.setAddress(sli) 2197 default: 2198 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", ptr, leaf.Name(), leaf)) 2199 } 2200 } 2201 2202 switch v := ptr.(type) { 2203 case *string: 2204 leaf.ptr = v 2205 case *[]string: 2206 leaf.sli = v 2207 if *v == nil { 2208 *leaf.sli = make([]string, 0) 2209 } 2210 default: 2211 panic(fmt.Errorf("invalid ptr type %T (leaf=%s|%T)", v, leaf.Name(), leaf)) 2212 } 2213 return nil 2214 } 2215 2216 func (leaf *LeafC) writeToBuffer(w *rbytes.WBuffer) (int, error) { 2217 if w.Err() != nil { 2218 return 0, w.Err() 2219 } 2220 2221 var nbytes int 2222 switch { 2223 case leaf.ptr != nil: 2224 w.WriteString(*leaf.ptr) 2225 sz := len(*leaf.ptr) 2226 nbytes += sz 2227 if v := int32(sz); v >= leaf.max { 2228 leaf.max = v + 1 2229 } 2230 if sz >= leaf.tleaf.len { 2231 leaf.tleaf.len = sz + 1 2232 } 2233 case leaf.count != nil: 2234 n := leaf.count.ivalue() 2235 max := leaf.count.imax() 2236 if n > max { 2237 n = max 2238 } 2239 end := leaf.tleaf.len * n 2240 w.WriteArrayString((*leaf.sli)[:end]) 2241 nbytes += leaf.tleaf.etype * end 2242 default: 2243 w.WriteArrayString((*leaf.sli)[:leaf.tleaf.len]) 2244 nbytes += leaf.tleaf.etype * leaf.tleaf.len 2245 } 2246 2247 return nbytes, w.Err() 2248 } 2249 2250 func init() { 2251 f := func() reflect.Value { 2252 o := &LeafC{} 2253 return reflect.ValueOf(o) 2254 } 2255 rtypes.Factory.Add("TLeafC", f) 2256 } 2257 2258 var ( 2259 _ root.Object = (*LeafC)(nil) 2260 _ root.Named = (*LeafC)(nil) 2261 _ Leaf = (*LeafC)(nil) 2262 _ rbytes.Marshaler = (*LeafC)(nil) 2263 _ rbytes.Unmarshaler = (*LeafC)(nil) 2264 )