MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / extractUnitOrReply

Function extractUnitOrReply

src/geo.cpp:128–144  ·  view source on GitHub ↗

Check that the unit argument matches one of the known units, and returns * the conversion factor to meters (you need to divide meters by the conversion * factor to convert to the right unit). * * If the unit is not valid, an error is reported to the client, and a value * less than zero is returned. */

Source from the content-addressed store, hash-verified

126 * If the unit is not valid, an error is reported to the client, and a value
127 * less than zero is returned. */
128double extractUnitOrReply(client *c, robj *unit) {
129 char *u = szFromObj(unit);
130
131 if (!strcmp(u, "m")) {
132 return 1;
133 } else if (!strcmp(u, "km")) {
134 return 1000;
135 } else if (!strcmp(u, "ft")) {
136 return 0.3048;
137 } else if (!strcmp(u, "mi")) {
138 return 1609.34;
139 } else {
140 addReplyError(c,
141 "unsupported unit provided. please use m, km, ft, mi");
142 return -1;
143 }
144}
145
146/* Input Argument Helper.
147 * Extract the distance from the specified two arguments starting at 'argv'

Callers 3

extractDistanceOrReplyFunction · 0.85
extractBoxOrReplyFunction · 0.85
geodistCommandFunction · 0.85

Calls 2

szFromObjFunction · 0.85
addReplyErrorFunction · 0.85

Tested by

no test coverage detected