Documentation ¶
Overview ¶
Package typing provides utilities for handling raw data objects and wraps basic Go types with additional functionality. It offers tools for flexible data processing and enhanced type manipulation, useful in various data handling and parsing scenarios.
Index ¶
- type Bool
- type Complex128
- type Complex64
- type Duration
- type Float32
- type Float64
- type Int
- type Int16
- type Int32
- type Int64
- type Int8
- type Object
- type RawObject
- func (o RawObject) Bytes() []byte
- func (o RawObject) Decode(decoder encoding.Decoder, v any) error
- func (o RawObject) Len() int
- func (o RawObject) MarshalBinary() ([]byte, error)
- func (o RawObject) MarshalJSON() ([]byte, error)
- func (o RawObject) MarshalText() ([]byte, error)
- func (o *RawObject) SetBytes(b []byte)
- func (o *RawObject) SetString(s string)
- func (o RawObject) String() string
- func (o *RawObject) UnmarshalBinary(data []byte) error
- func (o *RawObject) UnmarshalJSON(data []byte) error
- func (o *RawObject) UnmarshalText(data []byte) error
- type String
- type Time
- type Uint
- type Uint16
- type Uint32
- type Uint64
- type Uint8
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Complex128 ¶
type Complex128 complex128
Complex128 wraps a complex128 value.
func (*Complex128) Deref ¶
func (c *Complex128) Deref() complex128
func (*Complex128) Set ¶
func (c *Complex128) Set(v string) error
func (*Complex128) SetValue ¶
func (c *Complex128) SetValue(v complex128)
func (Complex128) Value ¶
func (c Complex128) Value() complex128
type Duration ¶
Duration wraps a time.Duration value.
Example ¶
d := Duration(5 * time.Second) fmt.Println("Duration:", d.Value()) jsonData, _ := json.Marshal(d) fmt.Println("JSON:", string(jsonData)) var parsed Duration _ = parsed.Set("10m") fmt.Println("Parsed:", parsed.Deref())
Output: Duration: 5s JSON: "5s" Parsed: 10m0s
func (Duration) MarshalJSON ¶
func (*Duration) UnmarshalJSON ¶
type RawObject ¶
type RawObject []byte
RawObject represents a raw object for delayed JSON decoding.
Example ¶
ro := NewRawObject(`{"name":"John","age":30}`) fmt.Println("Raw JSON:", ro) var person struct { Name string `json:"name"` Age int `json:"age"` } err := ro.Decode(json.Unmarshal, &person) if err != nil { fmt.Println("Error:", err) return } fmt.Printf("Decoded: Name=%s, Age=%d\n", person.Name, person.Age)
Output: Raw JSON: {"name":"John","age":30} Decoded: Name=John, Age=30
func NewRawObject ¶
NewRawObject creates a new RawObject with the provided data.
func (RawObject) Decode ¶
Decode decodes the Object's data using the provided decoder. It does nothing and returns nil if the Object is empty.
func (RawObject) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (RawObject) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. It returns the raw JSON encoding of the Object.
func (RawObject) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. It returns the base64 encoding of the Object's data.
func (*RawObject) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (*RawObject) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. It sets the Object's data to a copy of the input JSON data.
func (*RawObject) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. It decodes the input text as base64 and sets the Object's data to the result.