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.
144 lines
3.7 KiB
144 lines
3.7 KiB
// ------------------------------------------------------------------------
|
|
// Project atila
|
|
// Active Thing (activething.com) git.activething.com/go
|
|
//
|
|
// File name BuilderObject.go
|
|
// Created by DEV
|
|
// Modified 18/01/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 *Builder) PropAny (name string, value any) {
|
|
if p.addName(name) {
|
|
p.Any(value)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropBinary (name string, value []byte){
|
|
if p.options.IgnoreDefaults() && len(value) == 0 {
|
|
return
|
|
}
|
|
if p.addName(name) {
|
|
p.Binary(value)
|
|
}
|
|
}
|
|
func (p *Builder) PropString (name string, value string){
|
|
if p.options.IgnoreDefaults() && len(value) == 0 {
|
|
return
|
|
}
|
|
if p.addName(name) {
|
|
p.String(value)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropBool (name string, value bool ){
|
|
if p.options.IgnoreDefaults() && !value {
|
|
return
|
|
}
|
|
if p.addName(name) {
|
|
p.Bool(value)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropRune (name string, value rune ){
|
|
if p.options.IgnoreDefaults() && value == 0 {
|
|
return
|
|
}
|
|
if p.addName(name) {
|
|
p.Rune(value)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropInt8 (name string, value int8 ){ p.PropInt64(name, int64(value)) }
|
|
func (p *Builder) PropInt16 (name string, value int16 ){ p.PropInt64(name, int64(value)) }
|
|
func (p *Builder) PropInt32 (name string, value int32 ){ p.PropInt64(name, int64(value)) }
|
|
func (p *Builder) PropInt64 (name string, value int64 ){
|
|
if p.options.IgnoreDefaults() && value == 0 {
|
|
return
|
|
}
|
|
if p.addName(name) {
|
|
p.Int64(value)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropUInt8 (name string, value uint8 ){ p.PropUInt64(name, uint64(value)) }
|
|
func (p *Builder) PropUInt16 (name string, value uint16){ p.PropUInt64(name, uint64(value)) }
|
|
func (p *Builder) PropUInt32 (name string, value uint32){ p.PropUInt64(name, uint64(value)) }
|
|
func (p *Builder) PropUInt64 (name string, value uint64){
|
|
if p.options.IgnoreDefaults() && value == 0 {
|
|
return
|
|
}
|
|
if p.addName(name) {
|
|
p.UInt64(value)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropFloat32(name string, value float32){ p.PropFloat64(name, float64(value)) }
|
|
func (p *Builder) PropFloat64(name string, value float64){
|
|
if p.options.IgnoreDefaults() && value == 0 {
|
|
return
|
|
}
|
|
if p.addName(name) {
|
|
p.Float64(value)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropComplex64 (name string, value complex64 ){ p.PropComplex128(name, complex128(value)) }
|
|
func (p *Builder) PropComplex128(name string, value complex128){
|
|
if p.options.IgnoreDefaults() && value == (0+0i) {
|
|
return
|
|
}
|
|
if p.addName(name) {
|
|
p.Complex128(value)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropDate (name string, value time.Time) {
|
|
if p.options.IgnoreDefaults() && value.IsZero() {
|
|
return
|
|
}
|
|
if p.addName(name) {
|
|
p.Date(value)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropList (name string, builder func(packer packs.BuilderList)) {
|
|
if p.addName(name) {
|
|
p.List(builder)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropMap (name string, builder func(packer packs.BuilderMap)) {
|
|
if p.addName(name) {
|
|
p.Map(builder)
|
|
}
|
|
}
|
|
|
|
func (p *Builder) PropObject(name string, builder func(packer packs.BuilderObject)) {
|
|
if p.addName(name) {
|
|
p.Object(builder)
|
|
}
|
|
}
|
|
|
|
|