blob: b7a910b3d1bd69852f70f0f5cdfe099469dd76bf [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001package ndr
2
3import (
4 "fmt"
5 "reflect"
6)
7
8const (
9 subStringArrayTag = `ndr:"varying,X-subStringArray"`
10 subStringArrayValue = "X-subStringArray"
11)
12
13func uint16SliceToString(a []uint16) string {
14 s := make([]rune, len(a), len(a))
15 for i := range s {
16 s[i] = rune(a[i])
17 }
18 if len(s) > 0 {
19 // Remove any null terminator
20 if s[len(s)-1] == rune(0) {
21 s = s[:len(s)-1]
22 }
23 }
24 return string(s)
25}
26
27func (dec *Decoder) readVaryingString(def *[]deferedPtr) (string, error) {
28 a := new([]uint16)
29 v := reflect.ValueOf(a)
30 var t reflect.StructTag
31 err := dec.fillUniDimensionalVaryingArray(v.Elem(), t, def)
32 if err != nil {
33 return "", err
34 }
35 s := uint16SliceToString(*a)
36 return s, nil
37}
38
39func (dec *Decoder) readConformantVaryingString(def *[]deferedPtr) (string, error) {
40 a := new([]uint16)
41 v := reflect.ValueOf(a)
42 var t reflect.StructTag
43 err := dec.fillUniDimensionalConformantVaryingArray(v.Elem(), t, def)
44 if err != nil {
45 return "", err
46 }
47 s := uint16SliceToString(*a)
48 return s, nil
49}
50
51func (dec *Decoder) readStringsArray(v reflect.Value, tag reflect.StructTag, def *[]deferedPtr) error {
52 d, _ := sliceDimensions(v.Type())
53 ndrTag := parseTags(tag)
54 var m []int
55 //var ms int
56 if ndrTag.HasValue(TagConformant) {
57 for i := 0; i < d; i++ {
58 m = append(m, int(dec.precedingMax()))
59 }
60 //common max size
61 _ = dec.precedingMax()
62 //ms = int(n)
63 }
64 tag = reflect.StructTag(subStringArrayTag)
65 err := dec.fillVaryingArray(v, tag, def)
66 if err != nil {
67 return fmt.Errorf("could not read string array: %v", err)
68 }
69 return nil
70}