MCPcopy Create free account
hub / github.com/facebook/time / ParseTORReader

Function ParseTORReader

caliper/tor.go:79–241  ·  view source on GitHub ↗

ParseTORReader parses a Luciol OTDR .tor text file from a reader

(r io.Reader)

Source from the content-addressed store, hash-verified

77
78// ParseTORReader parses a Luciol OTDR .tor text file from a reader
79func ParseTORReader(r io.Reader) (*TORFile, error) {
80 tor := &TORFile{}
81 scanner := bufio.NewScanner(r)
82
83 // Skip header lines until we find the first section
84 for scanner.Scan() {
85 line := cleanLine(scanner.Text())
86 if line == "[DateTime]" {
87 break
88 }
89 }
90
91 currentSection := "DateTime"
92 for scanner.Scan() {
93 line := cleanLine(scanner.Text())
94
95 if line == "[-]" {
96 currentSection = ""
97 continue
98 }
99
100 if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
101 currentSection = line[1 : len(line)-1]
102 continue
103 }
104
105 if currentSection == "" && line == "" {
106 continue
107 }
108
109 switch currentSection {
110 case "DateTime":
111 ts, err := strconv.ParseInt(line, 10, 64)
112 if err != nil {
113 return nil, fmt.Errorf("parsing DateTime %q: %w", line, err)
114 }
115 tor.DateTime = time.Unix(ts, 0)
116 case "InstrumentInfo":
117 if tor.InstrumentInfo == "" {
118 tor.InstrumentInfo = line
119 } else if sn, ok := strings.CutPrefix(line, "OTDR module S/N:"); ok {
120 tor.ModuleSerialNumber = strings.TrimSpace(sn)
121 }
122 case "CableID":
123 tor.CableID = line
124 case "FiberID":
125 tor.FiberID = line
126 case "FiberType":
127 v, err := strconv.Atoi(line)
128 if err != nil {
129 return nil, fmt.Errorf("parsing FiberType %q: %w", line, err)
130 }
131 tor.FiberType = v
132 case "Wavelength":
133 v, err := strconv.Atoi(line)
134 if err != nil {
135 return nil, fmt.Errorf("parsing Wavelength %q: %w", line, err)
136 }

Callers 8

ParseTORFunction · 0.85
TestParseTORReaderFunction · 0.85
TestParseTORNoDataPointsFunction · 0.85
TestParseTORReaderEmptyFunction · 0.85
TestParseTORReaderValidFunction · 0.85

Calls 6

ScanMethod · 0.95
ErrMethod · 0.95
cleanLineFunction · 0.85
parseDataPointFunction · 0.85
parseWavelengthFromInfoFunction · 0.85
UnixMethod · 0.80

Tested by 7

TestParseTORReaderFunction · 0.68
TestParseTORNoDataPointsFunction · 0.68
TestParseTORReaderEmptyFunction · 0.68
TestParseTORReaderValidFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…