Skip to content

Map&OrderedMap: use enum type instead of int32 as ordered map keys #140

@Kybxd

Description

@Kybxd

For the following proto message:

message FruitConf {
  option (tableau.worksheet) = {
    ordered_map: true
  };

  map<int32, Fruit> fruit_map = 1 [(tableau.field) = { name: "Fruit" key: "Key" layout: LAYOUT_INCELL }];
  message Fruit {
    protoconf.FruitType key = 1 [(tableau.field) = { name: "Key" }];
    map<int32, int32> value_list = 3 [(tableau.field) = { name: "Value" layout: LAYOUT_INCELL }];
  }
}

The generated 1-level ordered map getter accepts int32 as func param. It would be better to replace int32 with enum type.

const FruitConf::OrderedMap_int32Map* FruitConf::GetOrderedMap(int32_t key) const {
  const auto* conf = GetOrderedMap();
  if (conf == nullptr) {
    return nullptr;
  }
  auto iter = conf->find(key);
  if (iter == conf->end()) {
    return nullptr;
  }
  return &iter->second.first;
}
// GetOrderedMap1 finds value in the 1-level ordered map. It will return
// NotFound error if the key is not found.
func (x *FruitConf) GetOrderedMap1(key int32) (*OrderedMap_FruitConf_int32Map, error) {
	conf := x.orderedMap
	if val, ok := conf.Get(key); !ok {
		return nil, fmt.Errorf("key(%v) %w", key, ErrNotFound)
	} else {
		return val.First, nil
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BreakingChangeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions