func NameHistoryToRpc(history *entity.NameChangeHistory) *NameHistory {
  if history == nil || len(history.History) == 0 {
    return &NameHistory{}
  }
  return &NameHistory{
    History: NameChangesToRpcArray(history.History),
  }
}
converts a name history element into its rpc representation
package rpc
import (
  "errors"
  "fmt"
  "time"
  "github.com/dotStart/Stockpile/entity"
  "github.com/dotStart/Stockpile/stockpile/plugin"
  "github.com/golang/protobuf/proto"
  "github.com/golang/protobuf/ptypes"
  "github.com/golang/protobuf/ptypes/any"
  "github.com/google/uuid"
)
const MessageTypeBaseUrl = "github.com/dotStart/Stockpile/stockpile/server/rpc/"
func ProfileIdFromRpc(rpc *ProfileId) (*entity.ProfileId, error) {
  if !rpc.IsPopulated() {
    return nil, nil
  }
  id, err := uuid.Parse(rpc.Id)
  if err != nil {
    return nil, err
  }
  return &entity.ProfileId{
    Id:          id,
    Name:        rpc.Name,
    FirstSeenAt: time.Unix(rpc.FirstSeenAt, 0),
    LastSeenAt:  time.Unix(rpc.LastSeenAt, 0),
    ValidUntil:  time.Unix(rpc.ValidUntil, 0),
  }, nil
}
func ProfileIdsFromRpcArray(rpc []*ProfileId) ([]*entity.ProfileId, error) {
  arr := make([]*entity.ProfileId, len(rpc))
  for i, encoded := range rpc {
    profileId, err := ProfileIdFromRpc(encoded)
    if err != nil {
      return nil, err
    }
    if profileId == nil {
      return nil, errors.New("encountered one or more unpopulated profiles in response")
    }
    arr[i] = profileId
  }
  return arr, nil
}
func ProfileIdToRpc(profileId *entity.ProfileId) *ProfileId {
  return &ProfileId{
    Id:          profileId.Id.String(),
    Name:        profileId.Name,
    FirstSeenAt: profileId.FirstSeenAt.Unix(),
    LastSeenAt:  profileId.LastSeenAt.Unix(),
    ValidUntil:  profileId.ValidUntil.Unix(),
  }
}
func ProfileIdsToRpcArray(profileIds []*entity.ProfileId) []*ProfileId {
  arr := make([]*ProfileId, len(profileIds))
  for i, profileId := range profileIds {
    arr[i] = ProfileIdToRpc(profileId)
  }
  return arr
}
func NameChangeToRpc(change *entity.NameChange) *NameHistoryEntry {
  return &NameHistoryEntry{
    Name:        change.Name,
    ChangedToAt: change.ChangedToAt.Unix(),
    ValidUntil:  change.ValidUntil.Unix(),
  }
}
func NameChangesToRpcArray(changes []*entity.NameChange) []*NameHistoryEntry {
  arr := make([]*NameHistoryEntry, len(changes))
  for i, change := range changes {
    arr[i] = NameChangeToRpc(change)
  }
  return arr
}
func NameChangeFromRpc(rpc *NameHistoryEntry) *entity.NameChange {
  return &entity.NameChange{
    Name:        rpc.Name,
    ChangedToAt: time.Unix(rpc.ChangedToAt, 0),
    ValidUntil:  time.Unix(rpc.ValidUntil, 0),
  }
}
func NameChangesFromRpcArray(rpc []*NameHistoryEntry) []*entity.NameChange {
  arr := make([]*entity.NameChange, len(rpc))
  for i, change := range rpc {
    arr[i] = NameChangeFromRpc(change)
  }
  return arr
}