func (s *State) serialize(indent bool) *bytes.Buffer {
    s.mu.Lock()
    defer s.mu.Unlock()
    b := bytes.Buffer{}
    e := json.NewEncoder(&b)