github.com/weaviate/weaviate@v1.24.6/usecases/sharding/state_serialization.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package sharding
    13  
    14  import "encoding/json"
    15  
    16  func (s *State) JSON() ([]byte, error) {
    17  	return json.Marshal(s)
    18  }
    19  
    20  func StateFromJSON(in []byte, nodes nodes) (*State, error) {
    21  	s := State{}
    22  
    23  	if err := json.Unmarshal(in, &s); err != nil {
    24  		return nil, err
    25  	}
    26  
    27  	s.localNodeName = nodes.LocalName()
    28  
    29  	return &s, nil
    30  }