Debian Codegraph @

mstypes/rpc_unicode_string.go

raw symbols SCIP
1 package mstypes
2
3 import (
4 "encoding/binary"
5
6 "gopkg.in/jcmturner/rpc.v0/ndr"
7 )
8
9 // RPCUnicodeString implements https://msdn.microsoft.com/en-us/library/cc230365.aspx
10 type RPCUnicodeString struct {
11 Length uint16
12 MaximumLength uint16
13 BufferPrt uint32
14 Value string
15 }
16
17 // ReadRPCUnicodeString reads a RPCUnicodeString from the bytes slice.
18 func ReadRPCUnicodeString(b *[]byte, p *int, e *binary.ByteOrder) (RPCUnicodeString, error) {
19 l := ndr.ReadUint16(b, p, e)
20 ml := ndr.ReadUint16(b, p, e)
21 if ml < l || l%2 != 0 || ml%2 != 0 {
22 return RPCUnicodeString{}, ndr.Malformed{EText: "Invalid data for RPC_UNICODE_STRING"}
23 }
24 ptr := ndr.ReadUint32(b, p, e)
25 return RPCUnicodeString{
26 Length: l,
27 MaximumLength: ml,
28 BufferPrt: ptr,
29 }, nil
30 }
31
32 // UnmarshalString populates a golang string into the RPCUnicodeString struct.
33 func (s *RPCUnicodeString) UnmarshalString(b *[]byte, p *int, e *binary.ByteOrder) (err error) {
34 s.Value, err = ndr.ReadConformantVaryingString(b, p, e)
35 return
36 }