parent
3d0c541f69
commit
d0529f9c2a
@ -0,0 +1,62 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project atila
|
||||
// Active Thing (activething.com, flags Flags) git.activething.com/go
|
||||
//
|
||||
// File name list_Itemer.go
|
||||
// Created by DEV
|
||||
// Modified 23/01/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License", flags Flags);
|
||||
// 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 packs
|
||||
|
||||
import "time"
|
||||
|
||||
type (
|
||||
|
||||
ListPacker interface {
|
||||
|
||||
ItemAny (value any, flags Flags)
|
||||
|
||||
ItemRaw (value []byte, flags Flags)
|
||||
|
||||
ItemBinary (value []byte, flags Flags)
|
||||
ItemString (value string, flags Flags)
|
||||
|
||||
ItemBool (value bool, flags Flags)
|
||||
|
||||
ItemInt8 (value int8, flags Flags)
|
||||
ItemInt16 (value int16, flags Flags)
|
||||
ItemInt32 (value int32, flags Flags)
|
||||
ItemInt64 (value int64, flags Flags)
|
||||
|
||||
ItemUInt8 (value uint8, flags Flags)
|
||||
ItemUInt16 (value uint16, flags Flags)
|
||||
ItemUInt32 (value uint32, flags Flags)
|
||||
ItemUInt64 (value uint64, flags Flags)
|
||||
|
||||
ItemFloat32 (value float32, flags Flags)
|
||||
ItemFloat64 (value float64, flags Flags)
|
||||
|
||||
ItemDate (value time.Time, flags Flags)
|
||||
|
||||
ItemList (builder func(packer ListPacker, flags Flags), flags Flags)
|
||||
ItemMap (builder func(packer MapPacker , flags Flags), flags Flags)
|
||||
ItemObject(builder func(packer ObjectPacker, flags Flags), flags Flags)
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project atila
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name value_packer.go
|
||||
// Created by DEV
|
||||
// Modified 05/02/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// 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 packs
|
||||
|
||||
import "time"
|
||||
|
||||
type (
|
||||
|
||||
ValuePacker interface {
|
||||
|
||||
PackAny (value any, flags Flags)
|
||||
|
||||
PackRaw (value []byte, flags Flags)
|
||||
PackBinary (value []byte, flags Flags)
|
||||
PackString (value string, flags Flags)
|
||||
|
||||
PackBool (value bool, flags Flags)
|
||||
|
||||
PackInt8 (value int8, flags Flags)
|
||||
PackInt16 (value int16, flags Flags)
|
||||
PackInt32 (value int32, flags Flags)
|
||||
PackInt64 (value int64, flags Flags)
|
||||
|
||||
PackUInt8 (value uint8 , flags Flags)
|
||||
PackUInt16 (value uint16, flags Flags)
|
||||
PackUInt32 (value uint32, flags Flags)
|
||||
PackUInt64 (value uint64, flags Flags)
|
||||
|
||||
PackFloat32 (value float32, flags Flags)
|
||||
PackFloat64 (value float64, flags Flags)
|
||||
|
||||
PackDate (value time.Time, flags Flags)
|
||||
|
||||
PackList (builder func(packer ListPacker , flags Flags), flags Flags)
|
||||
PackMap (builder func(packer MapPacker , flags Flags), flags Flags)
|
||||
PackObject(builder func(packer ObjectPacker, flags Flags), flags Flags)
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,187 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project atila
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name packer_list.go
|
||||
// Created by DEV
|
||||
// Modified 05/02/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// 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 pjson
|
||||
|
||||
import (
|
||||
"activething.com/go/gogo/packs"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
func (p *Packer) ItemAny (value any, flags packs.Flags) { p.addSep(); p.PackAny(value,flags) }
|
||||
|
||||
func (p *Packer) ItemRaw (value []byte, flags packs.Flags) { p.addSep(); packRaw(p.state,value,flags); p.state.Inc() }
|
||||
|
||||
func (p *Packer) ItemBinary (value []byte, flags packs.Flags) { p.addSep(); packBinary(p.state,value,flags); p.state.Inc() }
|
||||
func (p *Packer) ItemString (value string, flags packs.Flags) { p.addSep(); packString(p.state,value,flags); p.state.Inc() }
|
||||
|
||||
func (p *Packer) ItemBool (value bool, flags packs.Flags) { p.addSep(); packBool(p.state,value,flags); p.state.Inc() }
|
||||
|
||||
func (p *Packer) ItemInt8 (value int8 , flags packs.Flags) { p.addSep(); packInt(p.state,int64(value),flags); p.state.Inc() }
|
||||
func (p *Packer) ItemInt16 (value int16, flags packs.Flags) { p.addSep(); packInt(p.state,int64(value),flags); p.state.Inc() }
|
||||
func (p *Packer) ItemInt32 (value int32, flags packs.Flags) { p.addSep(); packInt(p.state,int64(value),flags); p.state.Inc() }
|
||||
func (p *Packer) ItemInt64 (value int64, flags packs.Flags) { p.addSep(); packInt(p.state, value,flags); p.state.Inc() }
|
||||
|
||||
func (p *Packer) ItemUInt8 (value uint8 , flags packs.Flags){ p.addSep(); packUInt(p.state,uint64(value),flags); p.state.Inc() }
|
||||
func (p *Packer) ItemUInt16 (value uint16, flags packs.Flags){ p.addSep(); packUInt(p.state,uint64(value),flags); p.state.Inc() }
|
||||
func (p *Packer) ItemUInt32 (value uint32, flags packs.Flags){ p.addSep(); packUInt(p.state,uint64(value),flags); p.state.Inc() }
|
||||
func (p *Packer) ItemUInt64 (value uint64, flags packs.Flags){ p.addSep(); packUInt(p.state,value,flags); p.state.Inc() }
|
||||
|
||||
func (p *Packer) ItemFloat32 (value float32, flags packs.Flags) { p.addSep(); packFloatString(p.state,float64(value),flags,32); p.state.Inc() }
|
||||
func (p *Packer) ItemFloat64 (value float64, flags packs.Flags) { p.addSep(); packFloatString(p.state,value,flags,64); p.state.Inc() }
|
||||
|
||||
func (p *Packer) ItemDate (value time.Time, flags packs.Flags) { p.addSep(); packDate(p.state,value,flags); p.state.Inc() }
|
||||
|
||||
func (p *Packer) ItemList (builder func(packer packs.ListPacker, flags packs.Flags), flags packs.Flags) {
|
||||
p.addSep()
|
||||
p.PackList(builder,flags)
|
||||
p.state.Inc()
|
||||
}
|
||||
|
||||
func (p *Packer) ItemMap (builder func(packer packs.MapPacker , flags packs.Flags), flags packs.Flags) {}
|
||||
|
||||
func (p *Packer) ItemObject(builder func(packer packs.ObjectPacker, flags packs.Flags), flags packs.Flags) {}
|
||||
|
||||
|
||||
func (p *Packer) addSep () {
|
||||
if p.state.Count() > 0 {
|
||||
p.state.WriteByte(',')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func packListString (state *packs.State, list []string, flags packs.Flags) {
|
||||
if !checkList(state,list == nil, len(list) ==0) {
|
||||
return
|
||||
}
|
||||
state.WriteByte('[')
|
||||
for i,v := range list {
|
||||
if i > 0 {
|
||||
state.WriteByte(',')
|
||||
}
|
||||
packString(state,v,flags)
|
||||
if state.Error != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
state.WriteByte(']')
|
||||
}
|
||||
|
||||
func packListBool (state *packs.State, list []bool, flags packs.Flags) {
|
||||
if !checkList(state,list == nil, len(list) ==0) {
|
||||
return
|
||||
}
|
||||
state.WriteByte('[')
|
||||
for i,v := range list {
|
||||
if i > 0 {
|
||||
state.WriteByte(',')
|
||||
}
|
||||
packBool(state,v,flags)
|
||||
if state.Error != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
state.WriteByte(']')
|
||||
}
|
||||
|
||||
func packListInt [T int | int8 | int16 | int32 | int64](state *packs.State, list []T, flags packs.Flags) {
|
||||
if !checkList(state,list == nil, len(list) ==0) {
|
||||
return
|
||||
}
|
||||
state.WriteByte('[')
|
||||
for i,v := range list {
|
||||
if i > 0 {
|
||||
state.WriteByte(',')
|
||||
}
|
||||
packInt(state,int64(v),flags)
|
||||
if state.Error != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
state.WriteByte(']')
|
||||
}
|
||||
|
||||
func packListUInt [T uint | uint8 | uint16 | uint32 | uint64](state *packs.State, list []T, flags packs.Flags) {
|
||||
if !checkList(state,list == nil, len(list) ==0) {
|
||||
return
|
||||
}
|
||||
state.WriteByte('[')
|
||||
for i,v := range list {
|
||||
if i > 0 {
|
||||
state.WriteByte(',')
|
||||
}
|
||||
packUInt(state,uint64(v),flags)
|
||||
if state.Error != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
state.WriteByte(']')
|
||||
}
|
||||
|
||||
func packListFloat[T float32 | float64](state *packs.State, list []T, flags packs.Flags, bits int) {
|
||||
if !checkList(state,list == nil, len(list) ==0) {
|
||||
return
|
||||
}
|
||||
state.WriteByte('[')
|
||||
for i,v := range list {
|
||||
if i > 0 {
|
||||
state.WriteByte(',')
|
||||
}
|
||||
packFloatString(state,float64(v),flags,bits)
|
||||
if state.Error != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
state.WriteByte(']')
|
||||
}
|
||||
|
||||
func packListDate (state *packs.State, list []time.Time, flags packs.Flags) {
|
||||
if !checkList(state,list == nil, len(list) ==0) {
|
||||
return
|
||||
}
|
||||
state.WriteByte('[')
|
||||
for i,v := range list {
|
||||
if i > 0 {
|
||||
state.WriteByte(',')
|
||||
}
|
||||
packDate(state,v,flags)
|
||||
if state.Error != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
state.WriteByte(']')
|
||||
}
|
||||
|
||||
|
||||
func checkList (state *packs.State, isNull, isEmpty bool) bool {
|
||||
if isNull {
|
||||
state.Write2Byte('"','"')
|
||||
return false
|
||||
}
|
||||
if isEmpty {
|
||||
state.Write2Byte('[',']')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -0,0 +1,166 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project atila
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name rkey.go
|
||||
// Created by DEV
|
||||
// Modified 05/02/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// 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 pjson
|
||||
|
||||
import (
|
||||
"activething.com/go/gogo/packs"
|
||||
"encoding"
|
||||
"math"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func stringifyRKey(rt reflect.Type) rPackerMapEntryFnc {
|
||||
fn,ok := G.keyersCache.Load(rt)
|
||||
if !ok {
|
||||
fn, _ = G.keyersCache.LoadOrStore(rt, _stringifyRKey(rt))
|
||||
}
|
||||
return fn.(rPackerMapEntryFnc)
|
||||
}
|
||||
|
||||
|
||||
func _stringifyRKey(rt reflect.Type) rPackerMapEntryFnc {
|
||||
|
||||
if rt.Kind() == reflect.String {
|
||||
return func(e *rPackerMapEntry, k reflect.Value) error {
|
||||
e.k = k.String()
|
||||
e.f = packs.FlagScapeHTML
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if rt.Implements(G.textMarshalerType) {
|
||||
return func(e *rPackerMapEntry, k reflect.Value) error {
|
||||
if k.Kind() == reflect.Pointer && k.IsNil() {
|
||||
return nil
|
||||
}
|
||||
bf, er := (k.Interface().(encoding.TextMarshaler)).MarshalText()
|
||||
if er == nil {
|
||||
e.k = string(bf)
|
||||
e.f = packs.FlagScapeHTML
|
||||
}
|
||||
return er
|
||||
}
|
||||
}
|
||||
|
||||
switch rt.Kind() {
|
||||
|
||||
case reflect.Int,
|
||||
reflect.Int8,
|
||||
reflect.Int16,
|
||||
reflect.Int32,
|
||||
reflect.Int64:
|
||||
return func(e *rPackerMapEntry, k reflect.Value) error {
|
||||
e.k = strconv.FormatInt(k.Int(), 10)
|
||||
return nil
|
||||
}
|
||||
case reflect.Uint,
|
||||
reflect.Uint8,
|
||||
reflect.Uint16,
|
||||
reflect.Uint32,
|
||||
reflect.Uint64,
|
||||
reflect.Uintptr:
|
||||
return func(e *rPackerMapEntry, k reflect.Value) error {
|
||||
e.k = strconv.FormatUint(k.Uint(), 10)
|
||||
return nil
|
||||
}
|
||||
|
||||
case reflect.Interface:
|
||||
return func(e *rPackerMapEntry, k reflect.Value) error {
|
||||
k = k.Elem()
|
||||
|
||||
if k.Type().Kind() == reflect.String {
|
||||
e.k = k.String()
|
||||
e.f = packs.FlagScapeHTML
|
||||
return nil
|
||||
}
|
||||
|
||||
if t,h := k.Interface().(encoding.TextMarshaler); h {
|
||||
if k.Type().Kind() == reflect.Pointer && k.IsNil() {
|
||||
return nil
|
||||
}
|
||||
bf, er := t.MarshalText()
|
||||
if er == nil {
|
||||
e.k = string(bf)
|
||||
e.f = packs.FlagScapeHTML
|
||||
}
|
||||
return er
|
||||
}
|
||||
|
||||
switch rt.Kind() {
|
||||
|
||||
case reflect.Int,
|
||||
reflect.Int8,
|
||||
reflect.Int16,
|
||||
reflect.Int32,
|
||||
reflect.Int64:
|
||||
e.k = strconv.FormatInt(k.Int(), 10)
|
||||
return nil
|
||||
|
||||
case reflect.Uint,
|
||||
reflect.Uint8,
|
||||
reflect.Uint16,
|
||||
reflect.Uint32,
|
||||
reflect.Uint64,
|
||||
reflect.Uintptr:
|
||||
e.k = strconv.FormatUint(k.Uint(), 10)
|
||||
return nil
|
||||
|
||||
default:
|
||||
return packs.G.ErrInvalidKey
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func stringifyFloat (buffer []byte, f float64, bits int) []byte {
|
||||
if math.IsInf(f, 0) || math.IsNaN(f) {
|
||||
return nil
|
||||
}
|
||||
|
||||
abs := math.Abs(f)
|
||||
fmt := byte('f')
|
||||
|
||||
if abs != 0 {
|
||||
if bits == 64 && (abs < 1e-6 || abs >= 1e21) || bits == 32 && (float32(abs) < 1e-6 || float32(abs) >= 1e21) {
|
||||
fmt = 'e'
|
||||
}
|
||||
}
|
||||
buffer = strconv.AppendFloat(buffer[:0], f, fmt, -1, int(bits))
|
||||
if fmt == 'e' {
|
||||
// clean up e-09 to e-9
|
||||
n := len(buffer)
|
||||
if n >= 4 && buffer[n-4] == 'e' && buffer[n-3] == '-' && buffer[n-2] == '0' {
|
||||
buffer[n-2] = buffer[n-1]
|
||||
buffer = buffer[:n-1]
|
||||
}
|
||||
}
|
||||
return buffer
|
||||
}
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project atila
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name packer_list.go
|
||||
// Created by DEV
|
||||
// Modified 05/02/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// 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 pjson
|
||||
|
||||
import (
|
||||
"activething.com/go/gogo/packs"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
rPackerList struct {
|
||||
packFn rPackerFnc
|
||||
}
|
||||
)
|
||||
|
||||
func newRPackerList (rtype reflect.Type) *rPackerList {
|
||||
return &rPackerList{
|
||||
packFn: rTypePacker(rtype),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (p rPackerList) pack (s *packs.State, v reflect.Value, f packs.Flags) {
|
||||
if v.IsNil() {
|
||||
_,_ = s.Write(G.nullValue)
|
||||
return
|
||||
}
|
||||
if v.Len() == 0 {
|
||||
s.Write2Byte('[',']')
|
||||
return
|
||||
}
|
||||
s.Open('[')
|
||||
for i:=0; i<v.Len(); i++ {
|
||||
if i > 0 {
|
||||
s.WriteByte(',')
|
||||
}
|
||||
p.packFn(s,v.Index(i),f)
|
||||
if s.Error != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
s.Close(']')
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,107 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project atila
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name rpacker_map.go
|
||||
// Created by DEV
|
||||
// Modified 05/02/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// 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 pjson
|
||||
|
||||
import (
|
||||
"activething.com/go/gogo/packs"
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
rPackerMap struct {
|
||||
keyFn rPackerMapEntryFnc
|
||||
packFn rPackerFnc
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
func newRPackerMap (rtype reflect.Type) *rPackerMap {
|
||||
return &rPackerMap{
|
||||
packFn: rTypePacker (rtype.Elem()),
|
||||
keyFn : stringifyRKey(rtype.Key()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (p *rPackerMap) pack (s *packs.State, v reflect.Value, f packs.Flags) {
|
||||
if p.keyFn == nil {
|
||||
s.SetError(packs.G.ErrInvalidKey)
|
||||
return
|
||||
}
|
||||
|
||||
if v.IsNil() {
|
||||
s.W(G.nullValue)
|
||||
return
|
||||
}
|
||||
if v.Len() == 0 {
|
||||
s.Write2Byte('{','}')
|
||||
return
|
||||
}
|
||||
|
||||
if s.Level > startDetectingCyclesAfter {
|
||||
if fn,ok := s.CheckCycle(v.UnsafePointer()); ok {
|
||||
defer fn()
|
||||
} else {
|
||||
s.SetError(packs.G.ErrRedundantPack)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
mi := v.MapRange()
|
||||
ls := make(rPackerMapEntryList,v.Len())
|
||||
|
||||
for i:=0; mi.Next(); i++ {
|
||||
ls[i] = rPackerMapEntry{
|
||||
v: mi.Value(),
|
||||
}
|
||||
if er := p.keyFn(&ls[i], mi.Key()); er != nil {
|
||||
s.SetError(er)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(ls)
|
||||
|
||||
s.Open ('{')
|
||||
for i:=0; i<len(ls); i++ {
|
||||
if i>0 {
|
||||
s.WriteByte(',')
|
||||
}
|
||||
packString(s,ls[i].k,ls[i].f)
|
||||
if s.Error != nil {
|
||||
return
|
||||
}
|
||||
s.WriteByte(':')
|
||||
p.packFn(s,ls[i].v,0)
|
||||
if s.Error != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
s.Close('}')
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue