// ------------------------------------------------------------------------ // 🚀 Project active3 // 🔗 Active Thing (activething.com) git.activething.com/go // // File name reflected_object.go // ✍️ Created by DEV // 📅 Modified 16/05/2024 // // 🔒 Copyright 2024 activething.com // // 📜 LICENSE -------------------------------------------------------------- // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ------------------------------------------------------------------------ package pkjson import ( "apack" "bfrs" "reflect" "sort" ) type ( rObject struct { fields rObjectFields indexes map[string]int } ) func newRObject(rtype reflect.Type) *rObject { cur := rObjectFields{} nxt := rObjectFields{{ rtype: rtype}} var fls rObjectFields var cnt, nxCnt map[reflect.Type]int vis := map[reflect.Type]bool{} nms := bfrs.NewABuffer() for len(nxt) > 0 { cur,nxt = nxt, cur[:0] cnt,nxCnt = nxCnt,map[reflect.Type]int{} for _,f := range cur { if vis[f.rtype] { continue } vis[f.rtype]=true for i:=0; i 1 { fls = append(fls,fls[len(fls)-1]) } continue } nxCnt[ft]++ if nxCnt[ft] == 1 { nxt = append(nxt,rObjectField{ name: ft.Name(), index: index, rtype: ft}) } } } } sort.Slice(fls,func(i,j int) bool { ls := fls if ls[i].name != ls[j].name { return ls[i].name < ls[j].name } if len(ls[i].index) != len(ls[j].index) { return len(ls[i].index) < len(ls[j].index) } if ls[i].isTagged != ls[j].isTagged { return ls[i].isTagged } return ls.Less(i, j) }) out := fls[:0] for ad,i :=0,0; i< len(fls); i += ad { fi := fls[i] nm := fi.name for ad=1; i+ad