Documentation ¶
Overview ¶
Common runtime (boilerplate support routines) for output of the goxdr XDR compiler.
Index ¶
- Constants
- Variables
- func XdrArrayOpaqueScan(dest []byte, ss fmt.ScanState, _ rune) error
- func XdrPanic(s string, args ...interface{})
- func XdrSymChar(r rune) bool
- func XdrToI32(i interface{}) int32
- func XdrToString(t XdrType) string
- type XDR
- type XdrAggregate
- type XdrArray
- type XdrArrayOpaque
- type XdrBool
- func (v XdrBool) GetU32() uint32
- func (v *XdrBool) Scan(ss fmt.ScanState, r rune) error
- func (v *XdrBool) SetU32(nv uint32)
- func (v XdrBool) String() string
- func (v *XdrBool) XdrMarshal(x XDR, name string)
- func (v *XdrBool) XdrPointer() interface{}
- func (XdrBool) XdrTypeName() string
- func (v XdrBool) XdrValue() interface{}
- type XdrBytes
- type XdrEnum
- type XdrError
- type XdrFloat32
- func (v XdrFloat32) GetU32() uint32
- func (v *XdrFloat32) Scan(ss fmt.ScanState, r rune) error
- func (v *XdrFloat32) SetU32(nv uint32)
- func (v XdrFloat32) String() string
- func (v *XdrFloat32) XdrMarshal(x XDR, name string)
- func (v *XdrFloat32) XdrPointer() interface{}
- func (XdrFloat32) XdrTypeName() string
- func (v XdrFloat32) XdrValue() interface{}
- type XdrFloat64
- func (v XdrFloat64) GetU64() uint64
- func (v *XdrFloat64) Scan(ss fmt.ScanState, r rune) error
- func (v *XdrFloat64) SetU64(nv uint64)
- func (v XdrFloat64) String() string
- func (v *XdrFloat64) XdrMarshal(x XDR, name string)
- func (v *XdrFloat64) XdrPointer() interface{}
- func (XdrFloat64) XdrTypeName() string
- func (v XdrFloat64) XdrValue() interface{}
- type XdrIn
- type XdrInt32
- func (v XdrInt32) GetU32() uint32
- func (v *XdrInt32) Scan(ss fmt.ScanState, r rune) error
- func (v *XdrInt32) SetU32(nv uint32)
- func (v XdrInt32) String() string
- func (v *XdrInt32) XdrMarshal(x XDR, name string)
- func (v *XdrInt32) XdrPointer() interface{}
- func (XdrInt32) XdrTypeName() string
- func (v XdrInt32) XdrValue() interface{}
- type XdrInt64
- func (v XdrInt64) GetU64() uint64
- func (v *XdrInt64) Scan(ss fmt.ScanState, r rune) error
- func (v *XdrInt64) SetU64(nv uint64)
- func (v XdrInt64) String() string
- func (v *XdrInt64) XdrMarshal(x XDR, name string)
- func (v *XdrInt64) XdrPointer() interface{}
- func (XdrInt64) XdrTypeName() string
- func (v XdrInt64) XdrValue() interface{}
- type XdrNum32
- type XdrNum64
- type XdrOut
- type XdrPrint
- type XdrProc
- type XdrPtr
- type XdrSendCall
- type XdrSize
- func (v XdrSize) GetU32() uint32
- func (v *XdrSize) Scan(ss fmt.ScanState, r rune) (err error)
- func (v *XdrSize) SetU32(nv uint32)
- func (v XdrSize) String() string
- func (v XdrSize) XdrBound() uint32
- func (v *XdrSize) XdrMarshal(x XDR, name string)
- func (v *XdrSize) XdrPointer() interface{}
- func (XdrSize) XdrTypeName() string
- func (v XdrSize) XdrValue() interface{}
- type XdrSrv
- type XdrSrvProc
- type XdrString
- func (v XdrString) GetByteSlice() []byte
- func (v XdrString) GetString() string
- func (v XdrString) Scan(ss fmt.ScanState, _ rune) error
- func (v XdrString) SetByteSlice(bs []byte)
- func (v XdrString) SetString(s string)
- func (v XdrString) String() string
- func (v XdrString) XdrBound() uint32
- func (v XdrString) XdrMarshal(x XDR, name string)
- func (v XdrString) XdrPointer() interface{}
- func (XdrString) XdrTypeName() string
- func (v XdrString) XdrValue() interface{}
- type XdrType
- type XdrType_bool
- type XdrType_float32
- type XdrType_float64
- type XdrType_int32
- type XdrType_int64
- type XdrType_uint32
- type XdrType_uint64
- type XdrType_void
- type XdrTypedef
- type XdrUint32
- func (v XdrUint32) GetU32() uint32
- func (v *XdrUint32) Scan(ss fmt.ScanState, r rune) error
- func (v *XdrUint32) SetU32(nv uint32)
- func (v XdrUint32) String() string
- func (v *XdrUint32) XdrMarshal(x XDR, name string)
- func (v *XdrUint32) XdrPointer() interface{}
- func (XdrUint32) XdrTypeName() string
- func (v XdrUint32) XdrValue() interface{}
- type XdrUint64
- func (v XdrUint64) GetU64() uint64
- func (v *XdrUint64) Scan(ss fmt.ScanState, r rune) error
- func (v *XdrUint64) SetU64(nv uint64)
- func (v XdrUint64) String() string
- func (v *XdrUint64) XdrMarshal(x XDR, name string)
- func (v *XdrUint64) XdrPointer() interface{}
- func (XdrUint64) XdrTypeName() string
- func (v XdrUint64) XdrValue() interface{}
- type XdrUnion
- type XdrVarBytes
- type XdrVec
- type XdrVecOpaque
- func (v XdrVecOpaque) GetByteSlice() []byte
- func (v XdrVecOpaque) Scan(ss fmt.ScanState, _ rune) error
- func (v XdrVecOpaque) SetByteSlice(bs []byte)
- func (v XdrVecOpaque) String() string
- func (v XdrVecOpaque) XdrBound() uint32
- func (v XdrVecOpaque) XdrMarshal(x XDR, name string)
- func (v XdrVecOpaque) XdrPointer() interface{}
- func (XdrVecOpaque) XdrTypeName() string
- func (v XdrVecOpaque) XdrValue() interface{}
- type XdrVoid
Constants ¶
const ( TRUE = true FALSE = false )
RFC4506 defines bool as equivalent to an enum with values all-caps TRUE and FALSE. For convenience, we represent an XDR bool as a Go bool instead, and so define these constants for use in union cases. (XDR source files should not use lower-case true and false, as these will not work in other languages or with other XDR compilers.)
Variables ¶
var XdrCatalog = make(map[uint64]func(uint32) XdrProc)
A catalog of procedures of different RPC programs and versions, mostly useful for debugging (e.g., pretty-printing a log of RPC messages). The key to the map is prog<<32|vers. The function returns a new instance of an appropriate XdrProc.
Functions ¶
func XdrArrayOpaqueScan ¶
Helper function for scanning fix-size opaque arrays.
func XdrSymChar ¶
Returns true for A-Z, a-z, 0-9, and _. (Used by the generated code that implements Scanner for enums.)
func XdrToI32 ¶
func XdrToI32(i interface{}) int32
Unfortunately, you can't cast a bool to an int. Hence, in situations like a union discriminant where we don't know if a type is equivalent to bool or not, then, short of using reflection, this is how we have to convert to an integer. Note that this expects types int, [u]int32, enum, and bool, rather than pointers to these types.
func XdrToString ¶
Generic function that converts any compiled XDR type to a multi-line string. Useful for debugging.
Types ¶
type XDR ¶
type XDR interface { // A function that gets called for each value to be marshalled. // The val XdrType argument will be one of the following: // // * A pointer type implementing XdrNum32 for bool, int, unsigned // int, float, the size of variable-length arrays except string // and opaque, and enums. In the case of enums, that instance // will just be a pointer to the enum. In the case of the other // types, it will be a pointer to a defined type that implements // the XdrNum32 interface (since plain go types cannot implement // methods)--e.g., *XdrUint32 for unsigned int. Variable array // sizes are passed as *XdrSize, which enforces the bound. // // * A pointer type implementing XdrNum64 for hyper, unsigned // hyper, and double. These are user-defined versions of int64, // uint64, and float64, called XdrInt64, XdrUint64, and // XdrFloat64, respectively. // // * An instance of XdrBytes for strings and opaque. // Specifically, strings are passed as XdrString, and // variable-length opaque<> vectors are passed as XdrVecOpaque, // both of which implement XdrVarBytes. // // * An XdrArrayOpaque containing a slice referencing a byte array // for fixed-length opaque[]. XdrArrayOpaque implements // XdrBytes, but not XdrVarBytes. // // * An instance of XdrAggregate for structs, unions, and // pointers. Note that structs and unions are just passed as // pointers to the underlying structures (which all implement // XdrAggregate). Pointers are passed as an XdrPtr interface // implemented by a defined pointer type (since plain pointers // cannot have methods). // // Note that the Marshal method is responsible for recursing into // XdrAggregate instance by calling the XdrRecurse method. // Requiring the Marshal method to recurse manually allows it to // refrain from recursing in cases where it needs to special-case // the handling of specific types. Marshal(name string, val XdrType) // This method should just be fmt.Sprintf for XDRs that use name. // Those that don't use name can use a trivial method returning "" Sprintf(string, ...interface{}) string }
The interface through which values are serialized, printed, etc.
type XdrAggregate ¶
Any struct, union, pointer, or variable-length array type (except opaque<> and string<>) is passed to XDR.Marshal as a pointer implementing the XdrAggregate interface. It is the responsibility of the XDR.Marshal function to call the XdrRecurse method so as to recurse into the data structure. Placing reponsibility on XDR.Marshal for recursing allows a custom XDR to prune the serialization at particular types (e.g., for pretty-printing a partucular struct in a non-standard way).
type XdrArray ¶
type XdrArray interface { XdrAggregate XdrArraySize() uint32 }
Any array type is passed as a pointer to a user-defined array supporting the XdrArray interface. This is a subtype of XdrAggregate, and so supports recursing to marshal each individual array member.
type XdrArrayOpaque ¶
The interface of XdrTypes of opaque[n] for all n
type XdrBool ¶
type XdrBool bool
The XdrType that bool gets turned into for marshaling.
func (*XdrBool) XdrMarshal ¶
func (*XdrBool) XdrPointer ¶
func (v *XdrBool) XdrPointer() interface{}
func (XdrBool) XdrTypeName ¶
type XdrBytes ¶
A common interface implemented by XdrString, XdrVecOpaque, and XdrArrayOpaque (and hence used to operate on the XdrTypes corresponding to value os ftype string<>, opaque<>, and opaque[]).
type XdrEnum ¶
Enums additionally provide access to a map of values to names. You generally don't need to invoke the XdrEnumNames() method (since the String and Scan methods already access the underlying maps), but the presence of this method can be useful to differentiate enums from other XdrNum32 types.
type XdrError ¶
type XdrError string
The error thrown by marshaling functions when data has a bad value.
type XdrFloat32 ¶
type XdrFloat32 float32
The XdrType that float gets converted to for marshaling.
func XDR_float32 ¶
func XDR_float32(v *float32) *XdrFloat32
func (XdrFloat32) GetU32 ¶
func (v XdrFloat32) GetU32() uint32
func (*XdrFloat32) SetU32 ¶
func (v *XdrFloat32) SetU32(nv uint32)
func (XdrFloat32) String ¶
func (v XdrFloat32) String() string
func (*XdrFloat32) XdrMarshal ¶
func (v *XdrFloat32) XdrMarshal(x XDR, name string)
func (*XdrFloat32) XdrPointer ¶
func (v *XdrFloat32) XdrPointer() interface{}
func (XdrFloat32) XdrTypeName ¶
func (XdrFloat32) XdrTypeName() string
func (XdrFloat32) XdrValue ¶
func (v XdrFloat32) XdrValue() interface{}
type XdrFloat64 ¶
type XdrFloat64 float64
The XdrType that double gets converted to for marshaling.
func XDR_float64 ¶
func XDR_float64(v *float64) *XdrFloat64
func (XdrFloat64) GetU64 ¶
func (v XdrFloat64) GetU64() uint64
func (*XdrFloat64) SetU64 ¶
func (v *XdrFloat64) SetU64(nv uint64)
func (XdrFloat64) String ¶
func (v XdrFloat64) String() string
func (*XdrFloat64) XdrMarshal ¶
func (v *XdrFloat64) XdrMarshal(x XDR, name string)
func (*XdrFloat64) XdrPointer ¶
func (v *XdrFloat64) XdrPointer() interface{}
func (XdrFloat64) XdrTypeName ¶
func (XdrFloat64) XdrTypeName() string
func (XdrFloat64) XdrValue ¶
func (v XdrFloat64) XdrValue() interface{}
type XdrInt32 ¶
type XdrInt32 int32
The XdrType that int gets converted to for marshaling.
func (*XdrInt32) XdrMarshal ¶
func (*XdrInt32) XdrPointer ¶
func (v *XdrInt32) XdrPointer() interface{}
func (XdrInt32) XdrTypeName ¶
type XdrInt64 ¶
type XdrInt64 int64
The XdrType that hyper gets converted to for marshaling.
func (*XdrInt64) XdrMarshal ¶
func (*XdrInt64) XdrPointer ¶
func (v *XdrInt64) XdrPointer() interface{}
func (XdrInt64) XdrTypeName ¶
type XdrNum32 ¶
All quantities that should be serialized as 32-bit numbers (including bools, enums, union discriminants, the bit saying whether or not a pointer is NULL, floats, and vector lenghts) are passed to the XDR.Marshal function as a pointer to a defined type implementing the XdrNum32 interface. The one exception is string<> and opaque<>, for which it is the job of XDR.Marshal to serialize the 32-bit length.
type XdrNum64 ¶
All 64-bit numbers (hyper, unsigned hyper, and double) are passed to XDR.Marshal as a pointer to a defined type implementing XdrNum64.
type XdrPrint ¶
Back end that renders an XDR data structure as simple text. Example:
XDR_MyType(&myVal).XdrMarshal(&XdrPrint{os.Stdout}, "")
type XdrProc ¶
type XdrProc interface { Prog() uint32 Vers() uint32 Proc() uint32 ProgName() string VersName() string ProcName() string GetArg() XdrType GetRes() XdrType }
Interface for a data structure containing the argument and result types of a call.
type XdrPtr ¶
type XdrPtr interface { // Marshals first the present/not-present bool, then if true, the // underlying value. XdrAggregate GetPresent() bool SetPresent(bool) // If the present/not-present bool is false, this function does // nothing. Otherwise, it marshals just the value, not the bit. XdrMarshalValue(XDR, string) }
Any pointer type is converted to an XdrType implementing the XdrPtr interface for marshaling. Note XdrPtr is a subtype of XdrAggregate. When a Marshal function does nothing special for XdrPtr and treats the XdrPtr like any other XdrAggregate (calling XdrRecurse), the Marshal function will then get called one or two more times, first with an XdrSize (implementing XdrNum32) to marshal the non-NULL bit, and then again with the underlying value if the pointer is non-NULL. An XDR.Marshal function that wants to special case pointers can access the present bit from the GetPresent and SetPresent methods, then bypass marshaling of the bit by calling XdrMarshalValue instead of XdrRecurse.
type XdrSendCall ¶
An interface for types that can send remote procedure calls and await their reply.
type XdrSize ¶
This XdrType is used to marshal the length of vectors and the present/not-present value of pointers.
func (*XdrSize) XdrMarshal ¶
func (*XdrSize) XdrPointer ¶
func (v *XdrSize) XdrPointer() interface{}
func (XdrSize) XdrTypeName ¶
type XdrSrv ¶
type XdrSrv interface { Prog() uint32 Vers() uint32 ProgName() string VersName() string GetProc(uint32) XdrSrvProc }
Interface for an RPC version interface bound to a server implementation. The result of GetProc() can be used to marshal the arguments and results as well as actually invoke the function (though Do()).
type XdrSrvProc ¶
Interface for a data structure containing argument and results of a procedure plus a way to invoke the procedure on an instance of the RPC version. In other words, Do() actually performs the work of an RPC on the server side.
type XdrString ¶
The XdrType that strings get converted to for marshaling.
func (XdrString) GetByteSlice ¶
func (XdrString) SetByteSlice ¶
func (XdrString) XdrMarshal ¶
func (XdrString) XdrPointer ¶
func (v XdrString) XdrPointer() interface{}
func (XdrString) XdrTypeName ¶
type XdrType ¶
type XdrType interface { // Return a string describing the name of the type (which will // reflect the name of a typedef). XdrTypeName() string // Return the underlying native representation of an XdrType // (e.g., int32 for an XdrInt32). XdrValue() interface{} // Return a pointer to the underlying native representation of an // XdrType (often just the same type as the XdrType, but sometimes // not, e.g., for primitive types that can't have methods // defined). XdrPointer() interface{} // Calls x.Marshal(name, v). XdrMarshal(XDR, string) }
Types passed to the XDR Marshal method implementing the XdrType interface. Pointers to some generated types T already implement the interface. However, since built-in types such as string and int32 cannot implement interfaces, each type T has a function XDR_T(*T) that returns some type implementing XdrType. These XdrType interfaces also encode limits on string and vector sizes and simplify code by collapsing similar cases (e.g., all 32-bit numbers are cast to a pointer implementing XdrNum32).
For most XdrType instances, XdrPointer() and XdrValue() provide access to the underlying type (which might not implement XdrType), with the following exceptions:
* opaque[] (fixed-length arrays of bytes) are returned as XdrArrayOpaque (by XdrValue()) or nil (by XdrPointer()). This is because XdrArrayOpaque wraps a byte slice rather than an actual array. One generally doesn't want to pass arrays around; moreover, getting a pointer to the actual array provides less information, because one can't test for arrays in a type switch without knowing the exact length of the array, while one can always dynamically test the length of a slice.
* Pointer types, in their XdrRecurse methods, marshal a special XdrNum32 type of 0 or 1 to record whether the pointer is nil or the value is present. Since this bool does not exist, XdrPointer() returns nil (while XdrValue returns a bool).
* For arrays, XdrValue() passes a slice, rather than the full array, so as to avoid copying the array.
func XdrBaseType ¶
Unwrap typedefs to obtain the underlying XdrType.
type XdrType_bool ¶
type XdrType_bool = *XdrBool
type XdrType_float32 ¶
type XdrType_float32 = *XdrFloat32
type XdrType_float64 ¶
type XdrType_float64 = *XdrFloat64
type XdrType_int32 ¶
type XdrType_int32 = *XdrInt32
type XdrType_int64 ¶
type XdrType_int64 = *XdrInt64
type XdrType_uint32 ¶
type XdrType_uint32 = *XdrUint32
type XdrType_uint64 ¶
type XdrType_uint64 = *XdrUint64
type XdrType_void ¶
type XdrType_void = *XdrVoid
func XDR_XdrVoid ¶
func XDR_XdrVoid(v *XdrVoid) XdrType_void
type XdrTypedef ¶
type XdrUint32 ¶
type XdrUint32 uint32
The XdrType that unsigned int gets converted to for marshaling.
func XDR_uint32 ¶
func (*XdrUint32) XdrMarshal ¶
func (*XdrUint32) XdrPointer ¶
func (v *XdrUint32) XdrPointer() interface{}
func (XdrUint32) XdrTypeName ¶
type XdrUint64 ¶
type XdrUint64 uint64
The XdrType that unsigned hyper gets converted to for marshaling.
func XDR_uint64 ¶
func (*XdrUint64) XdrMarshal ¶
func (*XdrUint64) XdrPointer ¶
func (v *XdrUint64) XdrPointer() interface{}
func (XdrUint64) XdrTypeName ¶
type XdrUnion ¶
type XdrUnion interface { XdrAggregate XdrValid() bool XdrValidTags() map[int32]bool // returns nil if there's a default XdrUnionTag() XdrNum32 XdrUnionTagName() string XdrUnionBody() XdrType XdrUnionBodyName() string }
A union type is an XdrAggregate with extra methods for individually accessing the tag and active branch.
type XdrVarBytes ¶
A common interface implemented by XdrString and XdrVecOpaque, the XdrTypes for opaque<> and string<>. Since XdrVarBytes is a subtype of XdrBytes, Marshal functions that want to distinguish between opaque<> and opaque[] should first try a type assertion for XdrVarBytes (to check for opaque<>) and then if that fails try XdrBytes (to check for opaque[]).
type XdrVec ¶
type XdrVec interface { XdrAggregate XdrBound() uint32 GetVecLen() uint32 SetVecLen(uint32) XdrMarshalN(XDR, string, uint32) }
Any vector type is passed as a pointer to a user-defined slice type that implements the XdrVec interface. XdrVec is a superset of XdrAggregate, so calling XdrRecurse will recurse to call XDR.Marshal first on the size (of type XdrSize), then on each element of the slice. An XDR.Marshal function can manually marshal the size and then call XdrMarshalN to marshal n vector elements. (When deserializing, it is advisable *not* to call SetVecLen before calling XdrMarshalN in case the length is huge and would exhaust memory; XdrMarshalN gradually grows the slice size as needed so as to throw a premature EOF error if N is larger than the actual input data.)
type XdrVecOpaque ¶
The XdrType that opaque<> gets converted to for marshaling.
func (XdrVecOpaque) GetByteSlice ¶
func (v XdrVecOpaque) GetByteSlice() []byte
func (XdrVecOpaque) SetByteSlice ¶
func (v XdrVecOpaque) SetByteSlice(bs []byte)
func (XdrVecOpaque) String ¶
func (v XdrVecOpaque) String() string
func (XdrVecOpaque) XdrBound ¶
func (v XdrVecOpaque) XdrBound() uint32
func (XdrVecOpaque) XdrMarshal ¶
func (v XdrVecOpaque) XdrMarshal(x XDR, name string)
func (XdrVecOpaque) XdrPointer ¶
func (v XdrVecOpaque) XdrPointer() interface{}
func (XdrVecOpaque) XdrTypeName ¶
func (XdrVecOpaque) XdrTypeName() string
func (XdrVecOpaque) XdrValue ¶
func (v XdrVecOpaque) XdrValue() interface{}
type XdrVoid ¶
type XdrVoid struct{}
An XdrType that marshals as zero bytes, and hence is used to represent void argument and return types of functions.
func (XdrVoid) XdrMarshal ¶
func (XdrVoid) XdrPointer ¶
func (XdrVoid) XdrPointer() interface{}