github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/network_version_info.go (about)

     1  package hedera
     2  
     3  /*-
     4   *
     5   * Hedera Go SDK
     6   *
     7   * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
     8   *
     9   * Licensed under the Apache License, Version 2.0 (the "License");
    10   * you may not use this file except in compliance with the License.
    11   * You may obtain a copy of the License at
    12   *
    13   *      http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing, software
    16   * distributed under the License is distributed on an "AS IS" BASIS,
    17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    18   * See the License for the specific language governing permissions and
    19   * limitations under the License.
    20   *
    21   */
    22  
    23  import (
    24  	"github.com/hashgraph/hedera-protobufs-go/services"
    25  	protobuf "google.golang.org/protobuf/proto"
    26  )
    27  
    28  // NetworkVersionInfo is the version info for the Hedera network protobuf and services
    29  type NetworkVersionInfo struct {
    30  	ProtobufVersion SemanticVersion
    31  	ServicesVersion SemanticVersion
    32  }
    33  
    34  func _NetworkVersionInfoFromProtobuf(version *services.NetworkGetVersionInfoResponse) NetworkVersionInfo {
    35  	if version == nil {
    36  		return NetworkVersionInfo{}
    37  	}
    38  	return NetworkVersionInfo{
    39  		ProtobufVersion: _SemanticVersionFromProtobuf(version.HapiProtoVersion),
    40  		ServicesVersion: _SemanticVersionFromProtobuf(version.HederaServicesVersion),
    41  	}
    42  }
    43  
    44  func (version *NetworkVersionInfo) _ToProtobuf() *services.NetworkGetVersionInfoResponse {
    45  	return &services.NetworkGetVersionInfoResponse{
    46  		HapiProtoVersion:      version.ProtobufVersion._ToProtobuf(),
    47  		HederaServicesVersion: version.ServicesVersion._ToProtobuf(),
    48  	}
    49  }
    50  
    51  // ToBytes returns the byte representation of the NetworkVersionInfo
    52  func (version *NetworkVersionInfo) ToBytes() []byte {
    53  	data, err := protobuf.Marshal(version._ToProtobuf())
    54  	if err != nil {
    55  		return make([]byte, 0)
    56  	}
    57  
    58  	return data
    59  }
    60  
    61  // NetworkVersionInfoFromBytes returns the NetworkVersionInfo from a raw byte array
    62  func NetworkVersionInfoFromBytes(data []byte) (NetworkVersionInfo, error) {
    63  	if data == nil {
    64  		return NetworkVersionInfo{}, errByteArrayNull
    65  	}
    66  	pb := services.NetworkGetVersionInfoResponse{}
    67  	err := protobuf.Unmarshal(data, &pb)
    68  	if err != nil {
    69  		return NetworkVersionInfo{}, err
    70  	}
    71  
    72  	info := _NetworkVersionInfoFromProtobuf(&pb)
    73  
    74  	return info, nil
    75  }