You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.0 KiB

// ------------------------------------------------------------------------
// 🚀 Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name list_packer.go
// ✍️ Created by DEV
// 📅 Modified 28/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"
"apack/pstate"
"cdcs/cjson"
"time"
)
func packListString (p *Builder, list []string, flags apack.Flags) {
p.makeLevel(pstate.ModeList,list == nil, len(list) == 0,func(b *Builder){
for i,v := range list {
if i > 0 {
p.B.WriteByte(sep)
}
p.packString(v, flags)
if p.Err != nil {
return
}
}
})
}
func packListError (p *Builder, list []error, flags apack.Flags) {
p.makeLevel(pstate.ModeList,list == nil, len(list) == 0,func(b *Builder){
for i,v := range list {
if i > 0 {
p.B.WriteByte(sep)
}
if v == nil {
b.B.WOQ(true,'"',cjson.G.NullValue)
continue
}
p.packString(v.Error(), apack.FlagScapeHTML)
}
})
}
func packListBool (p *Builder, list []bool, flags apack.Flags) {
p.makeLevel(pstate.ModeList,list == nil, len(list) == 0,func(b *Builder){
for i,v := range list {
if i > 0 {
p.B.WriteByte(sep)
}
cjson.WriteBool(p.B,v)
}
})
}
func packListInt [T int | int8 | int16 | int32 | int64 | time.Duration](p *Builder, list []T, flags apack.Flags) {
p.makeLevel(pstate.ModeList,list == nil, len(list) == 0,func(b *Builder){
for i,v := range list {
if i > 0 {
p.B.WriteByte(sep)
}
cjson.WriteInt(p.B,int64(v))
}
})
}
func packListUInt [T uint | uint8 | uint16 | uint32 | uint64|uintptr](p *Builder, list []T, flags apack.Flags) {
p.makeLevel(pstate.ModeList,list == nil, len(list) == 0,func(b *Builder){
for i,v := range list {
if i > 0 {
p.B.WriteByte(sep)
}
cjson.WriteUint(p.B,uint64(v))
}
})
}
func packListFloat[T float32 | float64](p *Builder, list []T, flags apack.Flags, bits int) {
p.makeLevel(pstate.ModeList,list == nil, len(list) == 0,func(b *Builder){
for i,v := range list {
if i > 0 {
p.B.WriteByte(sep)
}
cjson.WriteFloat(p.B,float64(v),bits)
}
})
}
func packListDate (p *Builder, list []time.Time, flags apack.Flags) {
p.makeLevel(pstate.ModeList,list == nil, len(list) == 0,func(b *Builder){
for i,v := range list {
if i > 0 {
p.B.WriteByte(sep)
}
cjson.WriteTime(p.B,v,flags.DateFormat())
}
})
}

Powered by TurnKey Linux.