Documentation
¶
Index ¶
- Constants
- Variables
- func AppendUvarint64(buf []byte, value uint64) []byte
- func AppendVarint64(buf []byte, value int64) []byte
- func DecodeUvarint64(buf []byte) (value uint64, bytesRead int, err error)
- func DecodeVarint64(buf []byte) (value int64, bytesRead int, err error)
- func EncodeUvarint64(value uint64) []byte
- func EncodeVarint64(value int64) []byte
- func Float64ToDecimalV1(fv float64, decimalPlaces int) (decimal.Decimal, error)
- func Float64ToDecimalV2(fv float64, decimalPlaces int) (decimal.Decimal, error)
- func Float64ToIntDecimalV1(fv float64, decimalPlaces int) (int64, error)
- func Float64ToIntDecimalV2(fv float64, decimalPlaces int) (int64, error)
- func Float64ToIntDecimalV3(fv float64, decimalPlaces int) (int64, error)
- func Float642String(fv float64, decimalPlaces int) (string, error)
- func GenDecimalPlacesError[T any](decimalPlaces int) (T, error)
- func HexI64(s string) (int64, error)
- func HexI64V2(s string) (int64, error)
- func HexU64(s string) (uint64, error)
- func HexU64V2(s string) (uint64, error)
- func I64Hex(i int64) string
- func I64HexV2(i int64) string
- func IntDecimalToFloat64V1(iv int64, decimalPlaces int) (float64, error)
- func IntDecimalToFloat64V2(iv int64, decimalPlaces int) (float64, error)
- func IntDecimalToFloat64V3(iv int64, decimalPlaces int) (float64, error)
- func KeyInMap(m map[string]any, k string) bool
- func MapClone(base map[string]any) map[string]any
- func MapMerge(base map[string]any, diff map[string]any) map[string]any
- func MapVal2Bool(m map[string]any, k string) bool
- func MapVal2BoolList(m map[string]any, k string) ([]bool, bool)
- func MapVal2Bytes(m map[string]any, k string) []byte
- func MapVal2Duration(m map[string]any, k string) (time.Duration, bool)
- func MapVal2Float64(m map[string]any, k string) float64
- func MapVal2Float64List(m map[string]any, k string) ([]float64, bool)
- func MapVal2Int(m map[string]any, k string) int
- func MapVal2Int32(m map[string]any, k string) int32
- func MapVal2Int32List(m map[string]any, k string) ([]int32, bool)
- func MapVal2Int64(m map[string]any, k string) int64
- func MapVal2Int64List(m map[string]any, k string) ([]int64, bool)
- func MapVal2IntList(m map[string]any, k string) ([]int, bool)
- func MapVal2String(m map[string]any, k string) string
- func MapVal2StringList(m map[string]any, k string) ([]string, bool)
- func MapVal2Time(m map[string]any, k string) (time.Time, bool)
- func ToBool(v any) bool
- func ToBytes(v any) []byte
- func ToDuration(v any) (time.Duration, bool)
- func ToFloat64(v any) float64
- func ToInt(v any) int
- func ToInt32(v any) int32
- func ToInt64(v any) int64
- func ToString(v any) string
- func ToStringList(v any) []string
- func ToTime(v any) (time.Time, bool)
- func ToUInt(v any) uint
- func ToUInt32(v any) uint32
- func ToUInt64(v any) uint64
- func U64Hex(u uint64) string
- func U64HexV2(u uint64) string
- func UvarintSize(value uint64) int
- func VarintSize(value int64) int
- type Base64Bytes
- type Buffer
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Cap() int
- func (b *Buffer) Grow(n int)
- func (b *Buffer) Len() int
- func (b *Buffer) Next(n int) []byte
- func (b *Buffer) ReWrite(pos int, p []byte)
- func (b *Buffer) Read(p []byte) (n int, err error)
- func (b *Buffer) ReadByte() (byte, error)
- func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)
- func (b *Buffer) ReadRune() (r rune, size int, err error)
- func (b *Buffer) Reset()
- func (b *Buffer) String() string
- func (b *Buffer) Truncate(n int)
- func (b *Buffer) UnreadByte() error
- func (b *Buffer) UnreadRune() error
- func (b *Buffer) Write(p []byte) (n int, err error)
- func (b *Buffer) WriteByte(c byte) error
- func (b *Buffer) WriteRune(r rune) (n int, err error)
- func (b *Buffer) WriteString(s string) (n int, err error)
- func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)
- type Duration
- type JsByte
- type JsInt64
- type JsNanoTime
- type JsUInt64
- type JsUnixTime
- type SQLTime2Unix
- type Unix2Time
- type UnixNano2Time
- type UnixStamp
Constants ¶
const (
MaxDecimals = 15 // Maximum supported decimal places
)
const MinRead = 512
MinRead is the minimum slice size passed to a Read call by Buffer.ReadFrom. As long as the Buffer has at least MinRead bytes beyond what is required to hold the contents of r, ReadFrom will not grow the underlying buffer.
Variables ¶
var ( ErrEmptyBuffer = errors.New("empty.buffer") ErrInvalidVarint = errors.New("invalid.varint.encoding") ErrNotRegularEncoding = errors.New("not.regular.varint.encoding") )
var (
ErrInvalidByteJs = errors.New(`byte.invalid.string`)
)
var (
ErrInvalidDuration = errors.New("invalid.duration.string")
)
var (
ErrInvalidInt64Js = errors.New(`int64 invalid string`)
)
var (
ErrInvalidUInt64Js = errors.New(`uint64 invalid string`)
)
var ErrTooLarge = errors.New("bytes.Buffer: too large")
ErrTooLarge is passed to panic if memory cannot be allocated to store data in a buffer.
Functions ¶
func AppendUvarint64 ¶ added in v1.2.10
AppendUvarint64 appends a varint-encoded uint64 to the given byte slice
func AppendVarint64 ¶ added in v1.2.10
AppendVarint64 appends a varint-encoded int64 to the given byte slice
func DecodeUvarint64 ¶ added in v1.2.9
DecodeUvarint64 decodes a variable-length encoded uint64 from bytes Returns the decoded value, the number of bytes consumed, and any error
func DecodeVarint64 ¶ added in v1.2.9
DecodeVarint64 decodes a variable-length encoded int64 from bytes Returns the decoded value, the number of bytes consumed, and any error
func EncodeUvarint64 ¶ added in v1.2.9
EncodeUvarint64 encodes a uint64 value using variable-length encoding (same as protobuf) Returns the encoded bytes
func EncodeVarint64 ¶ added in v1.2.9
EncodeVarint64 encodes an int64 value using variable-length encoding (same as protobuf) Returns the encoded bytes
func Float64ToDecimalV1 ¶ added in v1.2.9
Float64ToDecimalV1 converts a float64 value to a decimal.Decimal representation
func Float64ToDecimalV2 ¶ added in v1.2.9
Float64ToDecimalV2 converts a float64 value to a decimal.Decimal representation
func Float64ToIntDecimalV1 ¶ added in v1.2.9
Float64ToIntDecimalV1 converts a float64 value to an int64 representation with the specified number of decimal places.
func Float64ToIntDecimalV2 ¶ added in v1.2.9
Float64ToIntDecimalV2 converts a float64 value to an int64 representation with the specified number of decimal places.
func Float64ToIntDecimalV3 ¶ added in v1.2.9
Float64ToIntDecimalV3 converts a float64 value to an int64 representation with the specified number of decimal places.
func Float642String ¶ added in v1.2.9
Float642String converts a float64 value to a string representation
func GenDecimalPlacesError ¶ added in v1.2.9
GenDecimalPlacesError generates an error for invalid decimal places
func IntDecimalToFloat64V1 ¶ added in v1.2.9
IntDecimalToFloat64V1 converts an int64 representation back to a float64
func IntDecimalToFloat64V2 ¶ added in v1.2.9
IntDecimalToFloat64V2 converts an int64 representation back to a float64
func IntDecimalToFloat64V3 ¶ added in v1.2.9
IntDecimalToFloat64V3 converts an int64 representation back to a float64
func MapClone ¶ added in v0.3.3
MapClone : clone a new map from old Attention: deeply clone only support map[string]interface{}, can not deeply clone pointer or other pointer like type. 只支持值为map[string]interface{}类型的深度克隆,不支持类似指针类型或切片类型的深度克隆
func MapVal2Bool ¶
MapVal2Bool : 将map中的value转换为bool
func MapVal2BoolList ¶ added in v0.3.9
MapVal2BoolList : 将map中的value转换为bool list
func MapVal2Bytes ¶
MapVal2Bytes : 将map中的value转换为[]byte
func MapVal2Duration ¶ added in v0.0.3
MapVal2Duration : 将map中的value转换为Duration
func MapVal2Float64 ¶
MapVal2Float64 : 将map中的value转换为float64
func MapVal2Float64List ¶ added in v0.3.9
MapVal2Float64List : 将map中的value转换为float64 list
func MapVal2Int32 ¶
MapVal2Int32 : 将map中的value转换为int32
func MapVal2Int32List ¶ added in v0.3.9
MapVal2Int32List : 将map中的value转换为int32 list
func MapVal2Int64 ¶
MapVal2Int64 : 将map中的value转换为int64
func MapVal2Int64List ¶ added in v0.3.9
MapVal2Int64List : 将map中的value转换为int64 list
func MapVal2IntList ¶ added in v0.3.9
MapVal2IntList : 将map中的value转换为int list
func MapVal2String ¶
MapVal2String : 将map中的value转换为string
func MapVal2StringList ¶
MapVal2StringList : 将map中的value转换为string list
func MapVal2Time ¶
MapVal2Time : 将map中的value转换为time
func ToDuration ¶ added in v0.0.3
ToDuration 转换为time.Duration
func UvarintSize ¶ added in v1.2.9
UvarintSize returns the number of bytes required to encode the given uint64 value
func VarintSize ¶ added in v1.2.9
VarintSize returns the number of bytes required to encode the given int64 value
Types ¶
type Base64Bytes ¶
type Base64Bytes []byte
func (*Base64Bytes) Scan ¶
func (i *Base64Bytes) Scan(value any) error
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
A Buffer is a variable-sized buffer of bytes with Read and Write methods. The zero value for Buffer is an empty buffer ready to use.
func NewBuffer ¶
NewBuffer creates and initializes a new Buffer using buf as its initial contents. The new Buffer takes ownership of buf, and the caller should not use buf after this call. NewBuffer is intended to prepare a Buffer to read existing data. It can also be used to set the initial size of the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.
In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
func NewBufferString ¶
NewBufferString creates and initializes a new Buffer using string s as its initial contents. It is intended to prepare a buffer to read an existing string.
In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
func NewSizedBuffer ¶ added in v0.2.3
NewSizedBuffer create size buff, the reset, which means that write the buffer is from first position.
func (*Buffer) Bytes ¶
Bytes returns a slice of length b.Len() holding the unread portion of the buffer. The slice is valid for use only until the next buffer modification (that is, only until the next call to a method like Read, Write, Reset, or Truncate). The slice aliases the buffer content at least until the next buffer modification, so immediate changes to the slice will affect the result of future reads.
func (*Buffer) Cap ¶
Cap returns the capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data.
func (*Buffer) Grow ¶
Grow grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, Grow will panic. If the buffer can't grow it will panic with ErrTooLarge.
func (*Buffer) Len ¶
Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()).
func (*Buffer) Next ¶
Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.
func (*Buffer) Read ¶
Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.
func (*Buffer) ReadByte ¶
ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF.
func (*Buffer) ReadFrom ¶
ReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with ErrTooLarge.
func (*Buffer) ReadRune ¶
ReadRune reads and returns the next UTF-8-encoded Unicode code point from the buffer. If no bytes are available, the error returned is io.EOF. If the bytes are an erroneous UTF-8 encoding, it consumes one byte and returns U+FFFD, 1.
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes. Reset is the same as Truncate(0).
func (*Buffer) String ¶
String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".
To build strings more efficiently, see the strings.Builder type.
func (*Buffer) Truncate ¶
Truncate discards all but the first n unread bytes from the buffer but continues to use the same allocated storage. It panics if n is negative or greater than the length of the buffer.
func (*Buffer) UnreadByte ¶
UnreadByte unreads the last byte returned by the most recent successful read operation that read at least one byte. If a write has happened since the last read, if the last read returned an error, or if the read zero bytes, UnreadByte returns an error.
func (*Buffer) UnreadRune ¶
UnreadRune unreads the last rune returned by ReadRune. If the most recent read or write operation on the buffer was not a successful ReadRune, UnreadRune returns an error. (In this regard it is stricter than UnreadByte, which will unread the last byte from any read operation.)
func (*Buffer) Write ¶
Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge.
func (*Buffer) WriteByte ¶
WriteByte appends the byte c to the buffer, growing the buffer as needed. The returned error is always nil, but is included to match bufio.Writer's WriteByte. If the buffer becomes too large, WriteByte will panic with ErrTooLarge.
func (*Buffer) WriteRune ¶
WriteRune appends the UTF-8 encoding of Unicode code point r to the buffer, returning its length and an error, which is always nil but is included to match bufio.Writer's WriteRune. The buffer is grown as needed; if it becomes too large, WriteRune will panic with ErrTooLarge.
func (*Buffer) WriteString ¶
WriteString appends the contents of s to the buffer, growing the buffer as needed. The return value n is the length of s; err is always nil. If the buffer becomes too large, WriteString will panic with ErrTooLarge.
type Duration ¶ added in v0.8.7
func (Duration) MarshalJSON ¶ added in v0.8.7
func (*Duration) UnmarshalJSON ¶ added in v0.8.7
func (*Duration) UnmarshalTOML ¶ added in v0.8.7
type JsByte ¶
type JsByte []byte
JsByte json could not support readable []byte use string to replace the byte array
func (*JsByte) UnmarshalJSON ¶
UnmarshalJSON unmarshal json
type JsInt64 ¶
type JsInt64 int64
JsInt64 json could not support large number use string to replace the number if a field is int64
func MapVal2JsInt64 ¶
MapVal2JsInt64 : 将map中的value转换为 json int64
func MapVal2JsInt64List ¶ added in v0.3.9
MapVal2JsInt64List : 将map中的value转换为 json int64 list
func (JsInt64) MarshalJSON ¶
MarshalJSON marshal json
func (*JsInt64) UnmarshalJSON ¶
UnmarshalJSON unmarshal json
type JsNanoTime ¶ added in v1.2.0
JsNanoTime convert time to js timestamp(unix nano) with json
func (JsNanoTime) MarshalJSON ¶ added in v1.2.0
func (i JsNanoTime) MarshalJSON() ([]byte, error)
MarshalJSON marshal json
func (*JsNanoTime) UnmarshalJSON ¶ added in v1.2.0
func (i *JsNanoTime) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshal json
type JsUInt64 ¶
type JsUInt64 uint64
JsUInt64 json could not support large number use string to replace the number if a field is uint64
func (JsUInt64) MarshalJSON ¶
MarshalJSON marshal json
func (*JsUInt64) UnmarshalJSON ¶
UnmarshalJSON unmarshal json
type JsUnixTime ¶ added in v1.2.0
JsUnixTime convert time to js timestamp(unix) with json
func (JsUnixTime) MarshalJSON ¶ added in v1.2.0
func (i JsUnixTime) MarshalJSON() ([]byte, error)
MarshalJSON marshal json
func (*JsUnixTime) UnmarshalJSON ¶ added in v1.2.0
func (i *JsUnixTime) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshal json
type SQLTime2Unix ¶ added in v1.0.0
type SQLTime2Unix int64
SQLTime2Unix convert timestamp to time.Time in SQL write mode. convert time.Time to timestamp when load data from database. implement sql.Driver Scan/Value
func (*SQLTime2Unix) Scan ¶ added in v1.0.0
func (i *SQLTime2Unix) Scan(value any) error
Scan : sql scan
type UnixNano2Time ¶
UnixNano2Time 纳秒时间戳时间
type UnixStamp ¶
type UnixStamp int64
UnixStamp 时间转成秒(只需要秒/Database中的datetime)
func (UnixStamp) MarshalJSON ¶
MarshalJSON marshal json
func (*UnixStamp) UnmarshalJSON ¶
UnmarshalJSON unmarshal json