// ------------------------------------------------------------------------ // Project atila // Active Thing (activething.com) git.activething.com/go // // File name packs.go // Created by DEV // Modified 27/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 main import ( "activething.com/go/gogo/core/errs" "activething.com/go/gogo/packs/pjson" "fmt" "time" ) func packs_main () { pk := pjson.NewPacker() /* slc2 := [][]int16 {{1,2,3,4},{16,26,36,46}} //slc2:= [][]int16 {{}} slc2 = append(slc2,slc2 ...) pk.PackMap(func(mp packs.MapPacker) { mp.KeyValue("fb0",slc2) mp.KeyValueList("l01",func(l packs.ListPacker){ l.ItemList(func(l1 packs.ListPacker){ l1.ItemUInt64(11) l1.ItemUInt64(22) }) l.ItemList(func(l1 packs.ListPacker){ l1.ItemUInt64(33) l1.ItemUInt64(44) }) }) mp.KeyValueBool("boolean",true) mp.KeyValueFloat32("bf",12223234.34234) mp.KeyValueBinary("binary",[]byte{22,121,21,23,23,54,67}) mp.KeyValueDate("date",time.Now()) mp.KeyValueInt16("una",34) mp.KeyValueObject("MiObjeto",func(op packs.ObjectPacker){ op.FieldInt32("fb1",43433) op.FieldString ("fb2","aaaaa") op.Field("fb3",slc) }) }) */ /* var s = struct { F1Int int F2Uint uint F3String string F4Binary []byte }{ F1Int :-111, F2Uint: 333, F3String: "Esto es un string ", F4Binary: []byte("dklsdjflsdjflsdkfjlsdkfjlsdkfjlsdfjdlsfjsdlf"), } pk.Pack(s) errs.Test(pk.Error(),true) fmt.Printf("JSON \n%s",pk.Bytes()) */ as := 44 mp := map[int]any { 3:"23434434", 1:time.Now(), 4:233, 9:as, 7:[]uint16{2323,2323,2323}, } pk.Pack(mp) errs.Test(pk.Error(),true) fmt.Printf("JSON \n%s",pk.Bytes()) }