package ndrimport ()/*Serialization Version 1https://msdn.microsoft.com/en-us/library/cc243563.aspxCommon Header - https://msdn.microsoft.com/en-us/library/cc243890.aspx8 bytes in total:- First byte - Version: Must equal 1- Second byte - 1st 4 bits: Endianess (0=Big; 1=Little); 2nd 4 bits: Character Encoding (0=ASCII; 1=EBCDIC)- 3rd - Floating point representation (This does not seem to be the case in examples for Microsoft test sources)- 4th - Common Header Length: Must equal 8- 5th - 8th - Filler: MUST be set to 0xcccccccc on marshaling, and SHOULD be ignored during unmarshaling.Private Header - https://msdn.microsoft.com/en-us/library/cc243919.aspx8 bytes in total:- First 4 bytes - Indicates the length of a serialized top-level type in the octet stream. It MUST include the padding length and exclude the header itself.- Second 4 bytes - Filler: MUST be set to 0 (zero) during marshaling, and SHOULD be ignored during unmarshaling.*/const ( protocolVersion uint8 = 1 commonHeaderBytes uint16 = 8 bigEndian = 0 littleEndian = 1 ascii uint8 = 0 ebcdic uint8 = 1 ieee uint8 = 0 vax uint8 = 1 cray uint8 = 2 ibm uint8 = 3)// CommonHeader implements the NDR common header: https://msdn.microsoft.com/en-us/library/cc243889.aspxtypeCommonHeaderstruct { Version uint8 Endianness binary.ByteOrder CharacterEncoding uint8 FloatRepresentation uint8 HeaderLength uint16 Filler []byte}// PrivateHeader implements the NDR private header: https://msdn.microsoft.com/en-us/library/cc243919.aspxtypePrivateHeaderstruct { ObjectBufferLength uint32 Filler []byte}func ( *Decoder) () error {// Version , := .r.ReadByte()if != nil {returnMalformed{EText: "could not read first byte of common header for version"} } .ch.Version = uint8()if .ch.Version != protocolVersion {returnMalformed{EText: fmt.Sprintf("byte stream does not indicate a RPC Type serialization of version %v", protocolVersion)} }// Read Endianness & Character Encoding , := .r.ReadByte()if != nil {returnMalformed{EText: "could not read second byte of common header for endianness"} } := int( >> 4 & 0xF)if != 0 && != 1 {returnMalformed{EText: "common header does not indicate a valid endianness"} } .ch.CharacterEncoding = uint8( & 0xF)if .ch.CharacterEncoding != 0 && .ch.CharacterEncoding != 1 {returnMalformed{EText: "common header does not indicate a valid character encoding"} }switch {caselittleEndian: .ch.Endianness = binary.LittleEndiancasebigEndian: .ch.Endianness = binary.BigEndian }// Common header length , := .readBytes(2)if != nil {returnMalformed{EText: fmt.Sprintf("could not read common header length: %v", )} } .ch.HeaderLength = .ch.Endianness.Uint16()if .ch.HeaderLength != commonHeaderBytes {returnMalformed{EText: "common header does not indicate a valid length"} }// Filler bytes .ch.Filler, = .readBytes(4)if != nil {returnMalformed{EText: fmt.Sprintf("could not read common header filler: %v", )} }returnnil}func ( *Decoder) () error {// The next 8 bytes after the common header comprise the RPC type marshalling private header for constructed types. := binary.Read(.r, .ch.Endianness, &.ph.ObjectBufferLength)if != nil {returnMalformed{EText: "could not read private header object buffer length"} }if .ph.ObjectBufferLength%8 != 0 {returnMalformed{EText: "object buffer length not a multiple of 8"} }// Filler bytes .ph.Filler, = .readBytes(4)if != nil {returnMalformed{EText: fmt.Sprintf("could not read private header filler: %v", )} }returnnil}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.