json

package
v0.0.0-...-4a740ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEncodedIncludeNotDeffiendKey = er.New("urn:giti:json.ecma-international.org:error:encoded-include-not-deffiend-key").SetDetail(protocol.LanguageEnglish, domainEnglish, "Encoded Include Not Deffiend Key",
		"Given encoded json string include a key that must not be in the encoded string",
		"",
		"").Save()

	ErrEncodedCorrupted = er.New("urn:giti:json.ecma-international.org:error:encoded-corrupted").SetDetail(protocol.LanguageEnglish, domainEnglish, "Encoded Corrupted",
		"Given encoded json string corruputed and not encode in the way that can decode",
		"",
		"").Save()

	ErrEncodedIntegerCorrupted = er.New("urn:giti:json.ecma-international.org:error:encoded-integer-corrupted").SetDetail(protocol.LanguageEnglish, domainEnglish, "Encoded Integer Corrupted",
		"Given encoded json in Integer part corruputed and not encode in the way that can decode",
		"",
		"").Save()

	ErrEncodedStringCorrupted = er.New("urn:giti:json.ecma-international.org:error:encoded-string-corrupted").SetDetail(protocol.LanguageEnglish, domainEnglish, "Encoded String Corrupted",
		"Given encoded json in string part corruputed and not encode in the way that can decode",
		"",
		"").Save()

	ErrEncodedArrayCorrupted = er.New("urn:giti:json.ecma-international.org:error:encoded-array-corrupted").SetDetail(protocol.LanguageEnglish, domainEnglish, "Encoded Array Corrupted",
		"Given encoded json in array part corruputed and not encode in the way that can decode",
		"",
		"").Save()

	ErrEncodedSliceCorrupted = er.New("urn:giti:json.ecma-international.org:error:encoded-slice-corrupted").SetDetail(protocol.LanguageEnglish, domainEnglish, "Encoded Slice Corrupted",
		"Given encoded json in slice part corruputed and not encode in the way that can decode",
		"",
		"").Save()
)

Declare Errors Details TODO::: use json.ietf.org or ??

Functions

func Marshal

func Marshal(s interface{}) (p []byte, err protocol.Error)

Marshal encodes the value of s to the payload buffer in runtime.

func Unmarshal

func Unmarshal(p []byte, s interface{}) (err protocol.Error)

Unmarshal decode payload and stores the result in the value pointed to by s in runtime.

Types

type Codec

type Codec struct {
	// contains filtered or unexported fields
}

Codec is a wrapper to use anywhere need protocol.Codec interface instead of protocol.JSON interface

func NewCodec

func NewCodec(json protocol.JSON) (codec Codec)

func (*Codec) CompressType

func (c *Codec) CompressType() protocol.CompressType

func (*Codec) Decode

func (c *Codec) Decode(reader protocol.Reader) (err protocol.Error)

func (*Codec) Encode

func (c *Codec) Encode(writer protocol.Writer) (err protocol.Error)

func (*Codec) Len

func (c *Codec) Len() int

func (*Codec) Marshal

func (c *Codec) Marshal() (data []byte)

func (*Codec) MarshalTo

func (c *Codec) MarshalTo(data []byte) []byte

func (*Codec) ReadFrom

func (c *Codec) ReadFrom(reader io.Reader) (n int64, err error)

func (*Codec) Unmarshal

func (c *Codec) Unmarshal(data []byte) (err protocol.Error)

func (*Codec) WriteTo

func (c *Codec) WriteTo(writer io.Writer) (n int64, err error)

type Decoder

type Decoder struct {
	Buf      []byte
	Token    byte
	LastItem []byte
}

Decoder store data to decode data by each method!

func (*Decoder) CheckNullValue

func (d *Decoder) CheckNullValue() (null bool)

CheckNullValue check if null exist as value. pass d.Buf start from after : and receive from from after , if null exist

func (*Decoder) CheckToken

func (d *Decoder) CheckToken(t byte) bool

CheckToken set d.Token to nil

func (*Decoder) Decode32ByteArraySliceAsBase64

func (d *Decoder) Decode32ByteArraySliceAsBase64() (slice [][32]byte, err protocol.Error)

Decode32ByteArraySliceAsBase64 decode [32]byte base64 string slice. pass buf start from after [ and receive from after ]

func (*Decoder) DecodeBool

func (d *Decoder) DecodeBool() (b bool, err protocol.Error)

DecodeBool convert string base boolean to bool. pass d.Buf start from after : and receive from after ,

func (*Decoder) DecodeByteArrayAsBase64

func (d *Decoder) DecodeByteArrayAsBase64(array []byte) (err protocol.Error)

DecodeByteArrayAsBase64 convert base64 string to [n]byte

func (*Decoder) DecodeByteArrayAsNumber

func (d *Decoder) DecodeByteArrayAsNumber(array []byte) (err protocol.Error)

DecodeByteArrayAsNumber convert number array to [n]byte

func (*Decoder) DecodeByteSliceAsBase64

func (d *Decoder) DecodeByteSliceAsBase64() (slice []byte, err protocol.Error)

DecodeByteSliceAsBase64 convert base64 string to []byte

func (*Decoder) DecodeByteSliceAsNumber

func (d *Decoder) DecodeByteSliceAsNumber() (slice []byte, err protocol.Error)

DecodeByteSliceAsNumber convert number string slice to []byte. pass buf start from after [ and receive from after ]

func (*Decoder) DecodeFloat64AsNumber

func (d *Decoder) DecodeFloat64AsNumber() (f float64, err protocol.Error)

DecodeFloat64AsNumber convert float64 number string to float64 number. pass d.Buf start from after : and receive from ,

func (*Decoder) DecodeInt64

func (d *Decoder) DecodeInt64() (i int64, err protocol.Error)

DecodeInt64 convert 64bit number string to number. pass d.Buf start from number and receive from after ,

func (*Decoder) DecodeKey

func (d *Decoder) DecodeKey() string

DecodeKey return key very safe for each decode iteration. pass d.Buf start from any where and receive from after :

func (*Decoder) DecodeString

func (d *Decoder) DecodeString() (s string, err protocol.Error)

DecodeString return string. pass d.Buf start from after : and receive from from after "

func (*Decoder) DecodeUInt16

func (d *Decoder) DecodeUInt16() (ui uint16, err protocol.Error)

DecodeUInt16 convert 16bit integer number string to number. pass d.Buf start from number and receive from after ,

func (*Decoder) DecodeUInt16SliceAsNumber

func (d *Decoder) DecodeUInt16SliceAsNumber() (slice []uint16, err protocol.Error)

DecodeUInt16SliceAsNumber convert uint16 number string slice to []byte. pass buf start from after [ and receive from after ]

func (*Decoder) DecodeUInt32

func (d *Decoder) DecodeUInt32() (ui uint32, err protocol.Error)

DecodeUInt32 convert 32bit integer number string to number. pass d.Buf start from number and receive from after ,

func (*Decoder) DecodeUInt32SliceAsNumber

func (d *Decoder) DecodeUInt32SliceAsNumber() (slice []uint32, err protocol.Error)

DecodeUInt32SliceAsNumber convert uint32 number string slice to []byte. pass buf start from after [ and receive from after ]

func (*Decoder) DecodeUInt64

func (d *Decoder) DecodeUInt64() (ui uint64, err protocol.Error)

DecodeUInt64 convert 64bit integer number string to number. pass d.Buf start from after : and receive from after ,

func (*Decoder) DecodeUInt64SliceAsNumber

func (d *Decoder) DecodeUInt64SliceAsNumber() (slice []uint64, err protocol.Error)

DecodeUInt64SliceAsNumber convert uint64 number string slice to []byte. pass buf start from after [ and receive from after ]

func (*Decoder) DecodeUInt8

func (d *Decoder) DecodeUInt8() (ui uint8, err protocol.Error)

DecodeUInt8 convert 8bit integer number string to number. pass d.Buf start from number and receive from after ,

func (*Decoder) FindEndToken

func (d *Decoder) FindEndToken()

FindEndToken find next end json token

func (*Decoder) NotFoundKey

func (d *Decoder) NotFoundKey() (err protocol.Error)

NotFoundKey call in default switch of each decode iteration

func (*Decoder) NotFoundKeyStrict

func (d *Decoder) NotFoundKeyStrict() protocol.Error

NotFoundKeyStrict call in default switch of each decode iteration in strict mode.

func (*Decoder) Offset

func (d *Decoder) Offset(o int)

Offset make d.Buf to start of given offset

func (*Decoder) ResetToken

func (d *Decoder) ResetToken()

ResetToken set d.Token to nil

func (*Decoder) TrimSpaces

func (d *Decoder) TrimSpaces()

TrimSpaces remove any spaces from Buf

func (*Decoder) TrimToDigit

func (d *Decoder) TrimToDigit()

TrimToDigit remove any data and set Buf to first charecter as number

func (*Decoder) TrimToStringStart

func (d *Decoder) TrimToStringStart()

TrimToStringStart remove any data from Buf to first charecter after quotation mark as '"'

type DecoderMinifed

type DecoderMinifed struct {
	Buf      []byte
	Token    byte
	LastItem []byte
}

DecoderMinifed store data to decode data by each method!

func (*DecoderMinifed) CheckToken

func (d *DecoderMinifed) CheckToken(t byte) bool

CheckToken set d.Token to nil

func (*DecoderMinifed) Decode32ByteArraySliceAsBase64

func (d *DecoderMinifed) Decode32ByteArraySliceAsBase64() (slice [][32]byte, err protocol.Error)

Decode32ByteArraySliceAsBase64 decode [32]byte base64 string slice. pass buf start from after [ and receive from after ]

func (*DecoderMinifed) DecodeBool

func (d *DecoderMinifed) DecodeBool() (b bool, err protocol.Error)

DecodeBool convert 64bit integer number string to number. pass d.Buf start from after : and receive from after ,

func (*DecoderMinifed) DecodeByteArrayAsBase64

func (d *DecoderMinifed) DecodeByteArrayAsBase64(array []byte) (err protocol.Error)

DecodeByteArrayAsBase64 convert base64 string to [n]byte

func (*DecoderMinifed) DecodeByteArrayAsNumber

func (d *DecoderMinifed) DecodeByteArrayAsNumber(array []byte) (err protocol.Error)

DecodeByteArrayAsNumber convert number array to [n]byte

func (*DecoderMinifed) DecodeByteSliceAsBase64

func (d *DecoderMinifed) DecodeByteSliceAsBase64() (slice []byte, err protocol.Error)

DecodeByteSliceAsBase64 convert base64 string to []byte

func (*DecoderMinifed) DecodeByteSliceAsNumber

func (d *DecoderMinifed) DecodeByteSliceAsNumber() (slice []byte, err protocol.Error)

DecodeByteSliceAsNumber convert number string slice to []byte. pass buf start from after [ and receive from after ]

func (*DecoderMinifed) DecodeFloat64AsNumber

func (d *DecoderMinifed) DecodeFloat64AsNumber() (f float64, err protocol.Error)

DecodeFloat64AsNumber convert float64 number string to float64 number. pass d.Buf start from number and receive from ,

func (*DecoderMinifed) DecodeInt64

func (d *DecoderMinifed) DecodeInt64() (i int64, err protocol.Error)

DecodeInt64 convert 64bit number string to number. pass d.Buf start from number and receive from after ,

func (*DecoderMinifed) DecodeKey

func (d *DecoderMinifed) DecodeKey() string

DecodeKey return json key. pass d.Buf start from after {||, and receive from after :

func (*DecoderMinifed) DecodeString

func (d *DecoderMinifed) DecodeString() (s string)

DecodeString return string. pass d.Buf start from after " and receive from from after "

func (*DecoderMinifed) DecodeUInt16

func (d *DecoderMinifed) DecodeUInt16() (ui uint16, err protocol.Error)

DecodeUInt16 convert 16bit integer number string to number. pass d.Buf start from number and receive from after ,

func (*DecoderMinifed) DecodeUInt16SliceAsNumber

func (d *DecoderMinifed) DecodeUInt16SliceAsNumber() (slice []uint16, err protocol.Error)

DecodeUInt16SliceAsNumber convert uint16 number string slice to []byte. pass buf start from after [ and receive from after ]

func (*DecoderMinifed) DecodeUInt32

func (d *DecoderMinifed) DecodeUInt32() (ui uint32, err protocol.Error)

DecodeUInt32 convert 32bit integer number string to number. pass d.Buf start from number and receive from after ,

func (*DecoderMinifed) DecodeUInt32SliceAsNumber

func (d *DecoderMinifed) DecodeUInt32SliceAsNumber() (slice []uint32, err protocol.Error)

DecodeUInt32SliceAsNumber convert uint32 number string slice to []byte. pass buf start from after [ and receive from after ]

func (*DecoderMinifed) DecodeUInt64

func (d *DecoderMinifed) DecodeUInt64() (ui uint64, err protocol.Error)

DecodeUInt64 convert 64bit integer number string to number. pass d.Buf start from number and receive from after ,

func (*DecoderMinifed) DecodeUInt64SliceAsNumber

func (d *DecoderMinifed) DecodeUInt64SliceAsNumber() (slice []uint64, err protocol.Error)

DecodeUInt64SliceAsNumber convert uint64 number string slice to []byte. pass buf start from after [ and receive from after ]

func (*DecoderMinifed) DecodeUInt8

func (d *DecoderMinifed) DecodeUInt8() (ui uint8, err protocol.Error)

DecodeUInt8 convert 8bit integer number string to number. pass d.Buf start from number and receive from after ,

func (*DecoderMinifed) FindEndToken

func (d *DecoderMinifed) FindEndToken()

FindEndToken find next end json token

func (*DecoderMinifed) NotFoundKey

func (d *DecoderMinifed) NotFoundKey() (err protocol.Error)

NotFoundKey call in default switch of each decode iteration

func (*DecoderMinifed) NotFoundKeyStrict

func (d *DecoderMinifed) NotFoundKeyStrict() protocol.Error

NotFoundKeyStrict call in default switch of each decode iteration in strict mode.

func (*DecoderMinifed) Offset

func (d *DecoderMinifed) Offset(o int)

Offset make d.Buf to start of given offset

func (*DecoderMinifed) ResetToken

func (d *DecoderMinifed) ResetToken()

ResetToken set d.Token to nil

type DecoderUnsafe

type DecoderUnsafe struct {
	Decoder
}

DecoderUnsafe store data to decode data by each method!

func (*DecoderUnsafe) DecodeInt32

func (d *DecoderUnsafe) DecodeInt32() (i int32, err protocol.Error)

DecodeInt32 convert 32bit number string to number. pass d.Buf start from number and receive from after end of number

func (*DecoderUnsafe) DecodeString

func (d *DecoderUnsafe) DecodeString() (s string, err protocol.Error)

DecodeString return string. pass d.Buf start from after " and receive from from after "

type DecoderUnsafeMinifed

type DecoderUnsafeMinifed struct {
	DecoderMinifed
}

DecoderUnsafeMinifed store data to decode data by each method!

func (*DecoderUnsafeMinifed) DecodeString

func (d *DecoderUnsafeMinifed) DecodeString() (s string, err protocol.Error)

DecodeString return string. pass d.Buf start from after " and receive from from after "

type Encoder

type Encoder struct {
	Buf []byte
}

Encoder store data to encode given data by each method!

func (*Encoder) AddTrailingComma

func (e *Encoder) AddTrailingComma()

AddTrailingComma add last value in Buf as trailing comma

func (*Encoder) Encode32ByteArraySliceAsBase64

func (e *Encoder) Encode32ByteArraySliceAsBase64(slice [][32]byte)

Encode32ByteArraySliceAsBase64 use to append [][32]byte as base64 string

func (*Encoder) EncodeBoolean

func (e *Encoder) EncodeBoolean(b bool)

EncodeBoolean append given bool as true or false string

func (*Encoder) EncodeByte

func (e *Encoder) EncodeByte(b byte)

EncodeByte append given byte to Buf

func (*Encoder) EncodeByteSliceAsBase64

func (e *Encoder) EncodeByteSliceAsBase64(slice []byte)

EncodeByteSliceAsBase64 use to append []byte as base64 string

func (*Encoder) EncodeByteSliceAsNumber

func (e *Encoder) EncodeByteSliceAsNumber(slice []byte)

EncodeByteSliceAsNumber append given byte slice as number string

func (*Encoder) EncodeFloat32

func (e *Encoder) EncodeFloat32(f float32)

EncodeFloat32 append given float32 number as number string

func (*Encoder) EncodeFloat64

func (e *Encoder) EncodeFloat64(f float64)

EncodeFloat64 append given float64 number as number string

func (*Encoder) EncodeInt64

func (e *Encoder) EncodeInt64(i int64)

EncodeInt64 append given int64 number as number string

func (*Encoder) EncodeKey

func (e *Encoder) EncodeKey(s string)

EncodeKey append given string key as given format with ""

func (*Encoder) EncodeString

func (e *Encoder) EncodeString(s string)

EncodeString append given string as given format

func (*Encoder) EncodeStringValue

func (e *Encoder) EncodeStringValue(s string)

EncodeStringValue append given string as given format

func (*Encoder) EncodeUInt16

func (e *Encoder) EncodeUInt16(ui uint16)

EncodeUInt16 append given uint16 number as number string TODO::: not efficient enough code

func (*Encoder) EncodeUInt16SliceAsBase64

func (e *Encoder) EncodeUInt16SliceAsBase64(slice []uint16)

EncodeUInt16SliceAsBase64 use to append []byte as base64 string

func (*Encoder) EncodeUInt16SliceAsNumber

func (e *Encoder) EncodeUInt16SliceAsNumber(slice []uint16)

EncodeUInt16SliceAsNumber append given uint16 slice as number string

func (*Encoder) EncodeUInt32

func (e *Encoder) EncodeUInt32(ui uint32)

EncodeUInt32 append given uint32 number as number string

func (*Encoder) EncodeUInt32SliceAsBase64

func (e *Encoder) EncodeUInt32SliceAsBase64(slice []uint32)

EncodeUInt32SliceAsBase64 use to append []byte as base64 string

func (*Encoder) EncodeUInt32SliceAsNumber

func (e *Encoder) EncodeUInt32SliceAsNumber(slice []uint32)

EncodeUInt32SliceAsNumber append given uint32 slice as number string

func (*Encoder) EncodeUInt64

func (e *Encoder) EncodeUInt64(ui uint64)

EncodeUInt64 append given uint64 number as number string

func (*Encoder) EncodeUInt64SliceAsNumber

func (e *Encoder) EncodeUInt64SliceAsNumber(slice []uint64)

EncodeUInt64SliceAsNumber append given byte slice as number string

func (*Encoder) EncodeUInt8

func (e *Encoder) EncodeUInt8(ui uint8)

EncodeUInt8 append given uint8 number as number string TODO::: not efficient enough code

func (*Encoder) RemoveTrailingComma

func (e *Encoder) RemoveTrailingComma()

RemoveTrailingComma remove last value in Buf as trailing comma

type RunTimeCodec

type RunTimeCodec struct {
	// contains filtered or unexported fields
}

RunTimeCodec is a wrapper to use anywhere need protocol.Codec interface instead of protocol.JSON interface

func NewRunTimeCodec

func NewRunTimeCodec(t interface{}) (codec *RunTimeCodec)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL