How to use MarshalJSON method of lib Package

Best K6 code snippet using lib.MarshalJSON

decode_type.go

Source:decode_type.go Github

copy

Full Screen

...37 }38 if err != nil {39 return nil, err40 }41 bz2, err = codec.MarshalJSON(o)42 if err != nil {43 return nil, err44 }45 return46}47func DecodeIAVLAbsenceOp(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {48 var o iavl.IAVLAbsenceOp49 if lengthPrefixed {50 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)51 } else {52 err = codec.UnmarshalBinaryBare(bz, &o)53 }54 if err != nil {55 return nil, err56 }57 bz2, err = codec.MarshalJSON(o)58 if err != nil {59 return nil, err60 }61 return62}63func DecodeIAVLValueOp(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {64 var o iavl.IAVLValueOp65 if lengthPrefixed {66 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)67 } else {68 err = codec.UnmarshalBinaryBare(bz, &o)69 }70 if err != nil {71 return nil, err72 }73 bz2, err = codec.MarshalJSON(o)74 if err != nil {75 return nil, err76 }77 return78}79func DecodePrivKeyLedgerSecp256k1(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {80 var o crypto.PrivKeyLedgerSecp256k181 if lengthPrefixed {82 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)83 } else {84 err = codec.UnmarshalBinaryBare(bz, &o)85 }86 if err != nil {87 return nil, err88 }89 bz2, err = codec.MarshalJSON(o)90 if err != nil {91 return nil, err92 }93 return94}95func DecodeInfo(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {96 var o keys.Info97 if lengthPrefixed {98 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)99 } else {100 err = codec.UnmarshalBinaryBare(bz, &o)101 }102 if err != nil {103 return nil, err104 }105 bz2, err = codec.MarshalJSON(o)106 if err != nil {107 return nil, err108 }109 return110}111func DecodeBIP44Params(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {112 var o hd.BIP44Params113 if lengthPrefixed {114 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)115 } else {116 err = codec.UnmarshalBinaryBare(bz, &o)117 }118 if err != nil {119 return nil, err120 }121 bz2, err = codec.MarshalJSON(o)122 if err != nil {123 return nil, err124 }125 return126}127func DecodeLocalInfo(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {128 var o keys.LocalInfo129 if lengthPrefixed {130 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)131 } else {132 err = codec.UnmarshalBinaryBare(bz, &o)133 }134 if err != nil {135 return nil, err136 }137 bz2, err = codec.MarshalJSON(o)138 if err != nil {139 return nil, err140 }141 return142}143func DecodeLedgerInfo(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {144 var o keys.LedgerInfo145 if lengthPrefixed {146 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)147 } else {148 err = codec.UnmarshalBinaryBare(bz, &o)149 }150 if err != nil {151 return nil, err152 }153 bz2, err = codec.MarshalJSON(o)154 if err != nil {155 return nil, err156 }157 return158}159func DecodeOfflineInfo(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {160 var o keys.OfflineInfo161 if lengthPrefixed {162 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)163 } else {164 err = codec.UnmarshalBinaryBare(bz, &o)165 }166 if err != nil {167 return nil, err168 }169 bz2, err = codec.MarshalJSON(o)170 if err != nil {171 return nil, err172 }173 return174}175func DecodeMultiInfo(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {176 var o keys.MultiInfo177 if lengthPrefixed {178 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)179 } else {180 err = codec.UnmarshalBinaryBare(bz, &o)181 }182 if err != nil {183 return nil, err184 }185 bz2, err = codec.MarshalJSON(o)186 if err != nil {187 return nil, err188 }189 return190}191func DecodeMsg(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {192 var o types.Msg193 if lengthPrefixed {194 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)195 } else {196 err = codec.UnmarshalBinaryBare(bz, &o)197 }198 if err != nil {199 return nil, err200 }201 bz2, err = codec.MarshalJSON(o)202 if err != nil {203 return nil, err204 }205 return206}207func DecodeTx(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {208 var o types.Tx209 if lengthPrefixed {210 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)211 } else {212 err = codec.UnmarshalBinaryBare(bz, &o)213 }214 if err != nil {215 return nil, err216 }217 bz2, err = codec.MarshalJSON(o)218 if err != nil {219 return nil, err220 }221 return222}223func DecodeAccount(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {224 var o auth.Account225 if lengthPrefixed {226 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)227 } else {228 err = codec.UnmarshalBinaryBare(bz, &o)229 }230 if err != nil {231 return nil, err232 }233 bz2, err = codec.MarshalJSON(o)234 if err != nil {235 return nil, err236 }237 return238}239func DecodeVestingAccount(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {240 var o auth.VestingAccount241 if lengthPrefixed {242 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)243 } else {244 err = codec.UnmarshalBinaryBare(bz, &o)245 }246 if err != nil {247 return nil, err248 }249 bz2, err = codec.MarshalJSON(o)250 if err != nil {251 return nil, err252 }253 return254}255func DecodeBaseAccount(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {256 var o auth.BaseAccount257 if lengthPrefixed {258 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)259 } else {260 err = codec.UnmarshalBinaryBare(bz, &o)261 }262 if err != nil {263 return nil, err264 }265 bz2, err = codec.MarshalJSON(o)266 if err != nil {267 return nil, err268 }269 return270}271func DecodeBaseVestingAccount(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {272 var o auth.BaseVestingAccount273 if lengthPrefixed {274 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)275 } else {276 err = codec.UnmarshalBinaryBare(bz, &o)277 }278 if err != nil {279 return nil, err280 }281 bz2, err = codec.MarshalJSON(o)282 if err != nil {283 return nil, err284 }285 return286}287func DecodeContinuousVestingAccount(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {288 var o auth.ContinuousVestingAccount289 if lengthPrefixed {290 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)291 } else {292 err = codec.UnmarshalBinaryBare(bz, &o)293 }294 if err != nil {295 return nil, err296 }297 bz2, err = codec.MarshalJSON(o)298 if err != nil {299 return nil, err300 }301 return302}303func DecodeDelayedVestingAccount(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {304 var o auth.DelayedVestingAccount305 if lengthPrefixed {306 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)307 } else {308 err = codec.UnmarshalBinaryBare(bz, &o)309 }310 if err != nil {311 return nil, err312 }313 bz2, err = codec.MarshalJSON(o)314 if err != nil {315 return nil, err316 }317 return318}319func DecodeStdTx(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {320 var o auth.StdTx321 if lengthPrefixed {322 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)323 } else {324 err = codec.UnmarshalBinaryBare(bz, &o)325 }326 if err != nil {327 return nil, err328 }329 bz2, err = codec.MarshalJSON(o)330 if err != nil {331 return nil, err332 }333 return334}335func DecodeMsgSend(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {336 var o bank.MsgSend337 if lengthPrefixed {338 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)339 } else {340 err = codec.UnmarshalBinaryBare(bz, &o)341 }342 if err != nil {343 return nil, err344 }345 bz2, err = codec.MarshalJSON(o)346 if err != nil {347 return nil, err348 }349 return350}351func DecodeMsgMultiSend(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {352 var o bank.MsgMultiSend353 if lengthPrefixed {354 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)355 } else {356 err = codec.UnmarshalBinaryBare(bz, &o)357 }358 if err != nil {359 return nil, err360 }361 bz2, err = codec.MarshalJSON(o)362 if err != nil {363 return nil, err364 }365 return366}367func DecodeMsgVerifyInvariant(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {368 var o crisis.MsgVerifyInvariant369 if lengthPrefixed {370 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)371 } else {372 err = codec.UnmarshalBinaryBare(bz, &o)373 }374 if err != nil {375 return nil, err376 }377 bz2, err = codec.MarshalJSON(o)378 if err != nil {379 return nil, err380 }381 return382}383func DecodeMsgWithdrawDelegatorReward(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {384 var o distribution.MsgWithdrawDelegatorReward385 if lengthPrefixed {386 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)387 } else {388 err = codec.UnmarshalBinaryBare(bz, &o)389 }390 if err != nil {391 return nil, err392 }393 bz2, err = codec.MarshalJSON(o)394 if err != nil {395 return nil, err396 }397 return398}399func DecodeMsgWithdrawValidatorCommission(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {400 var o distribution.MsgWithdrawValidatorCommission401 if lengthPrefixed {402 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)403 } else {404 err = codec.UnmarshalBinaryBare(bz, &o)405 }406 if err != nil {407 return nil, err408 }409 bz2, err = codec.MarshalJSON(o)410 if err != nil {411 return nil, err412 }413 return414}415func DecodeMsgSetWithdrawAddress(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {416 var o distribution.MsgSetWithdrawAddress417 if lengthPrefixed {418 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)419 } else {420 err = codec.UnmarshalBinaryBare(bz, &o)421 }422 if err != nil {423 return nil, err424 }425 bz2, err = codec.MarshalJSON(o)426 if err != nil {427 return nil, err428 }429 return430}431func DecodeContent(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {432 var o gov.Content433 if lengthPrefixed {434 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)435 } else {436 err = codec.UnmarshalBinaryBare(bz, &o)437 }438 if err != nil {439 return nil, err440 }441 bz2, err = codec.MarshalJSON(o)442 if err != nil {443 return nil, err444 }445 return446}447func DecodeMsgSubmitProposal(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {448 var o gov.MsgSubmitProposal449 if lengthPrefixed {450 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)451 } else {452 err = codec.UnmarshalBinaryBare(bz, &o)453 }454 if err != nil {455 return nil, err456 }457 bz2, err = codec.MarshalJSON(o)458 if err != nil {459 return nil, err460 }461 return462}463func DecodeMsgDeposit(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {464 var o gov.MsgDeposit465 if lengthPrefixed {466 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)467 } else {468 err = codec.UnmarshalBinaryBare(bz, &o)469 }470 if err != nil {471 return nil, err472 }473 bz2, err = codec.MarshalJSON(o)474 if err != nil {475 return nil, err476 }477 return478}479func DecodeMsgVote(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {480 var o gov.MsgVote481 if lengthPrefixed {482 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)483 } else {484 err = codec.UnmarshalBinaryBare(bz, &o)485 }486 if err != nil {487 return nil, err488 }489 bz2, err = codec.MarshalJSON(o)490 if err != nil {491 return nil, err492 }493 return494}495func DecodeTextProposal(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {496 var o gov.TextProposal497 if lengthPrefixed {498 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)499 } else {500 err = codec.UnmarshalBinaryBare(bz, &o)501 }502 if err != nil {503 return nil, err504 }505 bz2, err = codec.MarshalJSON(o)506 if err != nil {507 return nil, err508 }509 return510}511func DecodeSoftwareUpgradeProposal(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {512 var o gov.SoftwareUpgradeProposal513 if lengthPrefixed {514 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)515 } else {516 err = codec.UnmarshalBinaryBare(bz, &o)517 }518 if err != nil {519 return nil, err520 }521 bz2, err = codec.MarshalJSON(o)522 if err != nil {523 return nil, err524 }525 return526}527func DecodeMsgIBCTransfer(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {528 var o ibc.MsgIBCTransfer529 if lengthPrefixed {530 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)531 } else {532 err = codec.UnmarshalBinaryBare(bz, &o)533 }534 if err != nil {535 return nil, err536 }537 bz2, err = codec.MarshalJSON(o)538 if err != nil {539 return nil, err540 }541 return542}543func DecodeMsgIBCReceive(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {544 var o ibc.MsgIBCReceive545 if lengthPrefixed {546 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)547 } else {548 err = codec.UnmarshalBinaryBare(bz, &o)549 }550 if err != nil {551 return nil, err552 }553 bz2, err = codec.MarshalJSON(o)554 if err != nil {555 return nil, err556 }557 return558}559func DecodeParameterChangeProposal(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {560 var o params.ParameterChangeProposal561 if lengthPrefixed {562 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)563 } else {564 err = codec.UnmarshalBinaryBare(bz, &o)565 }566 if err != nil {567 return nil, err568 }569 bz2, err = codec.MarshalJSON(o)570 if err != nil {571 return nil, err572 }573 return574}575func DecodeMsgUnjail(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {576 var o slashing.MsgUnjail577 if lengthPrefixed {578 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)579 } else {580 err = codec.UnmarshalBinaryBare(bz, &o)581 }582 if err != nil {583 return nil, err584 }585 bz2, err = codec.MarshalJSON(o)586 if err != nil {587 return nil, err588 }589 return590}591func DecodeMsgCreateValidator(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {592 var o staking.MsgCreateValidator593 if lengthPrefixed {594 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)595 } else {596 err = codec.UnmarshalBinaryBare(bz, &o)597 }598 if err != nil {599 return nil, err600 }601 bz2, err = codec.MarshalJSON(o)602 if err != nil {603 return nil, err604 }605 return606}607func DecodeMsgEditValidator(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {608 var o staking.MsgEditValidator609 if lengthPrefixed {610 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)611 } else {612 err = codec.UnmarshalBinaryBare(bz, &o)613 }614 if err != nil {615 return nil, err616 }617 bz2, err = codec.MarshalJSON(o)618 if err != nil {619 return nil, err620 }621 return622}623func DecodeMsgDelegate(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {624 var o staking.MsgDelegate625 if lengthPrefixed {626 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)627 } else {628 err = codec.UnmarshalBinaryBare(bz, &o)629 }630 if err != nil {631 return nil, err632 }633 bz2, err = codec.MarshalJSON(o)634 if err != nil {635 return nil, err636 }637 return638}639func DecodeMsgUndelegate(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {640 var o staking.MsgUndelegate641 if lengthPrefixed {642 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)643 } else {644 err = codec.UnmarshalBinaryBare(bz, &o)645 }646 if err != nil {647 return nil, err648 }649 bz2, err = codec.MarshalJSON(o)650 if err != nil {651 return nil, err652 }653 return654}655func DecodeMsgBeginRedelegate(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {656 var o staking.MsgBeginRedelegate657 if lengthPrefixed {658 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)659 } else {660 err = codec.UnmarshalBinaryBare(bz, &o)661 }662 if err != nil {663 return nil, err664 }665 bz2, err = codec.MarshalJSON(o)666 if err != nil {667 return nil, err668 }669 return670}671func DecodeBlockchainMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {672 var o tm_blockchain.BlockchainMessage673 if lengthPrefixed {674 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)675 } else {676 err = codec.UnmarshalBinaryBare(bz, &o)677 }678 if err != nil {679 return nil, err680 }681 bz2, err = codec.MarshalJSON(o)682 if err != nil {683 return nil, err684 }685 return686}687func DecodeBcBlockRequestMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {688 var o tm_blockchain.BcBlockRequestMessage689 if lengthPrefixed {690 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)691 } else {692 err = codec.UnmarshalBinaryBare(bz, &o)693 }694 if err != nil {695 return nil, err696 }697 bz2, err = codec.MarshalJSON(o)698 if err != nil {699 return nil, err700 }701 return702}703func DecodeBcBlockResponseMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {704 var o tm_blockchain.BcBlockResponseMessage705 if lengthPrefixed {706 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)707 } else {708 err = codec.UnmarshalBinaryBare(bz, &o)709 }710 if err != nil {711 return nil, err712 }713 bz2, err = codec.MarshalJSON(o)714 if err != nil {715 return nil, err716 }717 return718}719func DecodeBcNoBlockResponseMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {720 var o tm_blockchain.BcNoBlockResponseMessage721 if lengthPrefixed {722 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)723 } else {724 err = codec.UnmarshalBinaryBare(bz, &o)725 }726 if err != nil {727 return nil, err728 }729 bz2, err = codec.MarshalJSON(o)730 if err != nil {731 return nil, err732 }733 return734}735func DecodeBcStatusResponseMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {736 var o tm_blockchain.BcStatusResponseMessage737 if lengthPrefixed {738 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)739 } else {740 err = codec.UnmarshalBinaryBare(bz, &o)741 }742 if err != nil {743 return nil, err744 }745 bz2, err = codec.MarshalJSON(o)746 if err != nil {747 return nil, err748 }749 return750}751func DecodeBcStatusRequestMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {752 var o tm_blockchain.BcStatusRequestMessage753 if lengthPrefixed {754 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)755 } else {756 err = codec.UnmarshalBinaryBare(bz, &o)757 }758 if err != nil {759 return nil, err760 }761 bz2, err = codec.MarshalJSON(o)762 if err != nil {763 return nil, err764 }765 return766}767func DecodeConsensusMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {768 var o tm_consensus.ConsensusMessage769 if lengthPrefixed {770 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)771 } else {772 err = codec.UnmarshalBinaryBare(bz, &o)773 }774 if err != nil {775 return nil, err776 }777 bz2, err = codec.MarshalJSON(o)778 if err != nil {779 return nil, err780 }781 return782}783func DecodeNewRoundStepMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {784 var o tm_consensus.NewRoundStepMessage785 if lengthPrefixed {786 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)787 } else {788 err = codec.UnmarshalBinaryBare(bz, &o)789 }790 if err != nil {791 return nil, err792 }793 bz2, err = codec.MarshalJSON(o)794 if err != nil {795 return nil, err796 }797 return798}799func DecodeNewValidBlockMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {800 var o tm_consensus.NewValidBlockMessage801 if lengthPrefixed {802 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)803 } else {804 err = codec.UnmarshalBinaryBare(bz, &o)805 }806 if err != nil {807 return nil, err808 }809 bz2, err = codec.MarshalJSON(o)810 if err != nil {811 return nil, err812 }813 return814}815func DecodeProposalMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {816 var o tm_consensus.ProposalMessage817 if lengthPrefixed {818 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)819 } else {820 err = codec.UnmarshalBinaryBare(bz, &o)821 }822 if err != nil {823 return nil, err824 }825 bz2, err = codec.MarshalJSON(o)826 if err != nil {827 return nil, err828 }829 return830}831func DecodeProposalPOLMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {832 var o tm_consensus.ProposalPOLMessage833 if lengthPrefixed {834 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)835 } else {836 err = codec.UnmarshalBinaryBare(bz, &o)837 }838 if err != nil {839 return nil, err840 }841 bz2, err = codec.MarshalJSON(o)842 if err != nil {843 return nil, err844 }845 return846}847func DecodeBlockPartMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {848 var o tm_consensus.BlockPartMessage849 if lengthPrefixed {850 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)851 } else {852 err = codec.UnmarshalBinaryBare(bz, &o)853 }854 if err != nil {855 return nil, err856 }857 bz2, err = codec.MarshalJSON(o)858 if err != nil {859 return nil, err860 }861 return862}863func DecodeVoteMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {864 var o tm_consensus.VoteMessage865 if lengthPrefixed {866 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)867 } else {868 err = codec.UnmarshalBinaryBare(bz, &o)869 }870 if err != nil {871 return nil, err872 }873 bz2, err = codec.MarshalJSON(o)874 if err != nil {875 return nil, err876 }877 return878}879func DecodeHasVoteMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {880 var o tm_consensus.HasVoteMessage881 if lengthPrefixed {882 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)883 } else {884 err = codec.UnmarshalBinaryBare(bz, &o)885 }886 if err != nil {887 return nil, err888 }889 bz2, err = codec.MarshalJSON(o)890 if err != nil {891 return nil, err892 }893 return894}895func DecodeVoteSetMaj23Message(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {896 var o tm_consensus.VoteSetMaj23Message897 if lengthPrefixed {898 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)899 } else {900 err = codec.UnmarshalBinaryBare(bz, &o)901 }902 if err != nil {903 return nil, err904 }905 bz2, err = codec.MarshalJSON(o)906 if err != nil {907 return nil, err908 }909 return910}911func DecodeVoteSetBitsMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {912 var o tm_consensus.VoteSetBitsMessage913 if lengthPrefixed {914 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)915 } else {916 err = codec.UnmarshalBinaryBare(bz, &o)917 }918 if err != nil {919 return nil, err920 }921 bz2, err = codec.MarshalJSON(o)922 if err != nil {923 return nil, err924 }925 return926}927func DecodeWALMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {928 var o tm_consensus.WALMessage929 if lengthPrefixed {930 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)931 } else {932 err = codec.UnmarshalBinaryBare(bz, &o)933 }934 if err != nil {935 return nil, err936 }937 bz2, err = codec.MarshalJSON(o)938 if err != nil {939 return nil, err940 }941 return942}943func DecodeMsgInfo(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {944 var o tm_consensus.MsgInfo945 if lengthPrefixed {946 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)947 } else {948 err = codec.UnmarshalBinaryBare(bz, &o)949 }950 if err != nil {951 return nil, err952 }953 bz2, err = codec.MarshalJSON(o)954 if err != nil {955 return nil, err956 }957 return958}959func DecodeTimeoutInfo(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {960 var o tm_consensus.TimeoutInfo961 if lengthPrefixed {962 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)963 } else {964 err = codec.UnmarshalBinaryBare(bz, &o)965 }966 if err != nil {967 return nil, err968 }969 bz2, err = codec.MarshalJSON(o)970 if err != nil {971 return nil, err972 }973 return974}975func DecodeEndHeightMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {976 var o tm_consensus.EndHeightMessage977 if lengthPrefixed {978 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)979 } else {980 err = codec.UnmarshalBinaryBare(bz, &o)981 }982 if err != nil {983 return nil, err984 }985 bz2, err = codec.MarshalJSON(o)986 if err != nil {987 return nil, err988 }989 return990}991func DecodePubKey(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {992 var o tm_crypto.PubKey993 if lengthPrefixed {994 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)995 } else {996 err = codec.UnmarshalBinaryBare(bz, &o)997 }998 if err != nil {999 return nil, err1000 }1001 bz2, err = codec.MarshalJSON(o)1002 if err != nil {1003 return nil, err1004 }1005 return1006}1007func DecodePrivKey(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1008 var o tm_crypto.PrivKey1009 if lengthPrefixed {1010 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1011 } else {1012 err = codec.UnmarshalBinaryBare(bz, &o)1013 }1014 if err != nil {1015 return nil, err1016 }1017 bz2, err = codec.MarshalJSON(o)1018 if err != nil {1019 return nil, err1020 }1021 return1022}1023func DecodePubKeyEd25519(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1024 var o tm_ed25519.PubKeyEd255191025 if lengthPrefixed {1026 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1027 } else {1028 err = codec.UnmarshalBinaryBare(bz, &o)1029 }1030 if err != nil {1031 return nil, err1032 }1033 bz2, err = codec.MarshalJSON(o)1034 if err != nil {1035 return nil, err1036 }1037 return1038}1039func DecodePrivKeyEd25519(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1040 var o tm_ed25519.PrivKeyEd255191041 if lengthPrefixed {1042 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1043 } else {1044 err = codec.UnmarshalBinaryBare(bz, &o)1045 }1046 if err != nil {1047 return nil, err1048 }1049 bz2, err = codec.MarshalJSON(o)1050 if err != nil {1051 return nil, err1052 }1053 return1054}1055func DecodePubKeySecp256k1(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1056 var o tm_secp256k1.PubKeySecp256k11057 if lengthPrefixed {1058 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1059 } else {1060 err = codec.UnmarshalBinaryBare(bz, &o)1061 }1062 if err != nil {1063 return nil, err1064 }1065 bz2, err = codec.MarshalJSON(o)1066 if err != nil {1067 return nil, err1068 }1069 return1070}1071func DecodePrivKeySecp256k1(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1072 var o tm_secp256k1.PrivKeySecp256k11073 if lengthPrefixed {1074 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1075 } else {1076 err = codec.UnmarshalBinaryBare(bz, &o)1077 }1078 if err != nil {1079 return nil, err1080 }1081 bz2, err = codec.MarshalJSON(o)1082 if err != nil {1083 return nil, err1084 }1085 return1086}1087func DecodePubKeyMultisigThreshold(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1088 var o tm_multisig.PubKeyMultisigThreshold1089 if lengthPrefixed {1090 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1091 } else {1092 err = codec.UnmarshalBinaryBare(bz, &o)1093 }1094 if err != nil {1095 return nil, err1096 }1097 bz2, err = codec.MarshalJSON(o)1098 if err != nil {1099 return nil, err1100 }1101 return1102}1103func DecodeEvidenceMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1104 var o tm_evidence.EvidenceMessage1105 if lengthPrefixed {1106 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1107 } else {1108 err = codec.UnmarshalBinaryBare(bz, &o)1109 }1110 if err != nil {1111 return nil, err1112 }1113 bz2, err = codec.MarshalJSON(o)1114 if err != nil {1115 return nil, err1116 }1117 return1118}1119func DecodeEvidenceListMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1120 var o tm_evidence.EvidenceListMessage1121 if lengthPrefixed {1122 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1123 } else {1124 err = codec.UnmarshalBinaryBare(bz, &o)1125 }1126 if err != nil {1127 return nil, err1128 }1129 bz2, err = codec.MarshalJSON(o)1130 if err != nil {1131 return nil, err1132 }1133 return1134}1135func DecodeMempoolMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1136 var o tm_mempool.MempoolMessage1137 if lengthPrefixed {1138 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1139 } else {1140 err = codec.UnmarshalBinaryBare(bz, &o)1141 }1142 if err != nil {1143 return nil, err1144 }1145 bz2, err = codec.MarshalJSON(o)1146 if err != nil {1147 return nil, err1148 }1149 return1150}1151func DecodeTxMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1152 var o tm_mempool.TxMessage1153 if lengthPrefixed {1154 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1155 } else {1156 err = codec.UnmarshalBinaryBare(bz, &o)1157 }1158 if err != nil {1159 return nil, err1160 }1161 bz2, err = codec.MarshalJSON(o)1162 if err != nil {1163 return nil, err1164 }1165 return1166}1167func DecodePacket(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1168 var o tm_conn.Packet1169 if lengthPrefixed {1170 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1171 } else {1172 err = codec.UnmarshalBinaryBare(bz, &o)1173 }1174 if err != nil {1175 return nil, err1176 }1177 bz2, err = codec.MarshalJSON(o)1178 if err != nil {1179 return nil, err1180 }1181 return1182}1183func DecodePacketPing(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1184 var o tm_conn.PacketPing1185 if lengthPrefixed {1186 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1187 } else {1188 err = codec.UnmarshalBinaryBare(bz, &o)1189 }1190 if err != nil {1191 return nil, err1192 }1193 bz2, err = codec.MarshalJSON(o)1194 if err != nil {1195 return nil, err1196 }1197 return1198}1199func DecodePacketPong(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1200 var o tm_conn.PacketPong1201 if lengthPrefixed {1202 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1203 } else {1204 err = codec.UnmarshalBinaryBare(bz, &o)1205 }1206 if err != nil {1207 return nil, err1208 }1209 bz2, err = codec.MarshalJSON(o)1210 if err != nil {1211 return nil, err1212 }1213 return1214}1215func DecodePacketMsg(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1216 var o tm_conn.PacketMsg1217 if lengthPrefixed {1218 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1219 } else {1220 err = codec.UnmarshalBinaryBare(bz, &o)1221 }1222 if err != nil {1223 return nil, err1224 }1225 bz2, err = codec.MarshalJSON(o)1226 if err != nil {1227 return nil, err1228 }1229 return1230}1231func DecodePexMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1232 var o tm_pex.PexMessage1233 if lengthPrefixed {1234 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1235 } else {1236 err = codec.UnmarshalBinaryBare(bz, &o)1237 }1238 if err != nil {1239 return nil, err1240 }1241 bz2, err = codec.MarshalJSON(o)1242 if err != nil {1243 return nil, err1244 }1245 return1246}1247func DecodePexRequestMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1248 var o tm_pex.PexRequestMessage1249 if lengthPrefixed {1250 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1251 } else {1252 err = codec.UnmarshalBinaryBare(bz, &o)1253 }1254 if err != nil {1255 return nil, err1256 }1257 bz2, err = codec.MarshalJSON(o)1258 if err != nil {1259 return nil, err1260 }1261 return1262}1263func DecodePexAddrsMessage(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1264 var o tm_pex.PexAddrsMessage1265 if lengthPrefixed {1266 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1267 } else {1268 err = codec.UnmarshalBinaryBare(bz, &o)1269 }1270 if err != nil {1271 return nil, err1272 }1273 bz2, err = codec.MarshalJSON(o)1274 if err != nil {1275 return nil, err1276 }1277 return1278}1279func DecodeRemoteSignerMsg(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1280 var o tm_privval.RemoteSignerMsg1281 if lengthPrefixed {1282 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1283 } else {1284 err = codec.UnmarshalBinaryBare(bz, &o)1285 }1286 if err != nil {1287 return nil, err1288 }1289 bz2, err = codec.MarshalJSON(o)1290 if err != nil {1291 return nil, err1292 }1293 return1294}1295func DecodePubKeyRequest(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1296 var o tm_privval.PubKeyRequest1297 if lengthPrefixed {1298 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1299 } else {1300 err = codec.UnmarshalBinaryBare(bz, &o)1301 }1302 if err != nil {1303 return nil, err1304 }1305 bz2, err = codec.MarshalJSON(o)1306 if err != nil {1307 return nil, err1308 }1309 return1310}1311func DecodePubKeyResponse(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1312 var o tm_privval.PubKeyResponse1313 if lengthPrefixed {1314 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1315 } else {1316 err = codec.UnmarshalBinaryBare(bz, &o)1317 }1318 if err != nil {1319 return nil, err1320 }1321 bz2, err = codec.MarshalJSON(o)1322 if err != nil {1323 return nil, err1324 }1325 return1326}1327func DecodeSignVoteRequest(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1328 var o tm_privval.SignVoteRequest1329 if lengthPrefixed {1330 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1331 } else {1332 err = codec.UnmarshalBinaryBare(bz, &o)1333 }1334 if err != nil {1335 return nil, err1336 }1337 bz2, err = codec.MarshalJSON(o)1338 if err != nil {1339 return nil, err1340 }1341 return1342}1343func DecodeSignedVoteResponse(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1344 var o tm_privval.SignedVoteResponse1345 if lengthPrefixed {1346 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1347 } else {1348 err = codec.UnmarshalBinaryBare(bz, &o)1349 }1350 if err != nil {1351 return nil, err1352 }1353 bz2, err = codec.MarshalJSON(o)1354 if err != nil {1355 return nil, err1356 }1357 return1358}1359func DecodeSignProposalRequest(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1360 var o tm_privval.SignProposalRequest1361 if lengthPrefixed {1362 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1363 } else {1364 err = codec.UnmarshalBinaryBare(bz, &o)1365 }1366 if err != nil {1367 return nil, err1368 }1369 bz2, err = codec.MarshalJSON(o)1370 if err != nil {1371 return nil, err1372 }1373 return1374}1375func DecodeSignedProposalResponse(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1376 var o tm_privval.SignedProposalResponse1377 if lengthPrefixed {1378 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1379 } else {1380 err = codec.UnmarshalBinaryBare(bz, &o)1381 }1382 if err != nil {1383 return nil, err1384 }1385 bz2, err = codec.MarshalJSON(o)1386 if err != nil {1387 return nil, err1388 }1389 return1390}1391func DecodePingRequest(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1392 var o tm_privval.PingRequest1393 if lengthPrefixed {1394 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1395 } else {1396 err = codec.UnmarshalBinaryBare(bz, &o)1397 }1398 if err != nil {1399 return nil, err1400 }1401 bz2, err = codec.MarshalJSON(o)1402 if err != nil {1403 return nil, err1404 }1405 return1406}1407func DecodePingResponse(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1408 var o tm_privval.PingResponse1409 if lengthPrefixed {1410 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1411 } else {1412 err = codec.UnmarshalBinaryBare(bz, &o)1413 }1414 if err != nil {1415 return nil, err1416 }1417 bz2, err = codec.MarshalJSON(o)1418 if err != nil {1419 return nil, err1420 }1421 return1422}1423func DecodeTMEventData(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1424 var o tm_types.TMEventData1425 if lengthPrefixed {1426 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1427 } else {1428 err = codec.UnmarshalBinaryBare(bz, &o)1429 }1430 if err != nil {1431 return nil, err1432 }1433 bz2, err = codec.MarshalJSON(o)1434 if err != nil {1435 return nil, err1436 }1437 return1438}1439func DecodeEventDataNewBlock(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1440 var o tm_types.EventDataNewBlock1441 if lengthPrefixed {1442 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1443 } else {1444 err = codec.UnmarshalBinaryBare(bz, &o)1445 }1446 if err != nil {1447 return nil, err1448 }1449 bz2, err = codec.MarshalJSON(o)1450 if err != nil {1451 return nil, err1452 }1453 return1454}1455func DecodeEventDataNewBlockHeader(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1456 var o tm_types.EventDataNewBlockHeader1457 if lengthPrefixed {1458 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1459 } else {1460 err = codec.UnmarshalBinaryBare(bz, &o)1461 }1462 if err != nil {1463 return nil, err1464 }1465 bz2, err = codec.MarshalJSON(o)1466 if err != nil {1467 return nil, err1468 }1469 return1470}1471func DecodeEventDataTx(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1472 var o tm_types.EventDataTx1473 if lengthPrefixed {1474 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1475 } else {1476 err = codec.UnmarshalBinaryBare(bz, &o)1477 }1478 if err != nil {1479 return nil, err1480 }1481 bz2, err = codec.MarshalJSON(o)1482 if err != nil {1483 return nil, err1484 }1485 return1486}1487func DecodeEventDataRoundState(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1488 var o tm_types.EventDataRoundState1489 if lengthPrefixed {1490 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1491 } else {1492 err = codec.UnmarshalBinaryBare(bz, &o)1493 }1494 if err != nil {1495 return nil, err1496 }1497 bz2, err = codec.MarshalJSON(o)1498 if err != nil {1499 return nil, err1500 }1501 return1502}1503func DecodeEventDataNewRound(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1504 var o tm_types.EventDataNewRound1505 if lengthPrefixed {1506 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1507 } else {1508 err = codec.UnmarshalBinaryBare(bz, &o)1509 }1510 if err != nil {1511 return nil, err1512 }1513 bz2, err = codec.MarshalJSON(o)1514 if err != nil {1515 return nil, err1516 }1517 return1518}1519func DecodeEventDataCompleteProposal(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1520 var o tm_types.EventDataCompleteProposal1521 if lengthPrefixed {1522 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1523 } else {1524 err = codec.UnmarshalBinaryBare(bz, &o)1525 }1526 if err != nil {1527 return nil, err1528 }1529 bz2, err = codec.MarshalJSON(o)1530 if err != nil {1531 return nil, err1532 }1533 return1534}1535func DecodeEventDataVote(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1536 var o tm_types.EventDataVote1537 if lengthPrefixed {1538 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1539 } else {1540 err = codec.UnmarshalBinaryBare(bz, &o)1541 }1542 if err != nil {1543 return nil, err1544 }1545 bz2, err = codec.MarshalJSON(o)1546 if err != nil {1547 return nil, err1548 }1549 return1550}1551func DecodeEventDataValidatorSetUpdates(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1552 var o tm_types.EventDataValidatorSetUpdates1553 if lengthPrefixed {1554 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1555 } else {1556 err = codec.UnmarshalBinaryBare(bz, &o)1557 }1558 if err != nil {1559 return nil, err1560 }1561 bz2, err = codec.MarshalJSON(o)1562 if err != nil {1563 return nil, err1564 }1565 return1566}1567func DecodeEventDataString(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1568 var o tm_types.EventDataString1569 if lengthPrefixed {1570 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1571 } else {1572 err = codec.UnmarshalBinaryBare(bz, &o)1573 }1574 if err != nil {1575 return nil, err1576 }1577 bz2, err = codec.MarshalJSON(o)1578 if err != nil {1579 return nil, err1580 }1581 return1582}1583func DecodeEvidence(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1584 var o tm_types.Evidence1585 if lengthPrefixed {1586 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1587 } else {1588 err = codec.UnmarshalBinaryBare(bz, &o)1589 }1590 if err != nil {1591 return nil, err1592 }1593 bz2, err = codec.MarshalJSON(o)1594 if err != nil {1595 return nil, err1596 }1597 return1598}1599func DecodeDuplicateVoteEvidence(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1600 var o tm_types.DuplicateVoteEvidence1601 if lengthPrefixed {1602 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1603 } else {1604 err = codec.UnmarshalBinaryBare(bz, &o)1605 }1606 if err != nil {1607 return nil, err1608 }1609 bz2, err = codec.MarshalJSON(o)1610 if err != nil {1611 return nil, err1612 }1613 return1614}1615func DecodeMockGoodEvidence(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1616 var o tm_types.MockGoodEvidence1617 if lengthPrefixed {1618 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1619 } else {1620 err = codec.UnmarshalBinaryBare(bz, &o)1621 }1622 if err != nil {1623 return nil, err1624 }1625 bz2, err = codec.MarshalJSON(o)1626 if err != nil {1627 return nil, err1628 }1629 return1630}1631func DecodeMockRandomGoodEvidence(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1632 var o tm_types.MockRandomGoodEvidence1633 if lengthPrefixed {1634 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1635 } else {1636 err = codec.UnmarshalBinaryBare(bz, &o)1637 }1638 if err != nil {1639 return nil, err1640 }1641 bz2, err = codec.MarshalJSON(o)1642 if err != nil {1643 return nil, err1644 }1645 return1646}1647func DecodeMockBadEvidence(bz []byte, lengthPrefixed bool) (bz2 []byte, err error) {1648 var o tm_types.MockBadEvidence1649 if lengthPrefixed {1650 err = codec.UnmarshalBinaryLengthPrefixed(bz, &o)1651 } else {1652 err = codec.UnmarshalBinaryBare(bz, &o)1653 }1654 if err != nil {1655 return nil, err1656 }1657 bz2, err = codec.MarshalJSON(o)1658 if err != nil {1659 return nil, err1660 }1661 return1662}...

Full Screen

Full Screen

JsonRpcEncoder.go

Source:JsonRpcEncoder.go Github

copy

Full Screen

...90}91func NewRedactedSecretValueSerializer() *RedactedSecretValueSerializer {92 return &RedactedSecretValueSerializer{}93}94func (rss *RedactedSecretValueSerializer) MarshalJSON() ([]byte, error) {95 var result = map[string]interface{}{}96 result["SECRET"] = "*redacted*"97 return json.Marshal(result)98}99type SecretValueSerializer struct {100 secretValue *data.SecretValue101}102func (svs *SecretValueSerializer) MarshalJSON() ([]byte, error) {103 var result = map[string]interface{}{}104 result["SECRET"] = svs.secretValue.Value()105 return json.Marshal(result)106}107func NewSecretValueSerializer(value *data.SecretValue) *SecretValueSerializer {108 return &SecretValueSerializer{secretValue: value}109}110type BlobValueSerializer struct {111 blobValue *data.BlobValue112}113func (bvs *BlobValueSerializer) MarshalJSON() ([]byte, error) {114 var result = map[string]interface{}{}115 base64EncodedString := base64.StdEncoding.EncodeToString(bvs.blobValue.Value())116 result["BINARY"] = base64EncodedString117 return json.Marshal(result)118}119func NewBlobValueSerializer(value *data.BlobValue) *BlobValueSerializer {120 return &BlobValueSerializer{blobValue: value}121}122type JsonRpcRequestErrorSerializer struct {123 jsonRpcRequestError *JsonRpcRequestError124}125func NewJsonRpcRequestErrorSerializer(requestError *JsonRpcRequestError) *JsonRpcRequestErrorSerializer {126 return &JsonRpcRequestErrorSerializer{jsonRpcRequestError: requestError}127}128func (j *JsonRpcRequestErrorSerializer) MarshalJSON() ([]byte, error) {129 var result = make(map[string]interface{})130 jsonRpcRequest := j.jsonRpcRequestError.jsonRpc20Request131 if jsonRpcRequest != nil {132 result[lib.JSONRPC] = jsonRpcRequest.version133 if !j.jsonRpcRequestError.jsonRpc20Request.notification {134 result[lib.JSONRPC_ID] = j.jsonRpcRequestError.jsonRpc20Request.id135 }136 }137 jsonRpc20Error := j.jsonRpcRequestError.jsonRpc20Error138 if jsonRpc20Error != nil {139 var error = make(map[string]interface{})140 error[lib.ERROR_CODE] = jsonRpc20Error.Code()141 error[lib.ERROR_MESSAGE] = jsonRpc20Error.Message()142 if jsonRpc20Error.data != nil {143 error[lib.ERROR_DATA] = jsonRpc20Error.data144 }145 result[lib.METHOD_RESULT_ERROR] = error146 }147 return json.Marshal(result)148}149type StructValueSerializer struct {150 structValue *data.StructValue151 redactSecret bool152}153func NewStructValueSerializer(value *data.StructValue, redactSecret bool) *StructValueSerializer {154 return &StructValueSerializer{structValue: value, redactSecret: redactSecret}155}156func (svs *StructValueSerializer) MarshalJSON() ([]byte, error) {157 var itemMapS = make(map[string]interface{})158 for key, val := range svs.structValue.Fields() {159 itemMapS[key] = getCustomSerializer(val, svs.redactSecret)160 }161 var resultMap = make(map[string]interface{})162 resultMap[svs.structValue.Name()] = itemMapS163 var wrapperMap = make(map[string]interface{})164 wrapperMap[svs.structValue.Type().String()] = resultMap165 return json.Marshal(wrapperMap)166}167type StringValueSerializer struct {168 stringValue *data.StringValue169}170func NewStringValueSerializer(value *data.StringValue) *StringValueSerializer {171 return &StringValueSerializer{stringValue: value}172}173func (svs *StringValueSerializer) MarshalJSON() ([]byte, error) {174 return json.Marshal(svs.stringValue.Value())175}176type IntegerValueSerializer struct {177 integerValue *data.IntegerValue178}179func (svs *IntegerValueSerializer) MarshalJSON() ([]byte, error) {180 return json.Marshal(svs.integerValue.Value())181}182func NewIntegerValueSerializer(value *data.IntegerValue) *IntegerValueSerializer {183 return &IntegerValueSerializer{integerValue: value}184}185type DoubleValueSerializer struct {186 doubleValue *data.DoubleValue187}188func (svs *DoubleValueSerializer) MarshalJSON() ([]byte, error) {189 var buf []byte190 splitResult := strings.Split(svs.doubleValue.String(), ".")191 var prec int192 if len(splitResult) > 1 {193 prec = len(splitResult[1])194 } else {195 //setting minimum precision to 1196 prec = 1197 }198 buf = strconv.AppendFloat(buf, svs.doubleValue.Value(), 'f', prec, 64)199 return buf, nil200}201func NewDoubleValueSerializer(value *data.DoubleValue) *DoubleValueSerializer {202 return &DoubleValueSerializer{doubleValue: value}203}204type ListValueSerializer struct {205 listValue *data.ListValue206 redactSecret bool207}208func (lvs *ListValueSerializer) MarshalJSON() ([]byte, error) {209 result := make([]interface{}, 0)210 for _, element := range lvs.listValue.List() {211 result = append(result, getCustomSerializer(element, lvs.redactSecret))212 }213 return json.Marshal(result)214}215func NewListValueSerializer(value *data.ListValue, redactSecret bool) *ListValueSerializer {216 return &ListValueSerializer{listValue: value, redactSecret: redactSecret}217}218type OptionalValueSerializer struct {219 optionalValue *data.OptionalValue220 redactSecret bool221}222func (ovs *OptionalValueSerializer) MarshalJSON() ([]byte, error) {223 var result = make(map[string]interface{})224 if ovs.optionalValue.IsSet() {225 result[ovs.optionalValue.Type().String()] = getCustomSerializer(ovs.optionalValue.Value(), ovs.redactSecret)226 } else {227 result[ovs.optionalValue.Type().String()] = nil228 }229 return json.Marshal(result)230}231func NewOptionalValueSerializer(value *data.OptionalValue, redactSecret bool) *OptionalValueSerializer {232 return &OptionalValueSerializer{optionalValue: value, redactSecret: redactSecret}233}234type ErrorValueSerializer struct {235 errorValue *data.ErrorValue236 redactSecret bool237}238func (evs *ErrorValueSerializer) MarshalJSON() ([]byte, error) {239 var itemMapS = make(map[string]interface{})240 for key, val := range evs.errorValue.Fields() {241 itemMapS[key] = getCustomSerializer(val, evs.redactSecret)242 }243 var resultMap = make(map[string]interface{})244 resultMap[evs.errorValue.Name()] = itemMapS245 var wrapperMap = make(map[string]interface{})246 wrapperMap[evs.errorValue.Type().String()] = resultMap247 return json.Marshal(wrapperMap)248}249func NewErrorValueSerializer(value *data.ErrorValue, redactSecret bool) *ErrorValueSerializer {250 return &ErrorValueSerializer{errorValue: value, redactSecret: redactSecret}251}252type VoidValueSerializer struct {253}254func (vvs *VoidValueSerializer) MarshalJSON() ([]byte, error) {255 return json.Marshal(nil)256}257func NewVoidValueSerializer() *VoidValueSerializer {258 return &VoidValueSerializer{}259}260type BooleanValueSerializer struct {261 booleanValue *data.BooleanValue262}263func (bvs *BooleanValueSerializer) MarshalJSON() ([]byte, error) {264 return json.Marshal(bvs.booleanValue.Value())265}266func NewBooleanValueSerializer(value *data.BooleanValue) *BooleanValueSerializer {267 return &BooleanValueSerializer{booleanValue: value}268}269type MethodResultSerializer struct {270 methodResult core.MethodResult271 redactSecret bool272}273func NewMethodResultSerializer(methodResult core.MethodResult, redactSecret bool) *MethodResultSerializer {274 return &MethodResultSerializer{methodResult: methodResult, redactSecret: redactSecret}275}276func (methodResultSerializer *MethodResultSerializer) MarshalJSON() ([]byte, error) {277 var result = make(map[string]interface{})278 var methodResult = methodResultSerializer.methodResult279 if methodResult.IsSuccess() {280 result[lib.METHOD_RESULT_OUTPUT] = getCustomSerializer(methodResult.Output(), methodResultSerializer.redactSecret)281 } else {282 result[lib.METHOD_RESULT_ERROR] = getCustomSerializer(methodResult.Error(), methodResultSerializer.redactSecret)283 }284 return json.Marshal(result)285}286type ApplicationContextSerializer struct {287 appContext *core.ApplicationContext288}289func NewApplicationContextSerializer(appContext *core.ApplicationContext) *ApplicationContextSerializer {290 return &ApplicationContextSerializer{appContext: appContext}291}292func (acs *ApplicationContextSerializer) MarshalJSON() ([]byte, error) {293 return json.Marshal(acs.appContext)294}295type SecurityContextSerializer struct {296 securityContext core.SecurityContext297}298func NewSecurityContextSerializer(context core.SecurityContext) *SecurityContextSerializer {299 return &SecurityContextSerializer{securityContext: context}300}301func (scs *SecurityContextSerializer) MarshalJSON() ([]byte, error) {302 return json.Marshal(scs.securityContext)303}304type ExecutionContextSerializer struct {305 executionContext *core.ExecutionContext306}307func NewExecutionContextSerializer(executionContext *core.ExecutionContext) *ExecutionContextSerializer {308 return &ExecutionContextSerializer{executionContext: executionContext}309}310func (ecs *ExecutionContextSerializer) MarshalJSON() ([]byte, error) {311 var result = make(map[string]interface{})312 if ecs.executionContext.SecurityContext() != nil {313 result[lib.SECURITY_CONTEXT] = NewSecurityContextSerializer(ecs.executionContext.SecurityContext())314 }315 result[lib.APPLICATION_CONTEXT] = NewApplicationContextSerializer(ecs.executionContext.ApplicationContext())316 return json.Marshal(result)317}318func dispatcher(val interface{}, redactSecret bool) ([]byte, error) {319 switch reflect.TypeOf(val) {320 case structValuePtr:321 var structValueSerializer = NewStructValueSerializer(val.(*data.StructValue), redactSecret)322 return json.Marshal(structValueSerializer)323 case listValuePtr:324 var listValueSerializer = NewListValueSerializer(val.(*data.ListValue), redactSecret)325 return json.Marshal(listValueSerializer)326 case optionalValuePtr:327 var optionalValueSerializer = NewOptionalValueSerializer(val.(*data.OptionalValue), redactSecret)328 return json.Marshal(optionalValueSerializer)329 case errorValuePtr:330 var errorValueSerializer = NewErrorValueSerializer(val.(*data.ErrorValue), redactSecret)331 return json.Marshal(errorValueSerializer)332 case methodResultType:333 return json.Marshal(NewMethodResultSerializer(val.(core.MethodResult), redactSecret))334 case executionContextPtr:335 return json.Marshal(NewExecutionContextSerializer(val.(*core.ExecutionContext)))336 case jsonRpcRequestType:337 return json.Marshal(NewJsonRpc20RequestSerializer(val.(JsonRpc20Request)))338 case jsonRpcResponseType:339 return json.Marshal(NewJsonRpc20ResponseSerializer(val.(JsonRpc20Response), redactSecret))340 case jsonRpcRequestErrorType:341 return json.Marshal(NewJsonRpcRequestErrorSerializer(val.(*JsonRpcRequestError)))342 default:343 fmt.Println(reflect.TypeOf(val))344 }345 return nil, errors.New("Could not Serialize")346}347type JsonRpc20RequestSerializer struct {348 jsonRequest JsonRpc20Request349}350func NewJsonRpc20RequestSerializer(jsonRequest JsonRpc20Request) JsonRpc20RequestSerializer {351 return JsonRpc20RequestSerializer{jsonRequest: jsonRequest}352}353func (jsonreq JsonRpc20RequestSerializer) MarshalJSON() ([]byte, error) {354 var result = make(map[string]interface{})355 result[lib.JSONRPC] = jsonreq.jsonRequest.version356 result[lib.JSONRPC_METHOD] = jsonreq.jsonRequest.method357 result[lib.JSONRPC_PARAMS] = jsonreq.jsonRequest.params358 if !jsonreq.jsonRequest.notification {359 result[lib.JSONRPC_ID] = jsonreq.jsonRequest.id360 }361 return json.Marshal(result)362}363type JsonRpc20ResponseSerializer struct {364 jsonResponse JsonRpc20Response365 redactSecret bool366}367func NewJsonRpc20ResponseSerializer(response JsonRpc20Response, redactSecret bool) JsonRpc20ResponseSerializer {368 return JsonRpc20ResponseSerializer{response, redactSecret}369}370func (jsonResp JsonRpc20ResponseSerializer) MarshalJSON() ([]byte, error) {371 var result = make(map[string]interface{})372 result[lib.JSONRPC] = jsonResp.jsonResponse.version373 result[lib.JSONRPC_ID] = jsonResp.jsonResponse.id374 if jsonResp.jsonResponse.result != nil {375 result[lib.METHOD_RESULT] = getCustomSerializer(jsonResp.jsonResponse.result, jsonResp.redactSecret)376 } else {377 result[lib.METHOD_RESULT_ERROR] = jsonResp.jsonResponse.error378 if jsonResp.jsonResponse.error[lib.ERROR_CODE] == fmt.Sprint(JSONRPC_PARSE_ERROR) ||379 jsonResp.jsonResponse.error[lib.ERROR_CODE] == JSONRPC_INVALID_REQUEST {380 result[lib.JSONRPC_ID] = nil381 }382 }383 return json.Marshal(result)384}...

Full Screen

Full Screen

manifest_test.go

Source:manifest_test.go Github

copy

Full Screen

2import (3 "reflect"4 "testing"5)6func TestStringOrStrings_MarshalJSON(t *testing.T) {7 tests := []struct {8 name string9 l StringOrStrings10 want []byte11 wantErr bool12 }{13 {"one license", StringOrStrings{"MIT"}, []byte("[\"MIT\"]"), false},14 {"two licenses", StringOrStrings{"LGPL-2.1-only", "GPL-3.0-or-later"}, []byte("[\"LGPL-2.1-only\",\"GPL-3.0-or-later\"]"), false},15 {"one long license", StringOrStrings{"(LGPL-2.1-only or GPL-3.0-or-later)"}, []byte("[\"(LGPL-2.1-only or GPL-3.0-or-later)\"]"), false},16 }17 for _, tt := range tests {18 t.Run(tt.name, func(t *testing.T) {19 got, err := tt.l.MarshalJSON()20 if (err != nil) != tt.wantErr {21 t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)22 return23 }24 if !reflect.DeepEqual(got, tt.want) {25 t.Errorf("MarshalJSON() got = %s, want %s", got, tt.want)26 }27 })28 }29}30func TestStringOrStrings_UnmarshalJSON(t *testing.T) {31 type args struct {32 data []byte33 }34 tests := []struct {35 name string36 l StringOrStrings37 args args38 wantErr bool39 }{40 {"license as a string", StringOrStrings{"test string"}, args{data: []byte("\"test string\"")}, false},41 {"one license as array", StringOrStrings{"(LGPL-2.1-only or GPL-3.0-or-later)"}, args{data: []byte("[\"(LGPL-2.1-only or GPL-3.0-or-later)\"]")}, false},42 {"two licenses as array", StringOrStrings{"LGPL-2.1-only", "GPL-3.0-or-later"}, args{data: []byte("[\"LGPL-2.1-only\", \"GPL-3.0-or-later\"]")}, false},43 {"error on non-string", StringOrStrings{""}, args{data: []byte("12345")}, true},44 }45 for _, tt := range tests {46 t.Run(tt.name, func(t *testing.T) {47 if err := tt.l.UnmarshalJSON(tt.args.data); (err != nil) != tt.wantErr {48 t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)49 }50 })51 }52}53func TestValueOrMap_MarshalJSON(t *testing.T) {54 type fields struct {55 Value string56 Patterns map[string]string57 }58 tests := []struct {59 name string60 fields fields61 want []byte62 wantErr bool63 }{64 {"single value", fields{Value: "one"}, []byte("\"one\""), false},65 {"another value", fields{Value: "auto"}, []byte("\"auto\""), false},66 {"multiple values", fields{Patterns: map[string]string{"one": "two", "three": "four"}}, []byte("{\"one\":\"two\",\"three\":\"four\"}"), false},67 }68 for _, tt := range tests {69 t.Run(tt.name, func(t *testing.T) {70 pi := &ValueOrMap{71 Value: tt.fields.Value,72 Map: tt.fields.Patterns,73 }74 got, err := pi.MarshalJSON()75 if (err != nil) != tt.wantErr {76 t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)77 return78 }79 if !reflect.DeepEqual(got, tt.want) {80 t.Errorf("MarshalJSON() got = %v, want %v", got, tt.want)81 }82 })83 }84}85func TestValueOrMap_UnmarshalJSON(t *testing.T) {86 type args struct {87 data []byte88 }89 tests := []struct {90 name string91 pi ValueOrMap92 args args93 wantErr bool94 }{95 {"single value", ValueOrMap{Value: "one"}, args{data: []byte("\"one\"")}, false},96 {"another value", ValueOrMap{Value: "auto"}, args{data: []byte("\"auto\"")}, false},97 {"multiple values", ValueOrMap{Map: map[string]string{"one": "two", "three": "four"}}, args{data: []byte("{\"one\":\"two\",\"three\":\"four\"}")}, false},98 {"error", ValueOrMap{}, args{data: []byte("true")}, true},99 }100 for _, tt := range tests {101 t.Run(tt.name, func(t *testing.T) {102 var pi ValueOrMap103 if err := pi.UnmarshalJSON(tt.args.data); (err != nil) != tt.wantErr {104 t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)105 }106 if !reflect.DeepEqual(tt.pi, pi) {107 t.Errorf("UnmarshalJSON() %v not equal to %v", tt.pi, pi)108 }109 })110 }111}112func TestBoolOrString_MarshalJSON(t *testing.T) {113 tests := []struct {114 name string115 s BoolOrString116 want []byte117 wantErr bool118 }{119 {"store", BoolOrString{Bool: true}, []byte("true"), false},120 {"do not store", BoolOrString{Bool: false}, []byte("false"), false},121 {"prompt", BoolOrString{String: "prompt"}, []byte("\"prompt\""), false},122 }123 for _, tt := range tests {124 t.Run(tt.name, func(t *testing.T) {125 got, err := tt.s.MarshalJSON()126 if (err != nil) != tt.wantErr {127 t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)128 return129 }130 if !reflect.DeepEqual(got, tt.want) {131 t.Errorf("MarshalJSON() got = %v, want %v", got, tt.want)132 }133 })134 }135}136func TestBoolOrString_UnmarshalJSON(t *testing.T) {137 type args struct {138 bytes []byte139 }140 tests := []struct {141 name string142 s BoolOrString143 args args144 wantErr bool145 }{146 {"true", BoolOrString{Bool: true}, args{[]byte("true")}, false},147 {"True", BoolOrString{Bool: true}, args{[]byte("True")}, false},148 {"1", BoolOrString{Bool: true}, args{[]byte("1")}, false},149 {"\"1\"", BoolOrString{Bool: true}, args{[]byte("\"1\"")}, false},150 {"false", BoolOrString{Bool: false}, args{[]byte("false")}, false},151 {"False", BoolOrString{Bool: false}, args{[]byte("False")}, false},152 {"0", BoolOrString{Bool: false}, args{[]byte("0")}, false},153 {"\"0\"", BoolOrString{Bool: false}, args{[]byte("\"0\"")}, false},154 {"prompt", BoolOrString{String: "prompt"}, args{[]byte("\"prompt\"")}, false},155 {"error", BoolOrString{}, args{[]byte("[\"error\"]")}, true},156 }157 for _, tt := range tests {158 var s BoolOrString159 t.Run(tt.name, func(t *testing.T) {160 if err := s.UnmarshalJSON(tt.args.bytes); (err != nil) != tt.wantErr {161 t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)162 }163 if !reflect.DeepEqual(tt.s, s) {164 t.Errorf("UnmarshalJSON() %v not equal to %v", tt.s, s)165 }166 })167 }168}169func TestIntString_MarshalJSON(t *testing.T) {170 tests := []struct {171 name string172 c IntString173 want []byte174 wantErr bool175 }{176 {"string 300", IntString("300"), []byte("\"300\""), false},177 {"string 300MiB", IntString("300MiB"), []byte("\"300MiB\""), false},178 }179 for _, tt := range tests {180 t.Run(tt.name, func(t *testing.T) {181 got, err := tt.c.MarshalJSON()182 if (err != nil) != tt.wantErr {183 t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)184 return185 }186 if !reflect.DeepEqual(got, tt.want) {187 t.Errorf("MarshalJSON() got = %v, want %v", got, tt.want)188 }189 })190 }191}192func TestIntString_UnmarshalJSON(t *testing.T) {193 type args struct {194 bytes []byte195 }196 tests := []struct {197 name string198 c IntString199 args args200 wantErr bool201 }{202 {"int 300", IntString("300"), args{[]byte("300")}, false},203 {"string 300", IntString("300"), args{[]byte("\"300\"")}, false},204 {"string 300MiB", IntString("300MiB"), args{[]byte("\"300MiB\"")}, false},205 }206 for _, tt := range tests {207 t.Run(tt.name, func(t *testing.T) {208 var c IntString209 if err := c.UnmarshalJSON(tt.args.bytes); (err != nil) != tt.wantErr {210 t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)211 }212 if !reflect.DeepEqual(tt.c, c) {213 t.Errorf("UnmarshalJSON() %v not equal to %v", tt.c, c)214 }215 })216 }217}218func TestBool_MarshalJSON(t *testing.T) {219 tests := []struct {220 name string221 b Bool222 want []byte223 wantErr bool224 }{225 {"true", Bool(true), []byte("true"), false},226 {"false", Bool(false), []byte("false"), false},227 }228 for _, tt := range tests {229 t.Run(tt.name, func(t *testing.T) {230 got, err := tt.b.MarshalJSON()231 if (err != nil) != tt.wantErr {232 t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)233 return234 }235 if !reflect.DeepEqual(got, tt.want) {236 t.Errorf("MarshalJSON() got = %v, want %v", got, tt.want)237 }238 })239 }240}241func TestBool_UnmarshalJSON(t *testing.T) {242 type args struct {243 bytes []byte244 }245 tests := []struct {246 name string247 b Bool248 args args249 wantErr bool250 }{251 {"true", Bool(true), args{[]byte("true")}, false},252 {"True", Bool(true), args{[]byte("True")}, false},253 {"1", Bool(true), args{[]byte("1")}, false},254 {"\"1\"", Bool(true), args{[]byte("\"1\"")}, false},255 {"false", Bool(false), args{[]byte("false")}, false},256 {"False", Bool(false), args{[]byte("False")}, false},257 {"0", Bool(false), args{[]byte("0")}, false},258 {"\"0\"", Bool(false), args{[]byte("\"0\"")}, false},259 {"error", Bool(false), args{[]byte("\"error\"")}, true},260 }261 for _, tt := range tests {262 t.Run(tt.name, func(t *testing.T) {263 var b Bool264 if err := b.UnmarshalJSON(tt.args.bytes); (err != nil) != tt.wantErr {265 t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)266 }267 if !reflect.DeepEqual(tt.b, b) {268 t.Errorf("UnmarshalJSON() %v not equal to %v", tt.b, b)269 }270 })271 }272}273func TestPsr_MarshalJSON(t *testing.T) {274 tests := []struct {275 name string276 p Psr277 want []byte278 wantErr bool279 }{280 {"\"UniqueGlobalClass\":\"\"", Psr(map[string][]string{"UniqueGlobalClass": {""}}), []byte("{\"UniqueGlobalClass\":[\"\"]}"), false},281 {"\"\":\"src/\"", Psr(map[string][]string{"": {"src/"}}), []byte("{\"\":[\"src/\"]}"), false},282 {"\"Monolog\\\\\":[\"src/\",\"lib/\"]", Psr(map[string][]string{"Monolog\\": {"src/", "lib/"}}), []byte("{\"Monolog\\\\\":[\"src/\",\"lib/\"]}"), false},283 }284 for _, tt := range tests {285 t.Run(tt.name, func(t *testing.T) {286 got, err := tt.p.MarshalJSON()287 if (err != nil) != tt.wantErr {288 t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)289 return290 }291 if !reflect.DeepEqual(got, tt.want) {292 t.Errorf("MarshalJSON() got = %v, want %v", got, tt.want)293 }294 })295 }296}297func TestPsr_UnmarshalJSON(t *testing.T) {298 type args struct {299 bytes []byte300 }301 tests := []struct {302 name string303 p Psr304 args args305 wantErr bool306 }{307 {"\"UniqueGlobalClass\":\"\"", Psr(map[string][]string{"UniqueGlobalClass": {""}}), args{[]byte("{\"UniqueGlobalClass\":[\"\"]}")}, false},308 {"\"\":\"src/\"", Psr(map[string][]string{"": {"src/"}}), args{[]byte("{\"\":\"src/\"}")}, false},309 {"\"\":\"src/\"", Psr(map[string][]string{"": {"src/"}}), args{[]byte("{\"\":\"src/\"}")}, false},310 {"\"Monolog\\\\\":\"src/\",\"Vendor_Namespace_\":[\"abc/\",\"lib/\"]", Psr(map[string][]string{"Monolog\\": {"src/"}, "Vendor_Namespace_": {"abc/", "lib/"}}), args{[]byte("{\"Monolog\\\\\":\"src/\",\"Vendor_Namespace_\":[\"abc/\",\"lib/\"]}")}, false},311 {"\"Monolog\\\\\":\"src/\",\"Vendor_Namespace_\":\"abc/\"", Psr(map[string][]string{"Monolog\\": {"src/"}, "Vendor_Namespace_": {"abc/"}}), args{[]byte("{\"Monolog\\\\\":\"src/\",\"Vendor_Namespace_\":[\"abc/\"]}")}, false},312 {"\"Monolog\\\\\":true", Psr(map[string][]string{}), args{[]byte("{\"Monolog\\\\\":true}")}, true},313 {"\"String\"", Psr(map[string][]string{}), args{[]byte("\"Monolog\"")}, true},314 }315 for _, tt := range tests {316 t.Run(tt.name, func(t *testing.T) {317 p := Psr(map[string][]string{})318 if err := p.UnmarshalJSON(tt.args.bytes); (err != nil) != tt.wantErr {319 t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)320 }321 if !reflect.DeepEqual(tt.p, p) {322 t.Errorf("UnmarshalJSON() %v not equal to %v", tt.p, p)323 }324 })325 }326}327func TestRepositories_MarshalJSON(t *testing.T) {328 tests := []struct {329 name string330 p Repositories331 want []byte332 wantErr bool333 }{334 {"1 repository", Repositories{Repository{Type: "test"}}, []byte("[{\"type\":\"test\"}]"), false},335 {"nothing", Repositories{}, []byte("[]"), false},336 }337 for _, tt := range tests {338 t.Run(tt.name, func(t *testing.T) {339 got, err := tt.p.MarshalJSON()340 if (err != nil) != tt.wantErr {341 t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)342 return343 }344 if !reflect.DeepEqual(got, tt.want) {345 t.Errorf("MarshalJSON() got = %d, want %v", got, tt.want)346 }347 })348 }349}350func TestRepositories_UnmarshalJSON(t *testing.T) {351 type args struct {352 bytes []byte353 }354 tests := []struct {355 name string356 p Repositories357 args args358 wantErr bool359 }{...

Full Screen

Full Screen

MarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func (p Person) MarshalJSON() ([]byte, error) {5 return json.Marshal(struct {6 }{7 })8}9func main() {10 p := Person{11 }12 b, err := json.Marshal(p)13 if err != nil {14 fmt.Println(err)15 }16 fmt.Println(string(b))17}

Full Screen

Full Screen

MarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func (p *Person) MarshalJSON() ([]byte, error) {5 return []byte(fmt.Sprintf(`{"first":"%s","last":"%s","age":"%d"}`, p.First, p.Last, p.Age)), nil6}7func main() {8 p1 := Person{"James", "Bond", 20}9 bs, _ := json.Marshal(p1)10 fmt.Println(string(bs))11}

Full Screen

Full Screen

MarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func (p *Person) MarshalJSON() ([]byte, error) {5 return []byte(fmt.Sprintf(`{"name":"%s","age":%d}`, p.Name, p.Age)), nil6}7func main() {8 p := Person{9 }10 b, _ := json.Marshal(p)11 fmt.Println(string(b))12}

Full Screen

Full Screen

MarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func (p Person) MarshalJSON() ([]byte, error) {5 return []byte(fmt.Sprintf(`{"First":"%s","Last":"%s","Age":%d}`, p.First, p.Last, p.Age)), nil6}7func main() {8 p1 := Person{"James", "Bond", 20}9 p2 := Person{"Miss", "Moneypenny", 18}10 people := []Person{p1, p2}11 fmt.Println(people)12 jsonData, err := json.Marshal(people)13 if err != nil {14 fmt.Println(err)15 }16 fmt.Println(string(jsonData))17}18import (19type Person struct {20}21func (p *Person) MarshalJSON() ([]byte, error) {22 return []byte(fmt.Sprintf(`{"First":"%s","Last":"%s","Age":%d}`, p.First, p.Last, p.Age)), nil23}24func main() {25 p1 := Person{"James", "Bond", 20}26 p2 := Person{"Miss", "Moneypenny", 18}27 people := []Person{p1, p2}28 fmt.Println(people)29 jsonData, err := json.Marshal(people)30 if err != nil {31 fmt.Println(err)32 }33 fmt.Println(string(jsonData))34}

Full Screen

Full Screen

MarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Employee struct {3}4func (e Employee) MarshalJSON() ([]byte, error) {5 return json.Marshal(e.Name)6}7func main() {8 emp := Employee{101, "Rajesh"}9 json, err := json.Marshal(emp)10 if err != nil {11 fmt.Println(err)12 }13 fmt.Println(string(json))14}15import (16type Employee struct {17}18func (e Employee) MarshalJSON() ([]byte, error) {19 return json.Marshal(e.Name)20}21func main() {22 emp := Employee{101, "Rajesh"}23 json, err := json.Marshal(emp)24 if err != nil {25 fmt.Println(err)26 }27 fmt.Println(string(json))28}29import (30type Employee struct {31}32func (e Employee) MarshalJSON() ([]byte, error) {33 return json.Marshal(e.Name)34}35func main() {36 emp := Employee{101, "Rajesh"}37 json, err := json.Marshal(emp)38 if err != nil {39 fmt.Println(err)40 }41 fmt.Println(string(json))42}43import (44type Employee struct {45}46func (e Employee) MarshalJSON() ([]byte, error) {47 return json.Marshal(e.Name)48}49func main() {50 emp := Employee{101, "Rajesh"}51 json, err := json.Marshal(emp)52 if err != nil {53 fmt.Println(err)54 }55 fmt.Println(string(json))56}57import (58type Employee struct {59}60func (e Employee) MarshalJSON() ([]byte, error)

Full Screen

Full Screen

MarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func (p Person) MarshalJSON() ([]byte, error) {5 return []byte(fmt.Sprintf(`{"First":"%s","Last":"%s","Age":%d}`, p.First, p.Last, p.Age)), nil6}7func main() {8 p1 := Person{"James", "Bond", 20}9 bs, _ := json.Marshal(p1)10 fmt.Println(string(bs))11}

Full Screen

Full Screen

MarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type person struct {3}4func main() {5 p1 := person{6 }7 p2 := person{8 }9 people := []person{p1, p2}10 fmt.Println(people)11 bs, err := json.Marshal(people)12 if err != nil {13 fmt.Println(err)14 }15 fmt.Println(string(bs))16}17import (18type person struct {19}20func main() {21 p1 := person{22 }23 p2 := person{24 }25 people := []person{p1, p2}26 fmt.Println(people)27 bs, err := json.MarshalIndent(people, "", "\t")28 if err != nil {29 fmt.Println(err)30 }31 fmt.Println(string(bs))32}33import (34type person struct {35}36func main() {37 s := `[{"Name":"James Bond","Age":20},{"Name":"Miss Moneypenny","Age":18}]`38 bs := []byte(s)39 fmt.Printf("%T\n", s)40 fmt.Printf("%T\n", bs)41 err := json.Unmarshal(bs, &people)42 if err != nil {43 fmt.Println(err)44 }45 fmt.Println("all of the data", people)46 for i, v := range people {47 fmt.Println("\nPERSON NUMBER", i)48 fmt.Println(v.Name, v.Age)49 }50}51import (52type person struct {53}54func main() {

Full Screen

Full Screen

MarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Student struct {3}4func (s Student) MarshalJSON() ([]byte, error) {5 return json.Marshal(struct {6 }{7 })8}9func main() {10 s := Student{11 }12 b, _ := json.Marshal(s)13 fmt.Println(string(b))14}

Full Screen

Full Screen

MarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Employee struct {3}4func (e Employee) MarshalJSON() ([]byte, error) {5 return json.Marshal(map[string]interface{}{6 })7}8func main() {9 employee := Employee{Id: 1, FirstName: "John", LastName: "Doe"}10 employeeJson, _ := json.Marshal(employee)11 fmt.Println(string(employeeJson))12}

Full Screen

Full Screen

MarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func main() {5 jsonData := []byte(`{"Name":"James", "Age":32}`)6 json.Unmarshal(jsonData, &p1)7 fmt.Println(p1.Name, p1.Age)8}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful