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