github.com/urso/go-structform@v0.0.2/ubjson/stack.go (about) 1 package ubjson 2 3 type stateStack struct { 4 stack []state // state stack for nested arrays/objects 5 stack0 [32]state 6 current state 7 } 8 9 type lengthStack struct { 10 stack []int64 11 stack0 [32]int64 12 current int64 13 } 14 15 func (s *stateStack) push(next state) { 16 if s.current.stateType != stFail { 17 s.stack = append(s.stack, s.current) 18 } 19 s.current = next 20 } 21 22 func (s *stateStack) pop() { 23 if len(s.stack) == 0 { 24 s.current = state{stFail, stStart} 25 } else { 26 last := len(s.stack) - 1 27 s.current = s.stack[last] 28 s.stack = s.stack[:last] 29 } 30 } 31 32 func (s *lengthStack) push(l int64) { 33 s.stack = append(s.stack, s.current) 34 s.current = l 35 } 36 37 func (s *lengthStack) pop() int64 { 38 if len(s.stack) == 0 { 39 s.current = -1 40 return -1 41 } else { 42 last := len(s.stack) - 1 43 old := s.current 44 s.current = s.stack[last] 45 s.stack = s.stack[:last] 46 return old 47 } 48 }