types

package
v0.0.0-...-538e535 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package types defines types that encode values in SOAP requests and responses.

Based on https://openconnectivity.org/upnp-specs/UPnP-arch-DeviceArchitecture-v2.0-20200417.pdf pages 58-60.

Date/time formats are based on http://www.w3.org/TR/1998/NOTE-datetime-19980827

Index

Constants

View Source
const Fixed14_4Denominator = 1e4
View Source
const Fixed14_4MaxFrac = Fixed14_4Denominator - 1
View Source
const Fixed14_4MaxFractional = 1e18 - 1
View Source
const Fixed14_4MaxInteger = 1e14 - 1

Variables

This section is empty.

Functions

func TypeMap

func TypeMap() typedesc.TypeMap

TypeMap returns the builtin type map description.

Types

type BinBase64

type BinBase64 []byte

BinBase64 maps []byte to SOAP "bin.base64" type.

func NewBinBase64

func NewBinBase64(v []byte) *BinBase64

func (*BinBase64) MarshalText

func (v *BinBase64) MarshalText() ([]byte, error)

func (*BinBase64) String

func (v *BinBase64) String() string

func (*BinBase64) UnmarshalText

func (v *BinBase64) UnmarshalText(b []byte) error

type BinHex

type BinHex []byte

BinHex maps []byte to SOAP "bin.hex" type.

func NewBinHex

func NewBinHex(v []byte) *BinHex

func (*BinHex) MarshalText

func (v *BinHex) MarshalText() ([]byte, error)

func (*BinHex) String

func (v *BinHex) String() string

func (*BinHex) UnmarshalText

func (v *BinHex) UnmarshalText(b []byte) error

type Boolean

type Boolean bool

func NewBoolean

func NewBoolean(v bool) *Boolean

func (*Boolean) MarshalText

func (v *Boolean) MarshalText() ([]byte, error)

func (*Boolean) String

func (v *Boolean) String() string

func (*Boolean) UnmarshalText

func (v *Boolean) UnmarshalText(b []byte) error

type Char

type Char rune

Char maps rune to SOAP "char" type.

func NewChar

func NewChar(v rune) *Char

func (*Char) MarshalText

func (v *Char) MarshalText() ([]byte, error)

func (*Char) String

func (v *Char) String() string

func (*Char) UnmarshalText

func (v *Char) UnmarshalText(b []byte) error

type Date

type Date struct {
	Year  int
	Month time.Month
	Day   int
}

Date maps to the SOAP "date" type. Marshaling and Unmarshalling does *not* check if components are in range.

func DateFromTime

func DateFromTime(t time.Time) Date

func (Date) CheckValid

func (d Date) CheckValid() error

CheckValid returns an error if the date components are out of range.

func (*Date) MarshalText

func (d *Date) MarshalText() ([]byte, error)

func (*Date) SetFromTime

func (d *Date) SetFromTime(t time.Time)

func (*Date) String

func (d *Date) String() string

func (Date) ToTime

func (d Date) ToTime(loc *time.Location) time.Time

ToTime returns a time.Time from the date components, at midnight, and using the given location.

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(b []byte) error

type DateTime

type DateTime struct {
	Date      Date
	TimeOfDay TimeOfDay
}

DateTime maps to SOAP "dateTime" type.

func DateTimeFromTime

func DateTimeFromTime(v time.Time) DateTime

func (*DateTime) MarshalText

func (dt *DateTime) MarshalText() ([]byte, error)

func (*DateTime) String

func (dt *DateTime) String() string

func (DateTime) ToTime

func (dt DateTime) ToTime(loc *time.Location) time.Time

func (*DateTime) UnmarshalText

func (dt *DateTime) UnmarshalText(b []byte) error

type DateTimeTZ

type DateTimeTZ struct {
	Date      Date
	TimeOfDay TimeOfDay
	TZ        TZD
}

DateTime maps to SOAP type "dateTime.tz".

func DateTimeTZFromTime

func DateTimeTZFromTime(t time.Time) DateTimeTZ

func (*DateTimeTZ) MarshalText

func (dtz *DateTimeTZ) MarshalText() ([]byte, error)

func (*DateTimeTZ) String

func (dtz *DateTimeTZ) String() string

func (DateTimeTZ) Time

func (dtz DateTimeTZ) Time(defaultLoc *time.Location) time.Time

Time converts `dtz` to time.Time, using defaultLoc as the default location if `dtz` contains no offset information.

func (*DateTimeTZ) UnmarshalText

func (dtz *DateTimeTZ) UnmarshalText(b []byte) error

type Fixed14_4

type Fixed14_4 struct {
	// Fractional divided by 1e4 is the fixed point value. Take care setting
	// this directly, it should only contain values in the range (-1e18, 1e18).
	Fractional int64
}

Fixed14_4 represents a fixed point number with up to 14 decimal digits before the decimal point (integer part), and up to 4 decimal digits after the decimal point (fractional part).

Corresponds to the SOAP "fixed.14.4" type.

This is a struct to avoid accidentally using the value directly as an integer.

func Fixed14_4FromFloat

func Fixed14_4FromFloat(f float64) (Fixed14_4, error)

Fixed14_4FromFloat creates a Fixed14_4 from a float64. Returns error if the float is outside the range.

func Fixed14_4FromFractional

func Fixed14_4FromFractional(fracValue int64) (Fixed14_4, error)

Fixed14_4FromFractional creates a Fixed14_4 from an integer, where the parameter divided by 1e4 is the fixed point value.

func Fixed14_4FromParts

func Fixed14_4FromParts(intPart int64, fracPart int16) (Fixed14_4, error)

Fixed14_4FromParts creates a Fixed14_4 from components. Bounds:

  • Both intPart and fracPart must have the same sign.
  • -1e14 < intPart < 1e14
  • -1e4 < fracPart < 1e4

func (Fixed14_4) Float64

func (v Fixed14_4) Float64() float64

func (*Fixed14_4) MarshalText

func (v *Fixed14_4) MarshalText() ([]byte, error)

func (Fixed14_4) Parts

func (v Fixed14_4) Parts() (int64, int16)

Returns the integer part and fractional part of the fixed point number.

func (*Fixed14_4) SetFloat64

func (v *Fixed14_4) SetFloat64(f float64) error

SetFloat64 sets the value of the fixed point number from a float64. Returns error if the float is outside the range.

func (*Fixed14_4) SetFractional

func (v *Fixed14_4) SetFractional(fracValue int64) error

SetFromFractional sets the value of the fixed point number, where fracValue divided by 1e4 is the fixed point value. Unlike setting v.Fractional directly, this checks the value.

func (*Fixed14_4) SetParts

func (v *Fixed14_4) SetParts(intPart int64, fracPart int16) error

SetFromParts sets the value based on the integer component and the fractional component. Bounds:

  • Both intPart and fracPart must have the same sign.
  • -1e14 < intPart < 1e14
  • -1e4 < fracPart < 1e4

func (*Fixed14_4) String

func (v *Fixed14_4) String() string

func (*Fixed14_4) UnmarshalText

func (v *Fixed14_4) UnmarshalText(b []byte) error

type I1

type I1 int8

func NewI1

func NewI1(v int8) *I1

func (*I1) MarshalText

func (v *I1) MarshalText() ([]byte, error)

func (*I1) String

func (v *I1) String() string

func (*I1) UnmarshalText

func (v *I1) UnmarshalText(b []byte) error

type I2

type I2 int16

func NewI2

func NewI2(v int16) *I2

func (*I2) MarshalText

func (v *I2) MarshalText() ([]byte, error)

func (*I2) String

func (v *I2) String() string

func (*I2) UnmarshalText

func (v *I2) UnmarshalText(b []byte) error

type I4

type I4 int32

func NewI4

func NewI4(v int32) *I4

func (*I4) MarshalText

func (v *I4) MarshalText() ([]byte, error)

func (*I4) String

func (v *I4) String() string

func (*I4) UnmarshalText

func (v *I4) UnmarshalText(b []byte) error

type I8

type I8 int64

func NewI8

func NewI8(v int64) *I8

func (*I8) MarshalText

func (v *I8) MarshalText() ([]byte, error)

func (*I8) String

func (v *I8) String() string

func (*I8) UnmarshalText

func (v *I8) UnmarshalText(b []byte) error

type R4

type R4 float32

func NewR4

func NewR4(v float32) *R4

func (*R4) MarshalText

func (v *R4) MarshalText() ([]byte, error)

func (*R4) String

func (v *R4) String() string

func (*R4) UnmarshalText

func (v *R4) UnmarshalText(b []byte) error

type R8

type R8 float64

func NewR8

func NewR8(v float64) *R8

func (*R8) MarshalText

func (v *R8) MarshalText() ([]byte, error)

func (*R8) String

func (v *R8) String() string

func (*R8) UnmarshalText

func (v *R8) UnmarshalText(b []byte) error

type SOAPValue

type SOAPValue interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}

type String

type String string

func NewString

func NewString(v string) *String

func (*String) MarshalText

func (v *String) MarshalText() ([]byte, error)

func (*String) UnmarshalText

func (v *String) UnmarshalText(b []byte) error

type TZD

type TZD struct {
	// Offset is the timezone offset in seconds. Note that the SOAP encoding
	// only encodes precisions up to minutes, this is in seconds for
	// interoperability with time.Time.
	Offset int
	// HasTZ specifies if a timezone offset is specified or not.
	HasTZ bool
}

TZD is a timezone designator. Not a full SOAP time in itself, but used as part of timezone-aware date/time types that are.

func TZDFromTime

func TZDFromTime(t time.Time) TZD

func TZDOffset

func TZDOffset(secondsOffset int) TZD

func (TZD) Location

func (tzd TZD) Location(defaultLoc *time.Location) *time.Location

Location returns an appropriate *time.Location (time.UTC or time.FixedZone), or defaultLoc if `v` contains no offset information.

func (*TZD) String

func (tzd *TZD) String() string

type TimeOfDay

type TimeOfDay struct {
	Hour   int8
	Minute int8
	Second int8
}

TimeOfDay is used in cases where SOAP "time" or "time.tz" is used. It contains non-timezone aware components.

func TimeOfDayFromTime

func TimeOfDayFromTime(t time.Time) TimeOfDay

func (TimeOfDay) CheckValid

func (tod TimeOfDay) CheckValid() error

IsValid returns true iff v is positive and <= 24 hours. It allows equal to 24 hours as a special case as 24:00:00 is an allowed value by the SOAP type.

func (*TimeOfDay) MarshalText

func (tod *TimeOfDay) MarshalText() ([]byte, error)

func (*TimeOfDay) SetFromDuration

func (tod *TimeOfDay) SetFromDuration(d time.Duration) error

Sets components based on duration since midnight.

func (*TimeOfDay) SetFromTime

func (tod *TimeOfDay) SetFromTime(t time.Time)

func (*TimeOfDay) String

func (tod *TimeOfDay) String() string

func (TimeOfDay) ToDuration

func (tod TimeOfDay) ToDuration() time.Duration

Returns duration since midnight.

func (*TimeOfDay) UnmarshalText

func (tod *TimeOfDay) UnmarshalText(b []byte) error

type TimeOfDayTZ

type TimeOfDayTZ struct {
	// Components of the time of day.
	TimeOfDay TimeOfDay

	// Timezone designator.
	TZ TZD
}

TimeOfDayTZ maps to the SOAP "time.tz" type.

func (*TimeOfDayTZ) MarshalText

func (todz *TimeOfDayTZ) MarshalText() ([]byte, error)

func (*TimeOfDayTZ) String

func (todz *TimeOfDayTZ) String() string

func (*TimeOfDayTZ) UnmarshalText

func (todz *TimeOfDayTZ) UnmarshalText(b []byte) error

type UI1

type UI1 uint8

func NewUI1

func NewUI1(v uint8) *UI1

func (*UI1) MarshalText

func (v *UI1) MarshalText() ([]byte, error)

func (*UI1) String

func (v *UI1) String() string

func (*UI1) UnmarshalText

func (v *UI1) UnmarshalText(b []byte) error

type UI2

type UI2 uint16

func NewUI2

func NewUI2(v uint16) *UI2

func (*UI2) MarshalText

func (v *UI2) MarshalText() ([]byte, error)

func (*UI2) String

func (v *UI2) String() string

func (*UI2) UnmarshalText

func (v *UI2) UnmarshalText(b []byte) error

type UI4

type UI4 uint32

func NewUI4

func NewUI4(v uint32) *UI4

func (*UI4) MarshalText

func (v *UI4) MarshalText() ([]byte, error)

func (*UI4) String

func (v *UI4) String() string

func (*UI4) UnmarshalText

func (v *UI4) UnmarshalText(b []byte) error

type UI8

type UI8 uint64

func NewUI8

func NewUI8(v uint64) *UI8

func (*UI8) MarshalText

func (v *UI8) MarshalText() ([]byte, error)

func (*UI8) String

func (v *UI8) String() string

func (*UI8) UnmarshalText

func (v *UI8) UnmarshalText(b []byte) error

type URI

type URI url.URL

URI maps *url.URL to SOAP "uri" type.

func (*URI) MarshalText

func (v *URI) MarshalText() ([]byte, error)

func (*URI) String

func (v *URI) String() string

func (*URI) ToURL

func (v *URI) ToURL() *url.URL

func (*URI) UnmarshalText

func (v *URI) UnmarshalText(b []byte) error

Jump to

Keyboard shortcuts

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